Merge OSGiCredentialServiceAuthProvider 30/96130/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 12 May 2021 09:00:14 +0000 (11:00 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 12 May 2021 09:00:14 +0000 (11:00 +0200)
We now have OSGi R7, hence we can safely use constructor injection,
eliminating the need for an extra class.

Change-Id: I41a1bc06d6aec1be89979327e9b530952cd673ce
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/aaa-authn-odl-plugin/src/main/java/org/opendaylight/netconf/authprovider/CredentialServiceAuthProvider.java
netconf/aaa-authn-odl-plugin/src/main/java/org/opendaylight/netconf/authprovider/OSGiCredentialServiceAuthProvider.java [deleted file]

index 8e869aca32c26827dd15e7494a5a79cdb5f017c7..eab2c7fb3668123d80195940f6534084af9b42b2 100644 (file)
@@ -16,6 +16,9 @@ import org.opendaylight.aaa.api.Claim;
 import org.opendaylight.aaa.api.PasswordCredentialAuth;
 import org.opendaylight.aaa.api.PasswordCredentials;
 import org.opendaylight.netconf.auth.AuthProvider;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -23,13 +26,15 @@ import org.slf4j.LoggerFactory;
  * AuthProvider implementation delegating to a {@link PasswordCredentialAuth} instance.
  */
 @Singleton
+@Component(immediate = true, property = "type=netconf-auth-provider")
 public final class CredentialServiceAuthProvider implements AuthProvider {
     private static final Logger LOG = LoggerFactory.getLogger(CredentialServiceAuthProvider.class);
 
     private final PasswordCredentialAuth credService;
 
     @Inject
-    public CredentialServiceAuthProvider(final PasswordCredentialAuth credService) {
+    @Activate
+    public CredentialServiceAuthProvider(final @Reference PasswordCredentialAuth credService) {
         this.credService = requireNonNull(credService);
     }
 
diff --git a/netconf/aaa-authn-odl-plugin/src/main/java/org/opendaylight/netconf/authprovider/OSGiCredentialServiceAuthProvider.java b/netconf/aaa-authn-odl-plugin/src/main/java/org/opendaylight/netconf/authprovider/OSGiCredentialServiceAuthProvider.java
deleted file mode 100644 (file)
index 8d44faf..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netconf.authprovider;
-
-import org.opendaylight.aaa.api.PasswordCredentialAuth;
-import org.opendaylight.netconf.auth.AuthProvider;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Reference;
-
-@Component(immediate = true, property = "type=netconf-auth-provider")
-// FIXME: merge with CredentialServiceAuthProvider once we have OSGi R7
-public final class OSGiCredentialServiceAuthProvider implements AuthProvider {
-    @Reference
-    PasswordCredentialAuth credService;
-
-    private CredentialServiceAuthProvider delegate = null;
-
-    @Override
-    public boolean authenticated(final String username, final String password) {
-        return delegate.authenticated(username, password);
-    }
-
-    @Activate
-    void activate() {
-        delegate = new CredentialServiceAuthProvider(credService);
-    }
-
-    @Deactivate
-    void deactivate() {
-        delegate = null;
-    }
-}