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 index 23c78d1bc..1056790dc 100644 --- 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 @@ -51,4 +51,14 @@ public interface OrganizationConfigManager { * configuration. */ void deleteDiscoveryConfiguration() throws OrganizationConfigException; + + /** + * Fetch the discovery configuration by the tenant ID. + * + * @param tenantId The tenant ID. + * @return The discovery configuration. + * @throws OrganizationConfigException The exception thrown when an error occurs while fetching the discovery + * configuration. + */ + DiscoveryConfig getDiscoveryConfigurationByTenantId(int tenantId) 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 index 2979adbc4..6ddd75597 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 @@ -78,14 +78,7 @@ public void addDiscoveryConfiguration(DiscoveryConfig discoveryConfig) throws Or @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); + return getDiscoveryConfiguration(getDiscoveryResource()); } @Override @@ -104,6 +97,26 @@ public void deleteDiscoveryConfiguration() throws OrganizationConfigException { } } + @Override + public DiscoveryConfig getDiscoveryConfigurationByTenantId(int tenantId) throws OrganizationConfigException { + + return getDiscoveryConfiguration(getDiscoveryResourceByTenantId(tenantId)); + } + + private DiscoveryConfig getDiscoveryConfiguration(Optional resourceOptional) + throws OrganizationConfigException { + + 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); + } + private Optional getDiscoveryResource() throws OrganizationConfigException { try { @@ -116,6 +129,19 @@ private Optional getDiscoveryResource() throws OrganizationConfigExcep return Optional.empty(); } + private Optional getDiscoveryResourceByTenantId(int tenantId) throws OrganizationConfigException { + + try { + return Optional.ofNullable(getConfigurationManager().getResourceByTenantId(tenantId, 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()); diff --git a/pom.xml b/pom.xml index 9f6231c82..8df81ad2b 100644 --- a/pom.xml +++ b/pom.xml @@ -491,7 +491,7 @@ [1.0.0,2.0.0) - 1.0.67 + 1.0.69 [1.0.0,2.0.0) @@ -499,7 +499,7 @@ [4.7.0,5.0.0) - 5.25.396 + 5.25.400 [5.20.0, 7.0.0)