use of org.wso2.carbon.user.api.RealmConfiguration in project core-util by WSO2Telco.
the class UserRoleProsser method getRolesByUserName.
public List<String> getRolesByUserName(String userName) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class, null);
List<String> currentUserRoleList = null;
try {
RealmConfiguration realmConfiguration = new RealmConfiguration();
String[] currentUserRoles = realmService.getUserRealm(realmConfiguration).getUserStoreManager().getRoleListOfUser(userName);
currentUserRoleList = Arrays.asList(currentUserRoles);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
log.error("unable to retrieve user roles for user " + userName + " : ", e);
}
if (currentUserRoleList != null && !currentUserRoleList.isEmpty()) {
return currentUserRoleList;
} else {
return Collections.emptyList();
}
}
use of org.wso2.carbon.user.api.RealmConfiguration in project core-util by WSO2Telco.
the class UserAuthorizationValidator method isAuthorizedRole.
public boolean isAuthorizedRole(String userName, Set<String> allowedRolesSet) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class, null);
try {
RealmConfiguration realmConfiguration = new RealmConfiguration();
String[] currentUserRoles = realmService.getUserRealm(realmConfiguration).getUserStoreManager().getRoleListOfUser(userName);
List<String> currentUserRolesList = Arrays.asList(currentUserRoles);
Iterator<String> iterator = allowedRolesSet.iterator();
while (iterator.hasNext()) {
String allowedRole = iterator.next();
if (currentUserRolesList.contains(allowedRole)) {
return true;
}
}
} catch (org.wso2.carbon.user.api.UserStoreException e) {
log.error("authorization failed for user : " + userName, e);
return false;
}
log.error("authorization failed for user : " + userName);
return false;
}
Aggregations