*/
package org.opendaylight.netconf.authprovider;
+import static java.util.Objects.requireNonNull;
+
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.aaa.api.AuthenticationException;
import org.opendaylight.aaa.api.Claim;
-import org.opendaylight.aaa.api.CredentialAuth;
+import org.opendaylight.aaa.api.PasswordCredentialAuth;
import org.opendaylight.aaa.api.PasswordCredentials;
import org.opendaylight.netconf.auth.AuthProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * AuthProvider implementation delegating to AAA CredentialAuth<PasswordCredentials> instance.
+ * AuthProvider implementation delegating to a {@link PasswordCredentialAuth} instance.
*/
@Singleton
public final class CredentialServiceAuthProvider implements AuthProvider {
private static final Logger LOG = LoggerFactory.getLogger(CredentialServiceAuthProvider.class);
- // FIXME CredentialAuth is generic and it causes warnings during compilation
- // Maybe there should be a PasswordCredentialAuth implements CredentialAuth<PasswordCredentials>
- private final CredentialAuth<PasswordCredentials> credService;
+ private final PasswordCredentialAuth credService;
@Inject
- public CredentialServiceAuthProvider(final CredentialAuth<PasswordCredentials> credService) {
- this.credService = credService;
+ public CredentialServiceAuthProvider(final PasswordCredentialAuth credService) {
+ this.credService = requireNonNull(credService);
}
/**
xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
odl:use-default-for-reference-types="true">
- <reference id="credentialAuth" interface="org.opendaylight.aaa.api.CredentialAuth" odl:type="default" />
+ <reference id="credentialAuth" interface="org.opendaylight.aaa.api.PasswordCredentialAuth" odl:type="default" />
<bean id="credentialServiceAuthProvider" class="org.opendaylight.netconf.authprovider.CredentialServiceAuthProvider">
<argument ref="credentialAuth"/>
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
-import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.aaa.api.AuthenticationException;
import org.opendaylight.aaa.api.Claim;
-import org.opendaylight.aaa.api.CredentialAuth;
+import org.opendaylight.aaa.api.PasswordCredentialAuth;
import org.opendaylight.aaa.api.PasswordCredentials;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class CredentialServiceAuthProviderTest {
-
@Mock
- private CredentialAuth<PasswordCredentials> credAuth;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- }
-
+ private PasswordCredentialAuth credAuth;
@Test
public void testAuthenticatedTrue() throws Exception {
- ServiceReference serviceRef = mock(ServiceReference.class);
-
- ServiceListenerAnswer answer = new ServiceListenerAnswer();
-
Claim claim = mock(Claim.class);
doReturn("domain").when(claim).domain();
doReturn(claim).when(credAuth).authenticate(any(PasswordCredentials.class));
CredentialServiceAuthProvider credentialServiceAuthProvider = new CredentialServiceAuthProvider(credAuth);
assertFalse(credentialServiceAuthProvider.authenticated("user", "pwd"));
}
-
- private static class ServiceListenerAnswer implements Answer {
-
- ServiceListener serviceListener;
-
- @Override
- public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
- serviceListener = (ServiceListener) invocationOnMock.getArguments()[0];
- return null;
- }
- }
}