HttpSession httpSession = request.getSession(false);
String userName = DBUtils.getUsername(msgContext);
RealmService realmService = DataServicesDSComponent.getRealmService();
RegistryService registryService = DataServicesDSComponent.getRegistryService();
/* if session does not exist, return empty array of roles */
if (httpSession == null) {
return new String[0];
}
/* first return the tenant id from the tenant domain */
SuperTenantCarbonContext carbonContext = SuperTenantCarbonContext.getCurrentContext(httpSession);
String tenantDomain = carbonContext.getTenantDomain();
int tenantId = carbonContext.getTenantId();
if (tenantId < 0) {
tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
}
if (tenantId < 0) {
/* the tenant doesn't exist. */
log.error("The tenant doesn't exist. Tenant domain:" + tenantDomain);
throw new DataServiceFault("Access Denied. You are not authorized.");
}
if (!realmService.getTenantManager().isTenantActive(tenantId)) {
/* the tenant is not active. */
log.error("The tenant is not active. Tenant domain:" + tenantDomain);
throw new DataServiceFault("The tenant is not active. Tenant domain:" + tenantDomain);
}
UserRealm realm;
String roles[];
try {
realm = registryService.getUserRealm(tenantId);
roles = realm.getUserStoreManager().getRoleListOfUser(userName);
} catch (Exception e) {
String msg = "Error in retrieving the realm for the tenant id: " + tenantId
+ ", username: " + userName + ". " + e.getMessage();
log.error(msg);