Search in sources :

Example 51 with UserStoreManager

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];
    }
}
Also used : UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)

Example 52 with UserStoreManager

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);
    }
}
Also used : ClaimManager(org.wso2.carbon.user.api.ClaimManager) ClaimMapping(org.wso2.carbon.user.api.ClaimMapping) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) TreeMap(java.util.TreeMap)

Example 53 with UserStoreManager

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);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)

Example 54 with UserStoreManager

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;
    }
}
Also used : UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) RegistryService(org.wso2.carbon.registry.core.service.RegistryService)

Example 55 with UserStoreManager

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;
}
Also used : UserRealm(org.wso2.carbon.user.core.UserRealm) UserStoreException(org.wso2.carbon.user.core.UserStoreException) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Aggregations

UserStoreException (org.wso2.carbon.user.api.UserStoreException)30 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)29 RealmService (org.wso2.carbon.user.core.service.RealmService)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 Test (org.junit.Test)17 UserRealm (org.wso2.carbon.user.core.UserRealm)16 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)16 UserRealm (org.wso2.carbon.user.api.UserRealm)13 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)12 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)11 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)10 HashMap (java.util.HashMap)7 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)7 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)6 AuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException)5 Property (org.wso2.carbon.identity.application.common.model.Property)5 Assertion (org.opensaml.saml.saml2.core.Assertion)3 Response (org.opensaml.saml.saml2.core.Response)3 Subject (org.opensaml.saml.saml2.core.Subject)3 Test (org.testng.annotations.Test)3