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 tenant context rewrite valve to support organization perspective APIs #247

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 @@ -33,7 +33,7 @@ public RewriteContext(boolean isWebApp, String context) {

this.isWebApp = isWebApp;
this.context = context;
this.tenantContextPattern = Pattern.compile("^/t/([^/]+)" + context);
this.tenantContextPattern = Pattern.compile("^/t/([^/]+(?:/o)?)" + context);
this.baseContextPattern = Pattern.compile("^" + context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;

import static org.wso2.carbon.identity.context.rewrite.constant.RewriteConstants.ORGANIZATION_PATH_PARAM;
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.core.util.IdentityCoreConstants.ENABLE_TENANT_QUALIFIED_URLS;
Expand Down Expand Up @@ -108,7 +110,6 @@ public void invoke(Request request, Response response) throws IOException, Servl
}
}


String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try {
MDC.put(TENANT_DOMAIN, tenantDomain);
Expand Down Expand Up @@ -143,6 +144,14 @@ public void invoke(Request request, Response response) throws IOException, Servl

if (isWebApp) {
String dispatchLocation = "/" + requestURI.replaceAll("/t/.*" + contextToForward, "");
/* Verify the request not start with /o/ for backward compatibility. If /o/ path is found middle of
the request it should be dispatched to organization APIs.
Ex-: Request: /t/<tenant-domain>/o/api/server/v1/applications --> /o/server/v1/applications
*/
if (!requestURI.startsWith(ORGANIZATION_PATH_PARAM) &&
requestURI.contains(ORGANIZATION_PATH_PARAM)) {
dispatchLocation = "/o" + dispatchLocation;
}
if (contextListToOverwriteDispatch.contains(contextToForward) && !isIgnorePath(dispatchLocation)) {
dispatchLocation = "/";
}
Expand Down Expand Up @@ -195,6 +204,7 @@ private boolean isTenantQualifiedUrlsEnabled() {
}

private List<RewriteContext> getContextsToRewrite() {

List<RewriteContext> rewriteContexts = new ArrayList<>();
Map<String, Object> configuration = IdentityConfigParser.getInstance().getConfiguration();
Object webAppContexts = configuration.get("TenantContextsToRewrite.WebApp.Context");
Expand Down
Loading