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.auth.aaa;
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.netconf.auth.AuthProvider;
18 import org.osgi.service.component.annotations.Activate;
19 import org.osgi.service.component.annotations.Component;
20 import org.osgi.service.component.annotations.Reference;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * AuthProvider implementation delegating to a {@link PasswordCredentialAuth} instance.
28 @Component(immediate = true, property = "type=netconf-auth-provider")
29 public final class CredentialServiceAuthProvider implements AuthProvider {
30 private static final Logger LOG = LoggerFactory.getLogger(CredentialServiceAuthProvider.class);
32 private final PasswordCredentialAuth credService;
36 public CredentialServiceAuthProvider(final @Reference PasswordCredentialAuth credService) {
37 this.credService = requireNonNull(credService);
41 * Authenticate user. This implementation tracks CredentialAuth<PasswordCredentials>
42 * and delegates the decision to it.
45 public boolean authenticated(final String username, final String password) {
46 final var credentials = new DefaultPasswordCredentials(username, password);
50 claim = credService.authenticate(credentials);
51 } catch (AuthenticationException e) {
52 LOG.debug("Authentication failed for user '{}'", username, e);
56 LOG.debug("Authentication result for user '{}' : {}", username, claim.domain());