Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sadilchamishka committed Nov 27, 2023
1 parent 18dad43 commit a214796
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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/<carbon.super>/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/<carbon.super>/o/... */
if (StringUtils.startsWith(requestURI, ORGANIZATION_PATH_PARAM) && isAccessingOrganizationUnderSuperTenant()) {
requestURI = requestURI.replace(ORGANIZATION_PATH_PARAM, SUPER_TENANT_QUALIFIED_REQUEST);
}

Expand Down

0 comments on commit a214796

Please sign in to comment.