diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.common/src/main/java/org/wso2/carbon/identity/api/server/idp/common/Constants.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.common/src/main/java/org/wso2/carbon/identity/api/server/idp/common/Constants.java index d578b8f918..fe30c0eb24 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.common/src/main/java/org/wso2/carbon/identity/api/server/idp/common/Constants.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.common/src/main/java/org/wso2/carbon/identity/api/server/idp/common/Constants.java @@ -158,6 +158,8 @@ public enum ErrorMessage { "Unable to decode the provided authenticator ID %s."), ERROR_CODE_NO_SYSTEM_AUTHENTICATOR_FOUND("60043", "No system authenticator found.", "No system authenticator found for the provided authenticator Id %s."), + ERROR_COED_MULTIPLE_USER_DEFINED_AUTHENTICATORS_FOUND("60044", "Multiple authenticators found.", + "Multiple user defined authenticators are not allowed."), // Server Error starting from 650xx. ERROR_CODE_ERROR_ADDING_IDP("65002", diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java index 425f298f00..50ac07fe64 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java @@ -1779,6 +1779,10 @@ private void updateFederatedAuthenticatorConfig(IdentityProvider idp, FederatedA } else { definedByType = resolveDefinedByTypeToUpdateFederatedAuthenticator(authenticatorName); } + if (definedByType == DefinedByType.USER && federatedAuthenticators.size() > 1) { + throw handleException(Response.Status.BAD_REQUEST, + Constants.ErrorMessage.ERROR_COED_MULTIPLE_USER_DEFINED_AUTHENTICATORS_FOUND, null); + } FederatedAuthenticatorConfig authConfig = FederatedAuthenticatorConfigBuilderFactory.build( authenticator, authenticatorName, definedByType); diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/FederatedAuthenticatorConfigBuilderFactory.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/FederatedAuthenticatorConfigBuilderFactory.java index 7f2d7800a6..89e00d1e86 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/FederatedAuthenticatorConfigBuilderFactory.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/FederatedAuthenticatorConfigBuilderFactory.java @@ -38,11 +38,7 @@ import org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Base64; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -184,17 +180,22 @@ private static UserDefinedFederatedAuthenticatorConfig createUserDefinedFederate validateUserDefinedFederatedAuthenticatorModel(config); - UserDefinedFederatedAuthenticatorConfig authConfig = new UserDefinedFederatedAuthenticatorConfig(); - UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder endpointConfigBuilder = - new UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder(); - endpointConfigBuilder.uri(config.endpoint.getUri()); - endpointConfigBuilder.authenticationType(config.endpoint.getAuthentication().getType().toString()); - endpointConfigBuilder.authenticationProperties(config.endpoint.getAuthentication().getProperties() - .entrySet().stream().collect(Collectors.toMap( - Map.Entry::getKey, entry -> entry.getValue().toString()))); - authConfig.setEndpointConfig(endpointConfigBuilder.build()); - - return authConfig; + try { + UserDefinedFederatedAuthenticatorConfig authConfig = new UserDefinedFederatedAuthenticatorConfig(); + UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder endpointConfigBuilder = + new UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder(); + endpointConfigBuilder.uri(config.endpoint.getUri()); + endpointConfigBuilder.authenticationType(config.endpoint.getAuthentication().getType().toString()); + endpointConfigBuilder.authenticationProperties(config.endpoint.getAuthentication().getProperties() + .entrySet().stream().collect(Collectors.toMap( + Map.Entry::getKey, entry -> entry.getValue().toString()))); + authConfig.setEndpointConfig(endpointConfigBuilder.build()); + + return authConfig; + } catch (NoSuchElementException e) { + throw new IdentityProviderManagementClientException(Constants.ErrorMessage + .ERROR_CODE_INVALID_INPUT.getCode(), e.getMessage()); + } } private static void validateUserDefinedFederatedAuthenticatorModel(Config config)