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

Improve the service URL builder logic for organization perspective access #5148

Merged
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 @@ -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;
Expand Down Expand Up @@ -323,7 +324,9 @@ private String buildUrl(String defaultContext, Supplier<String> 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();
sadilchamishka marked this conversation as resolved.
Show resolved Hide resolved
} catch (URLBuilderException e) {
throw new IdentityRuntimeException(
"Error while building tenant qualified url for context: " + defaultContext, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management.core</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom.wso2</groupId>
<artifactId>axiom</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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/<tenant-domain>/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;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@
<carbon.identity.package.export.version>${project.version}</carbon.identity.package.export.version>
<carbon.identity.package.import.version.range>[5.14.0, 6.0.0)</carbon.identity.package.import.version.range>

<org.wso2.carbon.identity.organization.management.core.version>1.0.70
<org.wso2.carbon.identity.organization.management.core.version>1.0.85
</org.wso2.carbon.identity.organization.management.core.version>
<org.wso2.carbon.identity.organization.management.core.version.range>[1.0.0, 2.0.0)
</org.wso2.carbon.identity.organization.management.core.version.range>
Expand Down
Loading