diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImpl.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImpl.java index 88411875a..2979adbc4 100644 --- a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImpl.java +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImpl.java @@ -22,6 +22,7 @@ import org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException; import org.wso2.carbon.identity.configuration.mgt.core.model.Attribute; import org.wso2.carbon.identity.configuration.mgt.core.model.Resource; +import org.wso2.carbon.identity.organization.config.service.exception.OrganizationConfigClientException; import org.wso2.carbon.identity.organization.config.service.exception.OrganizationConfigException; import org.wso2.carbon.identity.organization.config.service.internal.OrganizationConfigServiceHolder; import org.wso2.carbon.identity.organization.config.service.model.ConfigProperty; @@ -43,8 +44,10 @@ import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_ERROR_ADDING_DISCOVERY_CONFIG; import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_ERROR_DELETING_DISCOVERY_CONFIG; import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_ERROR_RETRIEVING_DISCOVERY_CONFIG; +import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_INVALID_DISCOVERY_ATTRIBUTE; import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.RESOURCE_NAME; import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.RESOURCE_TYPE_NAME; +import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.SUPPORTED_DISCOVERY_ATTRIBUTE_KEYS; import static org.wso2.carbon.identity.organization.config.service.util.Utils.handleClientException; import static org.wso2.carbon.identity.organization.config.service.util.Utils.handleServerException; import static org.wso2.carbon.identity.organization.management.service.util.Utils.getOrganizationId; @@ -118,11 +121,16 @@ private boolean isDiscoveryConfigChangeAllowed() throws OrganizationManagementSe return getOrganizationManager().isPrimaryOrganization(getOrganizationId()); } - private Resource buildResourceFromValidationConfig(DiscoveryConfig discoveryConfig) { + private Resource buildResourceFromValidationConfig(DiscoveryConfig discoveryConfig) + throws OrganizationConfigClientException { Map configAttributes = new HashMap<>(); for (ConfigProperty property : discoveryConfig.getConfigProperties()) { - configAttributes.put(property.getKey(), property.getValue()); + String key = property.getKey(); + if (!SUPPORTED_DISCOVERY_ATTRIBUTE_KEYS.contains(key)) { + throw handleClientException(ERROR_CODE_INVALID_DISCOVERY_ATTRIBUTE, key); + } + configAttributes.put(key, property.getValue()); } List resourceAttributes = configAttributes.entrySet().stream() .filter(attribute -> attribute.getValue() != null && !"null".equals(attribute.getValue())) diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/constant/OrganizationConfigConstants.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/constant/OrganizationConfigConstants.java index c1de8667a..bbf64eff2 100644 --- a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/constant/OrganizationConfigConstants.java +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/constant/OrganizationConfigConstants.java @@ -18,6 +18,9 @@ package org.wso2.carbon.identity.organization.config.service.constant; +import java.util.Collections; +import java.util.List; + /** * Contains constants related to organization configuration management. */ @@ -25,6 +28,8 @@ public class OrganizationConfigConstants { public static final String RESOURCE_TYPE_NAME = "ORGANIZATION_CONFIGURATION"; public static final String RESOURCE_NAME = "OrganizationDiscovery"; + public static final List SUPPORTED_DISCOVERY_ATTRIBUTE_KEYS = + Collections.singletonList("emailDomain.enable"); private static final String ORGANIZATION_CONFIGURATION_ERROR_CODE_PREFIX = "OCM-"; /** @@ -40,6 +45,8 @@ public enum ErrorMessages { "There is no organization discovery configuration for organization with ID: %s."), ERROR_CODE_DISCOVERY_CONFIG_CONFLICT("60003", "The organization discovery configuration already exists.", "The organization discovery configuration is already for available for the organization with id: %s."), + ERROR_CODE_INVALID_DISCOVERY_ATTRIBUTE("60004", "Invalid organization discovery attribute.", + "The organization discovery attribute with key: %s is not supported."), // Server errors. ERROR_CODE_ERROR_ADDING_DISCOVERY_CONFIG("65001", "Unable to add the organization discovery " +