Split out DefaultPasswordCredentials 58/105758/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 30 Apr 2023 19:29:31 +0000 (21:29 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 30 Apr 2023 19:30:53 +0000 (21:30 +0200)
We would really like a default implementation coming from the API, but
this is really the best we can do for now.

Change-Id: I0cf30a2e86da0efc6c480f0404cf59dd0c2c9cc0
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/java/org/opendaylight/netconf/authprovider/DefaultPasswordCredentials.java [new file with mode: 0644]

index eab2c7fb3668123d80195940f6534084af9b42b2..aa05830cd1c3b44547096f1d87e45ad2c47741b6 100644 (file)
@@ -14,7 +14,6 @@ import javax.inject.Singleton;
 import org.opendaylight.aaa.api.AuthenticationException;
 import org.opendaylight.aaa.api.Claim;
 import org.opendaylight.aaa.api.PasswordCredentialAuth;
-import org.opendaylight.aaa.api.PasswordCredentials;
 import org.opendaylight.netconf.auth.AuthProvider;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
@@ -44,9 +43,11 @@ public final class CredentialServiceAuthProvider implements AuthProvider {
      */
     @Override
     public boolean authenticated(final String username, final String password) {
+        final var credentials = new DefaultPasswordCredentials(username, password);
+
         final Claim claim;
         try {
-            claim = credService.authenticate(new PasswordCredentialsWrapper(username, password));
+            claim = credService.authenticate(credentials);
         } catch (AuthenticationException e) {
             LOG.debug("Authentication failed for user '{}'", username, e);
             return false;
@@ -55,30 +56,4 @@ public final class CredentialServiceAuthProvider implements AuthProvider {
         LOG.debug("Authentication result for user '{}' : {}", username, claim.domain());
         return true;
     }
-
-    private static final class PasswordCredentialsWrapper implements PasswordCredentials {
-        private final String username;
-        private final String password;
-
-        PasswordCredentialsWrapper(final String username, final String password) {
-            this.username = username;
-            this.password = password;
-        }
-
-        @Override
-        public String username() {
-            return username;
-        }
-
-        @Override
-        public String password() {
-            return password;
-        }
-
-        @Override
-        public String domain() {
-            // If this is left null, default "sdn" domain is assumed
-            return null;
-        }
-    }
 }
diff --git a/netconf/aaa-authn-odl-plugin/src/main/java/org/opendaylight/netconf/authprovider/DefaultPasswordCredentials.java b/netconf/aaa-authn-odl-plugin/src/main/java/org/opendaylight/netconf/authprovider/DefaultPasswordCredentials.java
new file mode 100644 (file)
index 0000000..70798a7
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.authprovider;
+
+import org.opendaylight.aaa.api.PasswordCredentials;
+
+final class DefaultPasswordCredentials implements PasswordCredentials {
+    private final String username;
+    private final String password;
+
+    DefaultPasswordCredentials(final String username, final String password) {
+        this.username = username;
+        this.password = password;
+    }
+
+    @Override
+    public String username() {
+        return username;
+    }
+
+    @Override
+    public String password() {
+        return password;
+    }
+
+    @Override
+    public String domain() {
+        // If this is left null, default "sdn" domain is assumed
+        return null;
+    }
+}
\ No newline at end of file