diff --git a/components/org.wso2.carbon.identity.context.rewrite.valve/src/main/java/org/wso2/carbon/identity/context/rewrite/util/Utils.java b/components/org.wso2.carbon.identity.context.rewrite.valve/src/main/java/org/wso2/carbon/identity/context/rewrite/util/Utils.java index e9e2765a..aa28779d 100644 --- a/components/org.wso2.carbon.identity.context.rewrite.valve/src/main/java/org/wso2/carbon/identity/context/rewrite/util/Utils.java +++ b/components/org.wso2.carbon.identity.context.rewrite.valve/src/main/java/org/wso2/carbon/identity/context/rewrite/util/Utils.java @@ -21,7 +21,6 @@ import com.google.gson.JsonObject; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; -import org.apache.commons.lang.StringUtils; import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; @@ -77,11 +76,16 @@ public static void handleErrorResponse(int errorCode, String errorMessage, Strin response.getWriter().print(errorResponse); } - public static boolean isOrganizationPerspectiveResourceAccess() { + /** + * Check whether the requesting for organization resources under super tenant. + * + * @return True if the request send for accessing an organization of the super tenant. + */ + public static boolean isAccessingOrganizationUnderSuperTenant() { - // The root tenant domain is set for organization perspective resource access requests. + // The root tenant domain is set when accessing organization resources. String rootTenantDomain = (String) IdentityUtil.threadLocalProperties.get() .get(OrganizationManagementConstants.ROOT_TENANT_DOMAIN); - return StringUtils.isNotEmpty(rootTenantDomain); + return MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(rootTenantDomain); } } diff --git a/components/org.wso2.carbon.identity.context.rewrite.valve/src/main/java/org/wso2/carbon/identity/context/rewrite/valve/OrganizationContextRewriteValve.java b/components/org.wso2.carbon.identity.context.rewrite.valve/src/main/java/org/wso2/carbon/identity/context/rewrite/valve/OrganizationContextRewriteValve.java index 022b17e7..c70086ab 100644 --- a/components/org.wso2.carbon.identity.context.rewrite.valve/src/main/java/org/wso2/carbon/identity/context/rewrite/valve/OrganizationContextRewriteValve.java +++ b/components/org.wso2.carbon.identity.context.rewrite.valve/src/main/java/org/wso2/carbon/identity/context/rewrite/valve/OrganizationContextRewriteValve.java @@ -49,7 +49,7 @@ import static org.wso2.carbon.identity.context.rewrite.constant.RewriteConstants.TENANT_ID; import static org.wso2.carbon.identity.context.rewrite.util.Utils.getOrganizationDomainFromURL; import static org.wso2.carbon.identity.context.rewrite.util.Utils.handleErrorResponse; -import static org.wso2.carbon.identity.context.rewrite.util.Utils.isOrganizationPerspectiveResourceAccess; +import static org.wso2.carbon.identity.context.rewrite.util.Utils.isAccessingOrganizationUnderSuperTenant; import static org.wso2.carbon.identity.core.util.IdentityCoreConstants.TENANT_NAME_FROM_CONTEXT; /** @@ -76,6 +76,13 @@ public void invoke(Request request, Response response) throws IOException, Servl boolean subPathsConfigured = false; boolean isWebApp = false; + /* Organization context rewrite valve can be skipped when accessing organization under the super tenant. + Ex - /o/api/server/v1/applications */ + if (isAccessingOrganizationUnderSuperTenant()) { + getNext().invoke(request, response); + return; + } + if (ContextRewriteValveServiceComponentHolder.getInstance().isOrganizationManagementEnabled() && StringUtils.startsWith(requestURI, ORGANIZATION_PATH_PARAM)) { for (OrganizationRewriteContext organizationRewriteContext : orgContextsToRewrite) { @@ -108,10 +115,6 @@ public void invoke(Request request, Response response) throws IOException, Servl the base paths and any sub paths that might be defined under them. */ if (!orgRoutingPathSupported || (subPathsConfigured && !orgRoutingSubPathSupported)) { - if (isOrganizationPerspectiveResourceAccess()) { - getNext().invoke(request, response); - return; - } handleErrorResponse(HttpServletResponse.SC_NOT_FOUND, "Organization specific routing failed.", "Unsupported organization specific routing endpoint.", response); return; diff --git a/components/org.wso2.carbon.identity.context.rewrite.valve/src/main/java/org/wso2/carbon/identity/context/rewrite/valve/TenantContextRewriteValve.java b/components/org.wso2.carbon.identity.context.rewrite.valve/src/main/java/org/wso2/carbon/identity/context/rewrite/valve/TenantContextRewriteValve.java index 12b70fd4..e956cdc8 100644 --- a/components/org.wso2.carbon.identity.context.rewrite.valve/src/main/java/org/wso2/carbon/identity/context/rewrite/valve/TenantContextRewriteValve.java +++ b/components/org.wso2.carbon.identity.context.rewrite.valve/src/main/java/org/wso2/carbon/identity/context/rewrite/valve/TenantContextRewriteValve.java @@ -52,7 +52,7 @@ import static org.wso2.carbon.identity.context.rewrite.constant.RewriteConstants.SUPER_TENANT_QUALIFIED_REQUEST; import static org.wso2.carbon.identity.context.rewrite.constant.RewriteConstants.TENANT_DOMAIN; import static org.wso2.carbon.identity.context.rewrite.constant.RewriteConstants.TENANT_ID; -import static org.wso2.carbon.identity.context.rewrite.util.Utils.isOrganizationPerspectiveResourceAccess; +import static org.wso2.carbon.identity.context.rewrite.util.Utils.isAccessingOrganizationUnderSuperTenant; import static org.wso2.carbon.identity.core.util.IdentityCoreConstants.ENABLE_TENANT_QUALIFIED_URLS; import static org.wso2.carbon.identity.core.util.IdentityCoreConstants.TENANT_NAME_FROM_CONTEXT; @@ -87,9 +87,9 @@ public void invoke(Request request, Response response) throws IOException, Servl boolean isContextRewrite = false; boolean isWebApp = false; - /* The organization perspective resource accessed with organization qualified URL is prefixed - with super tenant qualified URL. /o/... -> /t//o/... */ - if (StringUtils.startsWith(requestURI, ORGANIZATION_PATH_PARAM) && isOrganizationPerspectiveResourceAccess()) { + /* If an organization under the super tenant is accessed with organization qualified URL, it is prefixed + with super tenant domain qualifier. /o/... -> /t//o/... */ + if (StringUtils.startsWith(requestURI, ORGANIZATION_PATH_PARAM) && isAccessingOrganizationUnderSuperTenant()) { requestURI = requestURI.replace(ORGANIZATION_PATH_PARAM, SUPER_TENANT_QUALIFIED_REQUEST); }