diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/ConfigurationFacade.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/ConfigurationFacade.java index 37d0adbe9966..2c5d946292b1 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/ConfigurationFacade.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/ConfigurationFacade.java @@ -21,6 +21,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.application.authentication.framework.config.builder.FileBasedConfigurationBuilder; import org.wso2.carbon.identity.application.authentication.framework.config.loader.UIBasedConfigurationLoader; import org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig; @@ -323,7 +324,9 @@ private String buildUrl(String defaultContext, Supplier getValueFromFile if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) { try { - return ServiceURLBuilder.create().addPath(defaultContext).build().getAbsolutePublicURL(); + String organizationId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getOrganizationId(); + return ServiceURLBuilder.create().addPath(defaultContext).setOrganization(organizationId).build() + .getAbsolutePublicURL(); } catch (URLBuilderException e) { throw new IdentityRuntimeException( "Error while building tenant qualified url for context: " + defaultContext, e); diff --git a/components/identity-core/org.wso2.carbon.identity.core/pom.xml b/components/identity-core/org.wso2.carbon.identity.core/pom.xml index 00647927a53a..76b27fa0cc86 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/pom.xml +++ b/components/identity-core/org.wso2.carbon.identity.core/pom.xml @@ -82,6 +82,11 @@ org.wso2.carbon org.wso2.carbon.user.core + + org.wso2.carbon.identity.organization.management.core + org.wso2.carbon.identity.organization.management.service + provided + org.apache.ws.commons.axiom.wso2 axiom diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/DefaultServiceURLBuilder.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/DefaultServiceURLBuilder.java index 6dedf163eb86..23aa6c127e38 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/DefaultServiceURLBuilder.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/DefaultServiceURLBuilder.java @@ -28,6 +28,7 @@ import org.wso2.carbon.identity.core.util.IdentityCoreConstants; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.identity.core.util.IdentityUtil; +import org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants; import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.NetworkUtils; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; @@ -126,15 +127,7 @@ protected String getResolvedUrlPath(String tenantDomain) { if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled() && !resolvedUrlContext.startsWith("t/") && !resolvedUrlContext.startsWith("o/")) { if (isSuperTenantRequiredInUrl() || isNotSuperTenant(tenantDomain)) { - String organizationId = StringUtils.isNotBlank(orgId) ? orgId : - PrivilegedCarbonContext.getThreadLocalCarbonContext().getOrganizationId(); - if (organizationId != null) { - // When requesting from an organization qualified url, the service urls should also be organization - // qualified. - resolvedUrlStringBuilder.append("/o/").append(organizationId); - } else { - resolvedUrlStringBuilder.append("/t/").append(tenantDomain); - } + setURL(resolvedUrlStringBuilder, tenantDomain); } } @@ -470,6 +463,33 @@ protected void appendContextToUri(StringBuilder serverUrl, String contextPath) { } } + private void setURL(StringBuilder resolvedUrlStringBuilder, String tenantDomain) { + + // ####### Organization perspective resource URL building. + // if organization ID is explicitly set, build an organization qualified URL. + if (StringUtils.isNotEmpty(this.orgId)) { + // The service urls are requested to be organization qualified. + resolvedUrlStringBuilder.append("/o/").append(this.orgId); + return; + } + /* If the root tenant domain of the accessed organization is set in the thread local properties, use it to build + the URL in the form of /t//o */ + String rootTenantDomain = (String) IdentityUtil.threadLocalProperties.get() + .get(OrganizationManagementConstants.ROOT_TENANT_DOMAIN); + if (StringUtils.isNotEmpty(rootTenantDomain)) { + // Set root tenant domain when resource accessed with organization perspective. + resolvedUrlStringBuilder.append("/t/").append(rootTenantDomain).append("/o"); + return; + } + String organizationId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getOrganizationId(); + if (StringUtils.isNotEmpty(organizationId)) { + resolvedUrlStringBuilder.append("/o/").append(organizationId); + return; + } + // ####### Tenant perspective resource URL building. + resolvedUrlStringBuilder.append("/t/").append(tenantDomain); + } + protected static class ServiceURLImpl implements ServiceURL { private String protocol; diff --git a/pom.xml b/pom.xml index f7b90ce7c084..81bbf8ed03dd 100644 --- a/pom.xml +++ b/pom.xml @@ -1885,7 +1885,7 @@ ${project.version} [5.14.0, 6.0.0) - 1.0.70 + 1.0.85 [1.0.0, 2.0.0)