From 0c77d9232353b6bac3b29af2ede7be2b0a672895 Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Fri, 8 Nov 2024 08:31:54 +0530 Subject: [PATCH] Add support for managing custom federated authenticators. --- .../management/model/Authentication.java | 20 ++++++++++--------- ...serDefinedAuthenticatorEndpointConfig.java | 2 +- ...erDefinedFederatedAuthenticatorConfig.java | 6 +++--- .../UserDefinedLocalAuthenticatorConfig.java | 6 +++--- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/model/Authentication.java b/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/model/Authentication.java index 2f77394f2d5a..5608107befc7 100644 --- a/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/model/Authentication.java +++ b/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/model/Authentication.java @@ -262,23 +262,25 @@ public Authentication build() { switch (authType) { case BASIC: return new Authentication.BasicAuthBuilder( - getProperty(authPropertiesMap, Property.USERNAME.getName()), - getProperty(authPropertiesMap, Property.PASSWORD.getName())).build(); + getProperty(Type.BASIC, authPropertiesMap, Property.USERNAME.getName()), + getProperty(Type.BASIC, authPropertiesMap, Property.PASSWORD.getName())).build(); case BEARER: return new Authentication.BearerAuthBuilder( - getProperty(authPropertiesMap, Property.ACCESS_TOKEN.getName())).build(); + getProperty(Type.BEARER, authPropertiesMap, Property.ACCESS_TOKEN.getName())).build(); case API_KEY: return new Authentication.APIKeyAuthBuilder( - getProperty(authPropertiesMap, Property.HEADER.getName()), - getProperty(authPropertiesMap, Property.VALUE.getName())).build(); + getProperty(Type.API_KEY, authPropertiesMap, Property.HEADER.getName()), + getProperty(Type.API_KEY, authPropertiesMap, Property.VALUE.getName())).build(); case NONE: return new Authentication.NoneAuthBuilder().build(); default: - throw new IllegalArgumentException(); + throw new IllegalArgumentException(String.format("An invalid authentication type '%s' is " + + "provided for the authentication configuration of the endpoint.", authType.name())); } } - private String getProperty(Map actionEndpointProperties, String propertyName) { + private String getProperty(Authentication.Type authType, Map actionEndpointProperties, + String propertyName) { if (actionEndpointProperties != null && actionEndpointProperties.containsKey(propertyName)) { String propValue = actionEndpointProperties.get(propertyName); @@ -288,8 +290,8 @@ private String getProperty(Map actionEndpointProperties, String throw new IllegalArgumentException(String.format("The Property %s cannot be blank.", propertyName)); } - throw new NoSuchElementException(String.format("The Property %s is not found in the authentication " + - "configuration.", propertyName)); + throw new NoSuchElementException(String.format("The property %s must be provided as an authentication " + + "property for the %s authentication type.", propertyName, authType.name())); } } } diff --git a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/UserDefinedAuthenticatorEndpointConfig.java b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/UserDefinedAuthenticatorEndpointConfig.java index ac1066e95866..444d6e41bb0e 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/UserDefinedAuthenticatorEndpointConfig.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/UserDefinedAuthenticatorEndpointConfig.java @@ -24,7 +24,7 @@ import java.util.Map; /** - * The authenticator endpoint configuration model. + * The authenticator endpoint configuration model for the user defined authenticator configurations. */ public class UserDefinedAuthenticatorEndpointConfig { diff --git a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/UserDefinedFederatedAuthenticatorConfig.java b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/UserDefinedFederatedAuthenticatorConfig.java index 4679585e9a15..c7fc749a3718 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/UserDefinedFederatedAuthenticatorConfig.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/UserDefinedFederatedAuthenticatorConfig.java @@ -36,9 +36,9 @@ public UserDefinedFederatedAuthenticatorConfig() { } /** - * Get the endpoint config of the User defined federated authenticator config. + * Get the endpoint configurations of the User defined federated authenticator config. * - * @return DefinedByType + * @return UserDefinedAuthenticatorEndpointConfig */ public UserDefinedAuthenticatorEndpointConfig getEndpointConfig() { @@ -46,7 +46,7 @@ public UserDefinedAuthenticatorEndpointConfig getEndpointConfig() { } /** - * Set the defined by type of the User defined federated authenticator config. + * Set the endpoint configurations of the User defined federated authenticator config. * * @param endpointConfig The endpoint config of the User defined federated authenticator config. */ diff --git a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/UserDefinedLocalAuthenticatorConfig.java b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/UserDefinedLocalAuthenticatorConfig.java index c372fb17f8d9..fab5a37a69bd 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/UserDefinedLocalAuthenticatorConfig.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.common/src/main/java/org/wso2/carbon/identity/application/common/model/UserDefinedLocalAuthenticatorConfig.java @@ -42,9 +42,9 @@ public UserDefinedLocalAuthenticatorConfig(AuthenticationType type) { } /** - * Get the endpoint config of the User defined local authenticator config. + * Get the endpoint configurations of the User defined local authenticator config. * - * @return DefinedByType + * @return UserDefinedAuthenticatorEndpointConfig */ public UserDefinedAuthenticatorEndpointConfig getEndpointConfig() { @@ -52,7 +52,7 @@ public UserDefinedAuthenticatorEndpointConfig getEndpointConfig() { } /** - * Set the defined by type of the User defined local authenticator config. + * Set the endpoint configurations of the User defined local authenticator config. * * @param endpointConfig The endpoint config of the User defined local authenticator config. */