From e70b7ea6cae27f2fb9a60ba3183558c70e596811 Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Tue, 10 Oct 2023 14:53:57 +0530 Subject: [PATCH] New method to get tenant when tenant qualified url enabled. --- .../core/util/IdentityTenantUtil.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityTenantUtil.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityTenantUtil.java index 14d3dbcf1f54..558aa5f61c27 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityTenantUtil.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityTenantUtil.java @@ -362,6 +362,26 @@ public static String getTenantDomainFromContext() { return (String) IdentityUtil.threadLocalProperties.get().get(IdentityCoreConstants.TENANT_NAME_FROM_CONTEXT); } + /** + * Get the tenant name from the thread local properties if available, otherwise get from the + * privileged carbon context. + * + * @return Tenant domain name. + */ + public static String resolveTenantDomain() { + + String tenantDomain = IdentityTenantUtil.getTenantDomainFromContext(); + if (StringUtils.isBlank(tenantDomain)) { + if (log.isDebugEnabled()) { + log.debug("The tenant domain is not set to the thread local. Hence using the tenant domain from the " + + "privileged carbon context."); + } + return PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + } + + return tenantDomain; + } + /** * Get the login tenant id. * First it gets the tenant domain from the thread local properties. If empty, retrieve it from thread local