-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add organization configuration service #246
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
components/org.wso2.carbon.identity.organization.config.service/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<parent> | ||
<groupId>org.wso2.carbon.identity.organization.management</groupId> | ||
<artifactId>identity-organization-management</artifactId> | ||
<version>1.3.70-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>org.wso2.carbon.identity.organization.config.service</artifactId> | ||
<name>WSO2 - Organization Configuration Service</name> | ||
<packaging>bundle</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>org.apache.felix.scr.ds-annotations</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wso2.carbon.identity.framework</groupId> | ||
<artifactId>org.wso2.carbon.identity.configuration.mgt.core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wso2.carbon.identity.organization.management.core</groupId> | ||
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<instructions> | ||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> | ||
<Bundle-Name>${project.artifactId}</Bundle-Name> | ||
<Bundle-Description>Organization Config Service Bundle</Bundle-Description> | ||
<Private-Package>org.wso2.carbon.identity.organization.config.service.internal | ||
</Private-Package> | ||
<Export-Package> | ||
!org.wso2.carbon.identity.organization.config.service.internal, | ||
org.wso2.carbon.identity.organization.config.service.*;version="${project.version}" | ||
</Export-Package> | ||
<Import-Package> | ||
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.exception;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}", | ||
</Import-Package> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
54 changes: 54 additions & 0 deletions
54
.../java/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
/** | ||
* Delete the discovery configuration of the primary organization. | ||
* | ||
* @throws OrganizationConfigException The exception thrown when an error occurs while deleting the discovery | ||
* configuration. | ||
*/ | ||
void deleteDiscoveryConfiguration() throws OrganizationConfigException; | ||
} |
146 changes: 146 additions & 0 deletions
146
...a/org/wso2/carbon/identity/organization/config/service/OrganizationConfigManagerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* 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<Resource> 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<Resource> resourceOptional = getDiscoveryResource(); | ||
if (!resourceOptional.isPresent()) { | ||
throw handleClientException(ERROR_CODE_DISCOVERY_CONFIG_NOT_EXIST, getOrganizationId()); | ||
} | ||
List<ConfigProperty> 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<Resource> 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<Resource> getDiscoveryResource() throws OrganizationConfigException { | ||
|
||
try { | ||
return Optional.ofNullable(getConfigurationManager().getResource(RESOURCE_TYPE_NAME, RESOURCE_NAME)); | ||
} catch (ConfigurationManagementException e) { | ||
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<String, String> configAttributes = new HashMap<>(); | ||
for (ConfigProperty property : discoveryConfig.getConfigProperties()) { | ||
configAttributes.put(property.getKey(), property.getValue()); | ||
} | ||
List<Attribute> 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(); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...so2/carbon/identity/organization/config/service/constant/OrganizationConfigConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that configuration manager get tenant id/tenant domain from the thread local? Is that the reason not to pass the tenant id/ domain from this service level it self ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it is picked from the thread local.
refer: https://github.com/wso2/carbon-identity-framework/blob/c750169c4818afed19155b8a0fbd9549b63ae115/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.core/src/main/java/org/wso2/carbon/identity/configuration/mgt/core/dao/impl/ConfigurationDAOImpl.java#L689