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);
}
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);
}
Aggregations