Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate if the discovery attribute key is supported #247

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading