use of org.wso2.carbon.user.api.UserStoreManager in project carbon-apimgt by wso2.
the class APIUtil method getRoleNames.
/**
* Retrieves the role list of system
*
* @throws APIManagementException If an error occurs
*/
public static String[] getRoleNames(String username) throws APIManagementException {
String tenantDomain = MultitenantUtils.getTenantDomain(username);
try {
if (!org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
UserStoreManager manager = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
return manager.getRoleNames();
} else {
return AuthorizationManager.getInstance().getRoleNames();
}
} catch (UserStoreException e) {
log.error("Error while getting all the roles", e);
return new String[0];
}
}
use of org.wso2.carbon.user.api.UserStoreManager in project carbon-apimgt by wso2.
the class APIUtil method getClaims.
/**
* Returns the user claims for the given user.
*
* @param endUserName name of the user whose claims needs to be returned
* @param tenantId tenant id of the user
* @param dialectURI claim dialect URI
* @return claims map
* @throws APIManagementException
*/
public static SortedMap<String, String> getClaims(String endUserName, int tenantId, String dialectURI) throws APIManagementException {
SortedMap<String, String> claimValues;
try {
ClaimManager claimManager = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getClaimManager();
ClaimMapping[] claims = claimManager.getAllClaimMappings(dialectURI);
String[] claimURIs = claimMappingtoClaimURIString(claims);
UserStoreManager userStoreManager = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(endUserName);
claimValues = new TreeMap(userStoreManager.getUserClaimValues(tenantAwareUserName, claimURIs, null));
return claimValues;
} catch (UserStoreException e) {
throw new APIManagementException("Error while retrieving user claim values from user store", e);
}
}
use of org.wso2.carbon.user.api.UserStoreManager in project carbon-apimgt by wso2.
the class APIUtil method getListOfRoles.
/**
* Retrieves the role list of a user
*
* @param username A username
* @param username A username
* @throws APIManagementException If an error occurs
*/
public static String[] getListOfRoles(String username) throws APIManagementException {
if (username == null) {
throw new APIManagementException("Attempt to execute privileged operation as" + " the anonymous user");
}
String[] roles = null;
roles = getValueFromCache(APIConstants.API_USER_ROLE_CACHE, username);
if (roles != null) {
return roles;
}
String tenantDomain = MultitenantUtils.getTenantDomain(username);
try {
if (!org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
UserStoreManager manager = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
roles = manager.getRoleListOfUser(MultitenantUtils.getTenantAwareUsername(username));
} else {
roles = AuthorizationManager.getInstance().getRolesOfUser(MultitenantUtils.getTenantAwareUsername(username));
}
addToRolesCache(APIConstants.API_USER_ROLE_CACHE, username, roles);
return roles;
} catch (UserStoreException e) {
throw new APIManagementException("UserStoreException while trying the role list of the user " + username, e);
}
}
use of org.wso2.carbon.user.api.UserStoreManager in project carbon-business-process by wso2.
the class BPSGroupManagerFactory method openSession.
@Override
public Session openSession() {
try {
RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
UserStoreManager userStoreManager = registryService.getUserRealm(tenantId).getUserStoreManager();
BPSGroupIdentityManager bpsGroupIdentityManager = new BPSGroupIdentityManager(userStoreManager);
return bpsGroupIdentityManager;
} catch (Exception e) {
String msg = "Failed to obtain a group identity manager.";
log.error(msg, e);
return null;
}
}
use of org.wso2.carbon.user.api.UserStoreManager in project carbon-business-process by wso2.
the class CommonTaskUtil method getAssignableUserNameList.
/**
* Returns the list of assignable user name list.
*
* @param task : The task object.
* @param excludeActualOwner : Whether to exclude the actual owner from the returned list.
* @return : the list of assignable user name list.
*/
public static List<String> getAssignableUserNameList(TaskDAO task, boolean excludeActualOwner) {
List<String> allPotentialOwners = new ArrayList<String>();
GenericHumanRoleDAO ghr = task.getGenericHumanRole(GenericHumanRole.GenericHumanRoleType.POTENTIAL_OWNERS);
RegistryService registryService = HumanTaskServiceComponent.getRegistryService();
for (OrganizationalEntityDAO orgEntity : ghr.getOrgEntities()) {
if (OrganizationalEntityDAO.OrganizationalEntityType.GROUP.equals(orgEntity.getOrgEntityType())) {
String roleName = orgEntity.getName();
UserRealm userRealm;
try {
userRealm = registryService.getUserRealm(task.getTenantId());
String[] assignableUsersArray = userRealm.getUserStoreManager().getUserListOfRole(roleName);
allPotentialOwners.addAll(Arrays.asList(assignableUsersArray));
} catch (RegistryException e) {
throw new HumanTaskRuntimeException("Cannot locate user realm for tenant id " + task.getTenantId());
} catch (UserStoreException e) {
throw new HumanTaskRuntimeException("Error retrieving the UserStoreManager " + task.getTenantId(), e);
}
} else if (OrganizationalEntityDAO.OrganizationalEntityType.USER.equals(orgEntity.getOrgEntityType())) {
allPotentialOwners.add(orgEntity.getName());
}
}
OrganizationalEntityDAO actualOwner = getActualOwner(task);
if (excludeActualOwner && actualOwner != null) {
allPotentialOwners.remove(actualOwner.getName());
}
return allPotentialOwners;
}
Aggregations