Пример #1
0
 public static String getTenantDomainFromId(int tid) {
   try {
     return DataServicesDSComponent.getRealmService()
         .getTenantManager()
         .getTenant(tid)
         .getDomain();
   } catch (UserStoreException e) {
     throw new RuntimeException(e);
   }
 }
Пример #2
0
 /**
  * Retrieves the current user's roles given the username.
  *
  * @param username The username
  * @return The user roles
  * @throws DataServiceFault
  */
 public static String[] getUserRoles(String username) throws DataServiceFault {
   RealmService realmService = DataServicesDSComponent.getRealmService();
   RegistryService registryService = DataServicesDSComponent.getRegistryService();
   username = MultitenantUtils.getTenantAwareUsername(username);
   String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
   int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
   username = MultitenantUtils.getTenantAwareUsername(username);
   try {
     if (tenantId < MultitenantConstants.SUPER_TENANT_ID) {
       tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
     }
     if (tenantId < MultitenantConstants.SUPER_TENANT_ID) {
       /* 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 = registryService.getUserRealm(tenantId);
     String roles[] = realm.getUserStoreManager().getRoleListOfUser(username);
     return roles;
   } catch (Exception e) {
     String msg =
         "Error in retrieving the realm for the tenant id: "
             + tenantId
             + ", username: "******". "
             + e.getMessage();
     log.error(msg);
     throw new DataServiceFault(msg);
   }
 }