Search in sources :

Example 1 with AbstractUserStoreManager

use of org.wso2.carbon.user.core.common.AbstractUserStoreManager in project carbon-apimgt by wso2.

the class APIUtil method checkIfUserInRole.

/**
 * Check whether the user has the given role
 *
 * @param username Logged-in username
 * @param roleName role that needs to be checked
 * @throws UserStoreException
 */
public static boolean checkIfUserInRole(String username, String roleName) throws UserStoreException {
    String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(username));
    String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(username);
    int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
    RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
    UserRealm realm = (UserRealm) realmService.getTenantUserRealm(tenantId);
    org.wso2.carbon.user.core.UserStoreManager manager = realm.getUserStoreManager();
    AbstractUserStoreManager abstractManager = (AbstractUserStoreManager) manager;
    return abstractManager.isUserInRole(tenantAwareUserName, roleName);
}
Also used : UserRealm(org.wso2.carbon.user.core.UserRealm) RealmService(org.wso2.carbon.user.core.service.RealmService) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)

Example 2 with AbstractUserStoreManager

use of org.wso2.carbon.user.core.common.AbstractUserStoreManager in project carbon-apimgt by wso2.

the class APIUtil method isUserInRole.

/**
 * Check whether the user has the given role
 *
 * @throws UserStoreException
 * @throws APIManagementException
 */
public static boolean isUserInRole(String user, String role) throws UserStoreException, APIManagementException {
    String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(user));
    UserRegistrationConfigDTO signupConfig = SelfSignUpUtil.getSignupConfiguration(tenantDomain);
    user = SelfSignUpUtil.getDomainSpecificUserName(user, signupConfig);
    String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(user);
    RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
    int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
    UserRealm realm = (UserRealm) realmService.getTenantUserRealm(tenantId);
    org.wso2.carbon.user.core.UserStoreManager manager = realm.getUserStoreManager();
    AbstractUserStoreManager abstractManager = (AbstractUserStoreManager) manager;
    return abstractManager.isUserInRole(tenantAwareUserName, role);
}
Also used : UserRealm(org.wso2.carbon.user.core.UserRealm) UserRegistrationConfigDTO(org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO) RealmService(org.wso2.carbon.user.core.service.RealmService) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)

Aggregations

Endpoint (org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)2 UserRealm (org.wso2.carbon.user.core.UserRealm)2 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)2 RealmService (org.wso2.carbon.user.core.service.RealmService)2 UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)1