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 org.opendaylight.aaa.api.AuthenticationException;
11 import org.opendaylight.aaa.api.Claim;
12 import org.opendaylight.aaa.api.CredentialAuth;
13 import org.opendaylight.aaa.api.PasswordCredentials;
14 import org.opendaylight.netconf.auth.AuthProvider;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
20 * AuthProvider implementation delegating to AAA CredentialAuth<PasswordCredentials> instance.
22 public final class CredentialServiceAuthProvider implements AuthProvider {
23 private static final Logger LOG = LoggerFactory.getLogger(CredentialServiceAuthProvider.class);
25 // FIXME CredentialAuth is generic and it causes warnings during compilation
26 // Maybe there should be a PasswordCredentialAuth implements CredentialAuth<PasswordCredentials>
27 private final CredentialAuth<PasswordCredentials> credService;
29 public CredentialServiceAuthProvider(final CredentialAuth<PasswordCredentials> credService) {
30 this.credService = credService;
34 * Authenticate user. This implementation tracks CredentialAuth<PasswordCredentials>
35 * and delegates the decision to it.
38 public boolean authenticated(final String username, final String password) {
42 claim = credService.authenticate(new PasswordCredentialsWrapper(username, password));
43 } catch (AuthenticationException e) {
44 LOG.debug("Authentication failed for user '{}'", username, e);
48 LOG.debug("Authentication result for user '{}' : {}", username, claim.domain());
52 private static final class PasswordCredentialsWrapper implements PasswordCredentials {
53 private final String username;
54 private final String password;
56 PasswordCredentialsWrapper(final String username, final String password) {
57 this.username = username;
58 this.password = password;
62 public String username() {
67 public String password() {
72 public String domain() {
73 // If this is left null, default "sdn" domain is assumed