Skip to content

Commit

Permalink
Merge pull request #247 from dewniMW/config-imp
Browse files Browse the repository at this point in the history
Validate if the discovery attribute key is supported
  • Loading branch information
dewniMW authored Sep 25, 2023
2 parents bfd39ec + 88a7354 commit d930a98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, String> 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<Attribute> resourceAttributes = configAttributes.entrySet().stream()
.filter(attribute -> attribute.getValue() != null && !"null".equals(attribute.getValue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@

package org.wso2.carbon.identity.organization.config.service.constant;

import java.util.Collections;
import java.util.List;

/**
* Contains constants related to organization configuration management.
*/
public class OrganizationConfigConstants {

public static final String RESOURCE_TYPE_NAME = "ORGANIZATION_CONFIGURATION";
public static final String RESOURCE_NAME = "OrganizationDiscovery";
public static final List<String> SUPPORTED_DISCOVERY_ATTRIBUTE_KEYS =
Collections.singletonList("emailDomain.enable");
private static final String ORGANIZATION_CONFIGURATION_ERROR_CODE_PREFIX = "OCM-";

/**
Expand All @@ -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 " +
Expand Down

0 comments on commit d930a98

Please sign in to comment.