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.osgi.service.component.annotations.Activate;
20 import org.osgi.service.component.annotations.Component;
21 import org.osgi.service.component.annotations.Reference;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * AuthProvider implementation delegating to a {@link PasswordCredentialAuth} instance.
29 @Component(immediate = true, property = "type=netconf-auth-provider")
30 public final class CredentialServiceAuthProvider implements AuthProvider {
31 private static final Logger LOG = LoggerFactory.getLogger(CredentialServiceAuthProvider.class);
33 private final PasswordCredentialAuth credService;
37 public CredentialServiceAuthProvider(final @Reference PasswordCredentialAuth credService) {
38 this.credService = requireNonNull(credService);
42 * Authenticate user. This implementation tracks CredentialAuth<PasswordCredentials>
43 * and delegates the decision to it.
46 public boolean authenticated(final String username, final String password) {
49 claim = credService.authenticate(new PasswordCredentialsWrapper(username, password));
50 } catch (AuthenticationException e) {
51 LOG.debug("Authentication failed for user '{}'", username, e);
55 LOG.debug("Authentication result for user '{}' : {}", username, claim.domain());
59 private static final class PasswordCredentialsWrapper implements PasswordCredentials {
60 private final String username;
61 private final String password;
63 PasswordCredentialsWrapper(final String username, final String password) {
64 this.username = username;
65 this.password = password;
69 public String username() {
74 public String password() {
79 public String domain() {
80 // If this is left null, default "sdn" domain is assumed