* 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();
}
--- /dev/null
+/*
+ * 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;
+ }
+}
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;
/**
* 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);
<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>