Add PasswordCredentialAuth 88/89388/3
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 26 Apr 2020 01:32:13 +0000 (03:32 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 4 May 2020 10:22:16 +0000 (12:22 +0200)
CredentialAuth is a generic interface which needs to be specialized
to capture capture which credentials are being passed. Downstreams
(in netconf) have a FIXME related to this, as they have no way to
express the type-safe dependency.

Introduce PasswordCredentialAuth to which downstreams can safely
bind. Also add a method to allow run-time discovery of required
credetial type.

Change-Id: I844db3b460bf95110fb3adbb687ce25e996e3608
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
aaa-authn-api/src/main/java/org/opendaylight/aaa/api/CredentialAuth.java
aaa-authn-api/src/main/java/org/opendaylight/aaa/api/PasswordCredentialAuth.java [new file with mode: 0644]
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/idm/IdmLightProxy.java
aaa-shiro/impl/src/main/resources/OSGI-INF/blueprint/impl-blueprint.xml

index a9d22a8197b3dec45a6703454d44caa3f58b851c..343d12df801b73a9f6a771228ba9b12463debeed 100644 (file)
@@ -5,24 +5,35 @@
  * 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.aaa.api;
 
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
- * An interface for direct authentication with some given credentials.
+ * An interface for direct authentication with some given credentials. Note this interface is not type-safe.
  *
  * @author liemmn
  */
 public interface CredentialAuth<T extends Credentials> {
-
     /**
      * Authenticate a claim with the given credentials and domain scope.
      *
-     * @param cred
-     *            credentials
+     * @param cred credentials
      * @return authenticated claim
-     * @throws AuthenticationException
-     *             if failed authentication
+     * @throws AuthenticationException if failed authentication
+     * @throws NullPointerException if credentials are null
      */
     Claim authenticate(T cred) throws AuthenticationException;
+
+    /**
+     * Return the credential class that is required by this services. This acts as a type check allowing discovery
+     * of the type at runtime.
+     *
+     * <p>
+     * Note: this method should be defined in subclasses specializations for a particular credential class as a default
+     *       (in case of an interface) or a final (in case of a class) method.
+     *
+     * @return Required credential class
+     */
+    @NonNull Class<T> credentialClass();
 }
diff --git a/aaa-authn-api/src/main/java/org/opendaylight/aaa/api/PasswordCredentialAuth.java b/aaa-authn-api/src/main/java/org/opendaylight/aaa/api/PasswordCredentialAuth.java
new file mode 100644 (file)
index 0000000..92ab241
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.aaa.api;
+
+/**
+ * Type-safe specialization combining {@link CredentialAuth} and {@link PasswordCredentials}.
+ */
+public interface PasswordCredentialAuth extends CredentialAuth<PasswordCredentials> {
+    @Override
+    default Class<PasswordCredentials> credentialClass() {
+        return PasswordCredentials.class;
+    }
+}
index 5ebd0d857431cf9d69af2031d6b7a4db7596e31e..38fafbd30676c7e85048fcc2cee884e06a56471b 100644 (file)
@@ -17,11 +17,11 @@ import java.util.concurrent.ConcurrentHashMap;
 import org.opendaylight.aaa.api.AuthenticationException;
 import org.opendaylight.aaa.api.Claim;
 import org.opendaylight.aaa.api.ClaimCache;
-import org.opendaylight.aaa.api.CredentialAuth;
 import org.opendaylight.aaa.api.IDMStoreException;
 import org.opendaylight.aaa.api.IIDMStore;
 import org.opendaylight.aaa.api.IdMService;
 import org.opendaylight.aaa.api.IdMServiceImpl;
+import org.opendaylight.aaa.api.PasswordCredentialAuth;
 import org.opendaylight.aaa.api.PasswordCredentials;
 import org.opendaylight.aaa.api.model.Domain;
 import org.opendaylight.aaa.api.model.Grant;
@@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
 /**
  * An OSGi proxy for the IdmLight server.
  */
-public class IdmLightProxy implements CredentialAuth<PasswordCredentials>, IdMService, ClaimCache {
+public class IdmLightProxy implements PasswordCredentialAuth, IdMService, ClaimCache {
 
     private static final Logger LOG = LoggerFactory.getLogger(IdmLightProxy.class);
 
index c93fc77f1787610cc163fc5453024935faef3f88..591619e93d6763df67252b060eb23db502b83732 100644 (file)
@@ -41,8 +41,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   <service ref="idmLightProxy" odl:type="default">
     <interfaces>
       <value>org.opendaylight.aaa.api.IdMService</value>
-      <value>org.opendaylight.aaa.api.CredentialAuth</value>
       <value>org.opendaylight.aaa.api.ClaimCache</value>
+      <value>org.opendaylight.aaa.api.CredentialAuth</value>
+      <value>org.opendaylight.aaa.api.PasswordCredentialAuth</value>
     </interfaces>
   </service>