2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.authprovider;
10 import static java.util.Objects.requireNonNull;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import org.opendaylight.aaa.api.AuthenticationException;
15 import org.opendaylight.aaa.api.Claim;
16 import org.opendaylight.aaa.api.PasswordCredentialAuth;
17 import org.opendaylight.aaa.api.PasswordCredentials;
18 import org.opendaylight.netconf.auth.AuthProvider;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * AuthProvider implementation delegating to a {@link PasswordCredentialAuth} instance.
26 public final class CredentialServiceAuthProvider implements AuthProvider {
27 private static final Logger LOG = LoggerFactory.getLogger(CredentialServiceAuthProvider.class);
29 private final PasswordCredentialAuth credService;
32 public CredentialServiceAuthProvider(final PasswordCredentialAuth credService) {
33 this.credService = requireNonNull(credService);
37 * Authenticate user. This implementation tracks CredentialAuth<PasswordCredentials>
38 * and delegates the decision to it.
41 public boolean authenticated(final String username, final String password) {
44 claim = credService.authenticate(new PasswordCredentialsWrapper(username, password));
45 } catch (AuthenticationException e) {
46 LOG.debug("Authentication failed for user '{}'", username, e);
50 LOG.debug("Authentication result for user '{}' : {}", username, claim.domain());
54 private static final class PasswordCredentialsWrapper implements PasswordCredentials {
55 private final String username;
56 private final String password;
58 PasswordCredentialsWrapper(final String username, final String password) {
59 this.username = username;
60 this.password = password;
64 public String username() {
69 public String password() {
74 public String domain() {
75 // If this is left null, default "sdn" domain is assumed