8d44faf96bad1f5916716470070dd73133668e57
[netconf.git] / netconf / aaa-authn-odl-plugin / src / main / java / org / opendaylight / netconf / authprovider / OSGiCredentialServiceAuthProvider.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.authprovider;
9
10 import org.opendaylight.aaa.api.PasswordCredentialAuth;
11 import org.opendaylight.netconf.auth.AuthProvider;
12 import org.osgi.service.component.annotations.Activate;
13 import org.osgi.service.component.annotations.Component;
14 import org.osgi.service.component.annotations.Deactivate;
15 import org.osgi.service.component.annotations.Reference;
16
17 @Component(immediate = true, property = "type=netconf-auth-provider")
18 // FIXME: merge with CredentialServiceAuthProvider once we have OSGi R7
19 public final class OSGiCredentialServiceAuthProvider implements AuthProvider {
20     @Reference
21     PasswordCredentialAuth credService;
22
23     private CredentialServiceAuthProvider delegate = null;
24
25     @Override
26     public boolean authenticated(final String username, final String password) {
27         return delegate.authenticated(username, password);
28     }
29
30     @Activate
31     void activate() {
32         delegate = new CredentialServiceAuthProvider(credService);
33     }
34
35     @Deactivate
36     void deactivate() {
37         delegate = null;
38     }
39 }