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;
*/
@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;
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;
- }
- }
}
--- /dev/null
+/*
+ * 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