Fix issue of initializeRegistry() in IdentityTenantUtil is called for every SSO request
@@ -45,6 +45,7 @@ import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import java.util.concurrent.ConcurrentHashMap;
public class IdentityTenantUtil {
@@ -53,6 +54,7 @@ public class IdentityTenantUtil {
private static Log log = LogFactory.getLog(IdentityTenantUtil.class);
private static TenantRegistryLoader tenantRegistryLoader;
private static BundleContext bundleContext;
+ protected static ConcurrentHashMap<Integer,Boolean> tenantIdMap = new ConcurrentHashMap<Integer,Boolean>();
public static TenantRegistryLoader getTenantRegistryLoader() {
return tenantRegistryLoader;
@@ -199,6 +201,8 @@ public class IdentityTenantUtil {
public static void initializeRegistry(int tenantId, String tenantDomain) throws IdentityException {
+ if (tenantIdMap.get(tenantId) == null || !tenantIdMap.get(tenantId)) {
+
if (tenantId != MultitenantConstants.SUPER_TENANT_ID) {
try {
PrivilegedCarbonContext.startTenantFlow();
@@ -222,6 +226,7 @@ public class IdentityTenantUtil {
}
try {
registryService.getGovernanceSystemRegistry(tenantId);
+ tenantIdMap.put(tenantId, true);
} catch (RegistryException e) {
throw IdentityException.error("Error obtaining governance system registry for tenant domain " +
tenantDomain, e);
@@ -232,6 +237,7 @@ public class IdentityTenantUtil {
}
}
}
+ }
public static int getTenantId(String tenantDomain) throws IdentityRuntimeException {
