Bind to PasswordCredentialAuth 90/89390/8
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 26 Apr 2020 01:52:08 +0000 (03:52 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 6 May 2020 10:14:52 +0000 (10:14 +0000)
Rather than using a non-safe wild generic, bind to the specialization
for passwords, addressing a long-standing FIXME.

Change-Id: I0b14c92c2801dfdc833a925c8b907e4802e0506e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/aaa-authn-odl-plugin/src/main/java/org/opendaylight/netconf/authprovider/CredentialServiceAuthProvider.java
netconf/aaa-authn-odl-plugin/src/main/resources/OSGI-INF/blueprint/aaa-authn-netconf.xml
netconf/aaa-authn-odl-plugin/src/test/java/org/opendaylight/netconf/authprovider/CredentialServiceAuthProviderTest.java

index aef23f5e2290ddbda8ac0a1c7043d5b0a6a118d2..8e869aca32c26827dd15e7494a5a79cdb5f017c7 100644 (file)
@@ -7,30 +7,30 @@
  */
 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&lt;PasswordCredentials&gt; 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);
     }
 
     /**
index ce49a534a2c06cce28e06644c86ffde42e7236dc..e04462b6f39705e2d26a2c863912de8cf4626008 100644 (file)
@@ -10,7 +10,7 @@
            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"/>
index 11d16fff1129e66e003ef5143da79f24770a69a6..a2ebe91c9d9dc255e957427567d04d8f1357615d 100644 (file)
@@ -14,36 +14,22 @@ import static org.mockito.Mockito.doReturn;
 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));
@@ -58,15 +44,4 @@ public class CredentialServiceAuthProviderTest {
         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;
-        }
-    }
 }