* @throws RegistryException if the operation failed.
*/
public static UserRegistry getRegistry(HttpServletRequest request) throws RegistryException {
String username = null;
String password = null;
UserRegistry registry =
(UserRegistry) request.getSession().getAttribute(
RegistryConstants.ROOT_REGISTRY_INSTANCE);
String tenantDomain = (String) request.getAttribute(MultitenantConstants.TENANT_DOMAIN);
int calledTenantId = 0;
if (tenantDomain != null) {
try {
if (RegistryContext.getBaseInstance().getRealmService() == null) {
String msg = "Error in getting the tenant manager. " +
"The realm service is not available.";
log.error(msg);
throw new RegistryException(msg);
}
calledTenantId = RegistryContext.getBaseInstance().getRealmService().
getTenantManager().getTenantId(tenantDomain);
if (!RegistryContext.getBaseInstance().getRealmService().getTenantManager()
.isTenantActive(calledTenantId)) {
// the tenant is not active.
String msg = "The tenant is not active. Domain: " + tenantDomain + ".";
log.error(msg);
throw new RegistryException(msg);
}
} catch (org.wso2.carbon.user.api.UserStoreException e) {
String msg = "Error in converting tenant domain to the id for tenant domain: "
+ tenantDomain + ".";
log.error(msg);
throw new RegistryException(msg);
}
}
boolean registryInvalidated = false;
if (registry != null && registry.getTenantId() != calledTenantId) {
// invalidate the registry.
registry = null;
registryInvalidated = true;
}
if (registry == null) {