diff --git a/components/org.wso2.carbon.identity.organization.config.service/pom.xml b/components/org.wso2.carbon.identity.organization.config.service/pom.xml new file mode 100644 index 000000000..a8293ef44 --- /dev/null +++ b/components/org.wso2.carbon.identity.organization.config.service/pom.xml @@ -0,0 +1,89 @@ + + + + + + + org.wso2.carbon.identity.organization.management + identity-organization-management + 1.3.70-SNAPSHOT + ../../pom.xml + + + 4.0.0 + org.wso2.carbon.identity.organization.config.service + WSO2 - Organization Configuration Service + bundle + + + + org.apache.felix + org.apache.felix.scr.ds-annotations + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.configuration.mgt.core + + + org.wso2.carbon.identity.organization.management.core + org.wso2.carbon.identity.organization.management.service + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + Organization Config Service Bundle + org.wso2.carbon.identity.organization.config.service.internal + + + !org.wso2.carbon.identity.organization.config.service.internal, + org.wso2.carbon.identity.organization.config.service.*;version="${project.version}" + + + org.apache.commons.lang;version="${org.apache.commons.lang.imp.pkg.version.range}", + org.apache.commons.logging;version="${org.apache.commons.logging.imp.pkg.version.range}", + org.osgi.framework;version="${osgi.framework.imp.pkg.version.range}", + org.osgi.service.component;version="${osgi.service.component.imp.pkg.version.range}", + org.wso2.carbon.identity.configuration.mgt.core;version="${carbon.identity.package.import.version.range}", + org.wso2.carbon.identity.configuration.mgt.core.constant;version="${carbon.identity.package.import.version.range}", + org.wso2.carbon.identity.configuration.mgt.core.exception;version="${carbon.identity.package.import.version.range}", + org.wso2.carbon.identity.configuration.mgt.core.model;version="${carbon.identity.package.import.version.range}", + org.wso2.carbon.identity.organization.config.service.constant;version="${org.wso2.identity.organization.mgt.imp.pkg.version.range}", + org.wso2.carbon.identity.organization.config.service.exception;version="${org.wso2.identity.organization.mgt.imp.pkg.version.range}", + org.wso2.carbon.identity.organization.config.service.model;version="${org.wso2.identity.organization.mgt.imp.pkg.version.range}", + org.wso2.carbon.identity.organization.config.service.util;version="${org.wso2.identity.organization.mgt.imp.pkg.version.range}", + org.wso2.carbon.identity.organization.management.service;version="${org.wso2.identity.organization.mgt.core.imp.pkg.version.range}", + org.wso2.carbon.identity.organization.management.service.util;version="${org.wso2.identity.organization.mgt.core.imp.pkg.version.range}", + + + + + + + diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManager.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManager.java new file mode 100644 index 000000000..068461ed4 --- /dev/null +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManager.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.organization.config.service; + +import org.wso2.carbon.identity.organization.config.service.exception.OrganizationConfigException; +import org.wso2.carbon.identity.organization.config.service.model.DiscoveryConfig; + +/** + * Interface for organization configuration management. + */ +public interface OrganizationConfigManager { + + /** + * Add the discovery configuration of the primary organization. + * + * @param discoveryConfig The discovery configuration. + * @throws OrganizationConfigException The exception thrown when an error occurs while adding the discovery + * configuration. + */ + void addDiscoveryConfiguration(DiscoveryConfig discoveryConfig) throws OrganizationConfigException; + + /** + * Fetch the discovery configuration of the primary organization. + * + * @return the discovery configuration. + * @throws OrganizationConfigException The exception thrown when an error occurs while fetching the discovery + * configuration. + */ + DiscoveryConfig getDiscoveryConfiguration() throws OrganizationConfigException; + + /** + * Add the discovery configuration of the primary organization. + * + * @throws OrganizationConfigException The exception thrown when an error occurs while adding the discovery + * configuration. + */ + void deleteDiscoveryConfiguration() throws OrganizationConfigException; +} 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 new file mode 100644 index 000000000..b1ef13a7b --- /dev/null +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImpl.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.organization.config.service; + +import org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager; +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.OrganizationConfigException; +import org.wso2.carbon.identity.organization.config.service.internal.OrganizationConfigServiceHolder; +import org.wso2.carbon.identity.organization.config.service.model.ConfigProperty; +import org.wso2.carbon.identity.organization.config.service.model.DiscoveryConfig; +import org.wso2.carbon.identity.organization.management.service.OrganizationManager; +import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementServerException; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +import static org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCE_DOES_NOT_EXISTS; +import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_DISCOVERY_CONFIG_CONFLICT; +import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_DISCOVERY_CONFIG_NOT_EXIST; +import static org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants.ErrorMessages.ERROR_CODE_DISCOVERY_CONFIG_UPDATE_NOT_ALLOWED; +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.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.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; + +/** + * Implementation of Organization Configuration Manager Interface. + */ +public class OrganizationConfigManagerImpl implements OrganizationConfigManager { + + @Override + public void addDiscoveryConfiguration(DiscoveryConfig discoveryConfig) throws OrganizationConfigException { + + try { + if (!isDiscoveryConfigChangeAllowed()) { + throw handleClientException(ERROR_CODE_DISCOVERY_CONFIG_UPDATE_NOT_ALLOWED); + } + Optional resourceOptional = getDiscoveryResource(); + if (resourceOptional.isPresent()) { + throw handleClientException(ERROR_CODE_DISCOVERY_CONFIG_CONFLICT, getOrganizationId()); + } + Resource resource = buildResourceFromValidationConfig(discoveryConfig); + getConfigurationManager().addResource(RESOURCE_TYPE_NAME, resource); + } catch (ConfigurationManagementException | OrganizationManagementServerException e) { + throw handleServerException(ERROR_CODE_ERROR_ADDING_DISCOVERY_CONFIG, e, getOrganizationId()); + } + } + + @Override + public DiscoveryConfig getDiscoveryConfiguration() throws OrganizationConfigException { + + Optional resourceOptional = getDiscoveryResource(); + if (!resourceOptional.isPresent()) { + throw handleClientException(ERROR_CODE_DISCOVERY_CONFIG_NOT_EXIST, getOrganizationId()); + } + List configProperties = resourceOptional.map(resource -> resource.getAttributes().stream() + .map(attribute -> new ConfigProperty(attribute.getKey(), attribute.getValue())) + .collect(Collectors.toList())).orElse(Collections.emptyList()); + return new DiscoveryConfig(configProperties); + } + + @Override + public void deleteDiscoveryConfiguration() throws OrganizationConfigException { + + try { + if (!isDiscoveryConfigChangeAllowed()) { + throw handleClientException(ERROR_CODE_DISCOVERY_CONFIG_UPDATE_NOT_ALLOWED); + } + Optional resourceOptional = getDiscoveryResource(); + if (resourceOptional.isPresent()) { + getConfigurationManager().deleteResource(RESOURCE_TYPE_NAME, RESOURCE_NAME); + } + } catch (ConfigurationManagementException | OrganizationManagementServerException e) { + throw handleServerException(ERROR_CODE_ERROR_DELETING_DISCOVERY_CONFIG, e, getOrganizationId()); + } + } + + private Optional getDiscoveryResource() throws OrganizationConfigException { + + try { + return Optional.ofNullable(getConfigurationManager().getResource(RESOURCE_TYPE_NAME, RESOURCE_NAME)); + } catch (ConfigurationManagementException e) { + // If the resource not exists handling it as null and throw different error code. + if (!ERROR_CODE_RESOURCE_DOES_NOT_EXISTS.getCode().equals(e.getErrorCode())) { + throw handleServerException(ERROR_CODE_ERROR_RETRIEVING_DISCOVERY_CONFIG, e, getOrganizationId()); + } + } + return Optional.empty(); + } + + private boolean isDiscoveryConfigChangeAllowed() throws OrganizationManagementServerException { + + return getOrganizationManager().isPrimaryOrganization(getOrganizationId()); + } + + private Resource buildResourceFromValidationConfig(DiscoveryConfig discoveryConfig) { + + Map configAttributes = new HashMap<>(); + for (ConfigProperty property : discoveryConfig.getConfigProperties()) { + configAttributes.put(property.getKey(), property.getValue()); + } + List resourceAttributes = configAttributes.entrySet().stream() + .filter(attribute -> attribute.getValue() != null && !"null".equals(attribute.getValue())) + .map(attribute -> new Attribute(attribute.getKey(), attribute.getValue())) + .collect(Collectors.toList()); + Resource resource = new Resource(); + resource.setResourceName(RESOURCE_NAME); + resource.setAttributes(resourceAttributes); + return resource; + } + + private ConfigurationManager getConfigurationManager() { + + return OrganizationConfigServiceHolder.getInstance().getConfigurationManager(); + } + + private OrganizationManager getOrganizationManager() { + + return OrganizationConfigServiceHolder.getInstance().getOrganizationManager(); + } +} 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 new file mode 100644 index 000000000..c1de8667a --- /dev/null +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/constant/OrganizationConfigConstants.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.organization.config.service.constant; + +/** + * 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"; + private static final String ORGANIZATION_CONFIGURATION_ERROR_CODE_PREFIX = "OCM-"; + + /** + * Enum for error messages related to organization management. + */ + public enum ErrorMessages { + + // Client errors. + ERROR_CODE_DISCOVERY_CONFIG_UPDATE_NOT_ALLOWED("60001", "Can't modify the organization discovery " + + "configuration.", "Only the primary organization has the authority to modify the organization " + + "discovery configuration."), + ERROR_CODE_DISCOVERY_CONFIG_NOT_EXIST("60002", "No organization discovery configuration found.", + "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."), + + // Server errors. + ERROR_CODE_ERROR_ADDING_DISCOVERY_CONFIG("65001", "Unable to add the organization discovery " + + "configuration.", "Server encountered an error while adding the organization discovery " + + "configuration for organization with ID: %s."), + ERROR_CODE_ERROR_RETRIEVING_DISCOVERY_CONFIG("65002", "Unable to retrieve the organization " + + "discovery configuration.", "Server encountered an error while retrieving the organization discovery " + + "configuration for organization with ID: %s."), + ERROR_CODE_ERROR_DELETING_DISCOVERY_CONFIG("65003", "Unable to delete the organization discovery " + + "configuration.", "Server encountered an error while deleting the organization discovery " + + "configuration for the organization with id: %s"); + + private final String code; + private final String message; + private final String description; + + ErrorMessages(String code, String message, String description) { + + this.code = code; + this.message = message; + this.description = description; + } + + public String getCode() { + + return ORGANIZATION_CONFIGURATION_ERROR_CODE_PREFIX + code; + } + + public String getMessage() { + + return message; + } + + public String getDescription() { + + return description; + } + } +} diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/exception/OrganizationConfigClientException.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/exception/OrganizationConfigClientException.java new file mode 100644 index 000000000..cffb1252d --- /dev/null +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/exception/OrganizationConfigClientException.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.organization.config.service.exception; + +/** + * This exception class is to represent client side errors related to organization configurations. + */ +public class OrganizationConfigClientException extends OrganizationConfigException { + + public OrganizationConfigClientException(String message) { + + super(message); + } + + public OrganizationConfigClientException(String errorCode, String message, String description) { + + super(errorCode, message, description); + } + + public OrganizationConfigClientException(String errorCode, String message, String description, Throwable cause) { + + super(errorCode, message, description, cause); + } +} diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/exception/OrganizationConfigException.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/exception/OrganizationConfigException.java new file mode 100644 index 000000000..a90bddb30 --- /dev/null +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/exception/OrganizationConfigException.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.organization.config.service.exception; + +/** + * Base exception class for organization configurations. + */ +public class OrganizationConfigException extends Exception { + + private String errorCode; + private String description; + + public OrganizationConfigException(String message) { + + super(message); + } + + public OrganizationConfigException(String errorCode, String message) { + + super(message); + this.errorCode = errorCode; + } + + public OrganizationConfigException(String errorCode, String message, Throwable cause) { + + super(message, cause); + this.errorCode = errorCode; + } + + public OrganizationConfigException(String errorCode, String message, String description) { + + super(message); + this.errorCode = errorCode; + this.description = description; + } + + public OrganizationConfigException(String errorCode, String message, String description, Throwable cause) { + + super(message, cause); + this.errorCode = errorCode; + this.description = description; + } + + public String getErrorCode() { + + return errorCode; + } + + public void setErrorCode(String errorCode) { + + this.errorCode = errorCode; + } + + public String getDescription() { + + return description; + } + + public void setDescription(String description) { + + this.description = description; + } +} diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/exception/OrganizationConfigServerException.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/exception/OrganizationConfigServerException.java new file mode 100644 index 000000000..e283176b9 --- /dev/null +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/exception/OrganizationConfigServerException.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.organization.config.service.exception; + +/** + * Organization configuration server exception. + */ +public class OrganizationConfigServerException extends OrganizationConfigException { + + public OrganizationConfigServerException(String message) { + + super(message); + } + + public OrganizationConfigServerException(String errorCode, String message, String description) { + + super(errorCode, message, description); + } + + public OrganizationConfigServerException(String errorCode, String message, String description, Throwable cause) { + + super(errorCode, message, description, cause); + } +} diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/internal/OrganizationConfigServiceComponent.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/internal/OrganizationConfigServiceComponent.java new file mode 100644 index 000000000..22d4bf544 --- /dev/null +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/internal/OrganizationConfigServiceComponent.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.organization.config.service.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; +import org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager; +import org.wso2.carbon.identity.organization.config.service.OrganizationConfigManager; +import org.wso2.carbon.identity.organization.config.service.OrganizationConfigManagerImpl; +import org.wso2.carbon.identity.organization.management.service.OrganizationManager; + +/** + * Service component class for the organization configuration service. + */ +@Component( + name = "org.wso2.carbon.identity.organization.config.service", + immediate = true) +public class OrganizationConfigServiceComponent { + + private static final Log LOG = LogFactory.getLog(OrganizationConfigServiceComponent.class); + + @Activate + protected void activate(ComponentContext componentContext) { + + BundleContext bundleContext = componentContext.getBundleContext(); + bundleContext.registerService(OrganizationConfigManager.class.getName(), new OrganizationConfigManagerImpl(), + null); + LOG.debug("Organization configuration service component activated successfully."); + } + + @Reference( + name = "resource.configuration.manager", + service = ConfigurationManager.class, + cardinality = ReferenceCardinality.MANDATORY, + policy = ReferencePolicy.DYNAMIC, + unbind = "unsetConfigurationManager" + ) + protected void setConfigurationManager(ConfigurationManager configurationManager) { + + OrganizationConfigServiceHolder.getInstance().setConfigurationManager(configurationManager); + } + + protected void unsetConfigurationManager(ConfigurationManager configurationManager) { + + OrganizationConfigServiceHolder.getInstance().setConfigurationManager(null); + } + + @Reference(name = "identity.organization.management.component", + service = OrganizationManager.class, + cardinality = ReferenceCardinality.MANDATORY, + policy = ReferencePolicy.DYNAMIC, + unbind = "unsetOrganizationManager") + protected void setOrganizationManager(OrganizationManager organizationManager) { + + OrganizationConfigServiceHolder.getInstance().setOrganizationManager(organizationManager); + } + + protected void unsetOrganizationManager(OrganizationManager organizationManager) { + + OrganizationConfigServiceHolder.getInstance().setOrganizationManager(null); + } +} diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/internal/OrganizationConfigServiceHolder.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/internal/OrganizationConfigServiceHolder.java new file mode 100644 index 000000000..2e3a7e396 --- /dev/null +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/internal/OrganizationConfigServiceHolder.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.organization.config.service.internal; + +import org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager; +import org.wso2.carbon.identity.organization.management.service.OrganizationManager; + +/** + * Organization configuration data holder. + */ +public class OrganizationConfigServiceHolder { + + private static final OrganizationConfigServiceHolder instance = new OrganizationConfigServiceHolder(); + private ConfigurationManager configurationManager = null; + private OrganizationManager organizationManager = null; + + public static OrganizationConfigServiceHolder getInstance() { + + return instance; + } + + public ConfigurationManager getConfigurationManager() { + + return configurationManager; + } + + public void setConfigurationManager(ConfigurationManager configurationManager) { + + this.configurationManager = configurationManager; + } + + public OrganizationManager getOrganizationManager() { + + return organizationManager; + } + + public void setOrganizationManager(OrganizationManager organizationManager) { + + this.organizationManager = organizationManager; + } +} diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/model/ConfigProperty.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/model/ConfigProperty.java new file mode 100644 index 000000000..f6818ebfa --- /dev/null +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/model/ConfigProperty.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.organization.config.service.model; + +/** + * This class represents the configuration property. + */ +public class ConfigProperty { + + private String key; + private String value; + + public ConfigProperty(String key, String value) { + + this.key = key; + this.value = value; + } + + public String getKey() { + + return key; + } + + public void setKey(String key) { + + this.key = key; + } + + public String getValue() { + + return value; + } + + public void setValue(String value) { + + this.value = value; + } +} diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/model/DiscoveryConfig.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/model/DiscoveryConfig.java new file mode 100644 index 000000000..781be1f29 --- /dev/null +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/model/DiscoveryConfig.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.organization.config.service.model; + +import java.util.List; + +/** + * This class represents the organization discovery configuration. + */ +public class DiscoveryConfig { + + private List configProperties; + + public DiscoveryConfig(List configProperties) { + + this.configProperties = configProperties; + } + + public List getConfigProperties() { + + return configProperties; + } + + public void setConfigProperties(List configProperties) { + + this.configProperties = configProperties; + } +} diff --git a/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/util/Utils.java b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/util/Utils.java new file mode 100644 index 000000000..8c8a9e571 --- /dev/null +++ b/components/org.wso2.carbon.identity.organization.config.service/src/main/java/org/wso2/carbon/identity/organization/config/service/util/Utils.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.organization.config.service.util; + +import org.apache.commons.lang.ArrayUtils; +import org.wso2.carbon.identity.organization.config.service.constant.OrganizationConfigConstants; +import org.wso2.carbon.identity.organization.config.service.exception.OrganizationConfigClientException; +import org.wso2.carbon.identity.organization.config.service.exception.OrganizationConfigServerException; + +/** + * This class provides utility functions for the organization configuration management. + */ +public class Utils { + + /** + * Throw an OrganizationConfigClientException upon client side error in organization configuration management. + * + * @param error The error enum. + * @param data The error message data. + * @return OrganizationConfigClientException + */ + public static OrganizationConfigClientException handleClientException( + OrganizationConfigConstants.ErrorMessages error, String... data) { + + String description = error.getDescription(); + if (ArrayUtils.isNotEmpty(data)) { + description = String.format(description, data); + } + return new OrganizationConfigClientException(error.getCode(), error.getMessage(), description); + } + + /** + * Throw an OrganizationConfigServerException upon server side error in organization management. + * + * @param error The error enum. + * @param e The error. + * @param data The error message data. + * @return OrganizationConfigServerException + */ + public static OrganizationConfigServerException handleServerException( + OrganizationConfigConstants.ErrorMessages error, Throwable e, String... data) { + + String description = error.getDescription(); + if (ArrayUtils.isNotEmpty(data)) { + description = String.format(description, data); + } + return new OrganizationConfigServerException(error.getCode(), error.getMessage(), description, e); + } +} diff --git a/features/org.wso2.carbon.identity.organization.management.server.feature/pom.xml b/features/org.wso2.carbon.identity.organization.management.server.feature/pom.xml index efd67034d..054faac84 100644 --- a/features/org.wso2.carbon.identity.organization.management.server.feature/pom.xml +++ b/features/org.wso2.carbon.identity.organization.management.server.feature/pom.xml @@ -71,6 +71,10 @@ org.wso2.carbon.identity.organization.management org.wso2.carbon.identity.organization.user.invitation.management + + org.wso2.carbon.identity.organization.management + org.wso2.carbon.identity.organization.config.service + @@ -105,6 +109,7 @@ org.wso2.carbon.identity.organization.management:org.wso2.carbon.identity.organization.management.claim.provider org.wso2.carbon.identity.organization.management:org.wso2.carbon.identity.organization.management.governance.connector org.wso2.carbon.identity.organization.management:org.wso2.carbon.identity.organization.user.invitation.management + org.wso2.carbon.identity.organization.management:org.wso2.carbon.identity.organization.config.service org.wso2.carbon.core:compatible:${carbon.kernel.feature.version} diff --git a/pom.xml b/pom.xml index ac2764ac3..49e9e53e7 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,7 @@ components/org.wso2.carbon.identity.organization.management.claim.provider components/org.wso2.carbon.identity.organization.management.governance.connector components/org.wso2.carbon.identity.organization.user.invitation.management + components/org.wso2.carbon.identity.organization.config.service @@ -165,6 +166,12 @@ ${project.version} provided + + org.wso2.carbon.identity.organization.management + org.wso2.carbon.identity.organization.config.service + ${project.version} + provided + org.wso2.carbon.identity.framework @@ -196,6 +203,11 @@ org.wso2.carbon.idp.mgt ${carbon.identity.framework.version} + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.configuration.mgt.core + ${carbon.identity.framework.version} + org.wso2.carbon.identity.inbound.auth.oauth2 org.wso2.carbon.identity.oauth