Annotate CredentialServiceAuthProvider for injection 02/89602/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 5 May 2020 09:59:36 +0000 (11:59 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 5 May 2020 10:01:55 +0000 (12:01 +0200)
This is a component which should be a singleton and should receive
a CredentialAuth service injected. Annotate it as such.

Change-Id: I2060728e2d364ba2b46960b62b37d3762cefa9cd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/aaa-authn-odl-plugin/pom.xml
netconf/aaa-authn-odl-plugin/src/main/java/org/opendaylight/netconf/authprovider/CredentialServiceAuthProvider.java

index 05b0e5f18cbb636baae3228b71eaa13149fecb03..994b4f351a886f8a67ee3216ffcc082d4de1cad4 100644 (file)
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>javax.inject</groupId>
+            <artifactId>javax.inject</artifactId>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
 </project>
index 5f7bc777d610ccbd7a60f6ee56e1e2729fcffb42..aef23f5e2290ddbda8ac0a1c7043d5b0a6a118d2 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netconf.authprovider;
 
+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;
@@ -15,10 +17,10 @@ import org.opendaylight.netconf.auth.AuthProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
  * AuthProvider implementation delegating to AAA CredentialAuth&lt;PasswordCredentials&gt; instance.
  */
+@Singleton
 public final class CredentialServiceAuthProvider implements AuthProvider {
     private static final Logger LOG = LoggerFactory.getLogger(CredentialServiceAuthProvider.class);
 
@@ -26,6 +28,7 @@ public final class CredentialServiceAuthProvider implements AuthProvider {
     // Maybe there should be a PasswordCredentialAuth implements CredentialAuth<PasswordCredentials>
     private final CredentialAuth<PasswordCredentials> credService;
 
+    @Inject
     public CredentialServiceAuthProvider(final CredentialAuth<PasswordCredentials> credService) {
         this.credService = credService;
     }
@@ -36,8 +39,7 @@ public final class CredentialServiceAuthProvider implements AuthProvider {
      */
     @Override
     public boolean authenticated(final String username, final String password) {
-
-        Claim claim;
+        final Claim claim;
         try {
             claim = credService.authenticate(new PasswordCredentialsWrapper(username, password));
         } catch (AuthenticationException e) {