From c69513e0f5fd79c8bdec3b292ef4ff195324ba49 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 5 Jan 2017 17:51:23 +0530 Subject: [PATCH] removed tenant domain from the web.xml --- .../webapp/publisher/APIPublisherUtil.java | 19 +++++++++++++++---- .../APIPublisherLifecycleListener.java | 5 +++++ .../authorizer/WebappTenantAuthorizer.java | 6 +++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java index 6d1bc7695b..a4f0a0d954 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java @@ -29,7 +29,10 @@ import org.wso2.carbon.apimgt.webapp.publisher.config.APIResource; import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration; import org.wso2.carbon.apimgt.webapp.publisher.config.WebappPublisherConfig; import org.wso2.carbon.base.MultitenantConstants; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.core.util.Utils; +import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import javax.servlet.ServletContext; import java.util.*; @@ -42,7 +45,6 @@ public class APIPublisherUtil { private static final String DEFAULT_API_VERSION = "1.0.0"; private static final String API_CONFIG_DEFAULT_VERSION = "1.0.0"; private static final String PARAM_MANAGED_API_ENDPOINT = "managed-api-endpoint"; - private static final String PARAM_MANAGED_API_OWNER = "managed-api-owner"; private static final String PARAM_MANAGED_API_TRANSPORTS = "managed-api-transports"; private static final String PARAM_MANAGED_API_POLICY = "managed-api-policy"; private static final String PARAM_MANAGED_API_IS_SECURED = "managed-api-isSecured"; @@ -193,7 +195,8 @@ public class APIPublisherUtil { * @param apiDef * @return */ - public static APIConfig buildApiConfig(ServletContext servletContext, APIResourceConfiguration apiDef) { + public static APIConfig buildApiConfig(ServletContext servletContext, APIResourceConfiguration apiDef) + throws UserStoreException { APIConfig apiConfig = new APIConfig(); String name = apiDef.getName(); @@ -233,7 +236,8 @@ public class APIPublisherUtil { apiConfig.setTags(tags); } - String tenantDomain = servletContext.getInitParameter(PARAM_PROVIDER_TENANT_DOMAIN); + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + servletContext.setAttribute(PARAM_PROVIDER_TENANT_DOMAIN, tenantDomain); tenantDomain = (tenantDomain != null && !tenantDomain.isEmpty()) ? tenantDomain : MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; apiConfig.setTenantDomain(tenantDomain); @@ -253,7 +257,11 @@ public class APIPublisherUtil { } apiConfig.setEndpoint(endpoint); - String owner = servletContext.getInitParameter(PARAM_MANAGED_API_OWNER); + String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration() + .getAdminUserName(); + if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { + owner = owner + "@" + tenantDomain; + } if (owner == null || owner.isEmpty()) { if (log.isDebugEnabled()) { log.debug("'managed-api-owner' attribute is not configured"); @@ -286,6 +294,9 @@ public class APIPublisherUtil { String sharingValueParam = servletContext.getInitParameter(PARAM_SHARED_WITH_ALL_TENANTS); boolean isSharedWithAllTenants = Boolean.parseBoolean(sharingValueParam); + if (isSharedWithAllTenants && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { + isSharedWithAllTenants = false; + } apiConfig.setSharedWithAllTenants(isSharedWithAllTenants); Set uriTemplates = new LinkedHashSet<>(); diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java index 436580978c..f9a28ee41d 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java @@ -32,6 +32,8 @@ import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration; import org.wso2.carbon.apimgt.webapp.publisher.config.WebappPublisherConfig; import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder; import org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util.AnnotationProcessor; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.user.api.UserStoreException; import javax.servlet.ServletContext; import java.io.IOException; @@ -106,6 +108,9 @@ public class APIPublisherLifecycleListener implements LifecycleListener { log.error("Error encountered while discovering annotated classes", e); } catch (ClassNotFoundException e) { log.error("Error while scanning class for annotations", e); + } catch (UserStoreException e) { + log.error("Error while retrieving tenant admin user for the tenant domain" + + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(), e); } } } diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authorizer/WebappTenantAuthorizer.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authorizer/WebappTenantAuthorizer.java index e6a55eba89..26d8ff995d 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authorizer/WebappTenantAuthorizer.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authorizer/WebappTenantAuthorizer.java @@ -43,7 +43,11 @@ public class WebappTenantAuthorizer { } private static boolean isProviderTenant(Request request, String requestTenantDomain) { - String param = request.getContext().findParameter(PROVIDER_TENANT_DOMAIN_PARAM_NAME); + Object tenantDoamin = request.getServletContext().getAttribute(PROVIDER_TENANT_DOMAIN_PARAM_NAME); + String param = null; + if (tenantDoamin != null) { + param = (String)request.getServletContext().getAttribute(PROVIDER_TENANT_DOMAIN_PARAM_NAME); + } return (param == null || requestTenantDomain.equals(param)); } }