use of org.wso2.carbon.user.core.config.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;
}
use of org.wso2.carbon.user.core.config.RealmConfiguration in project carbon-apimgt by wso2.
the class AbstractJWTGenerator method getMultiAttributeSeparator.
protected String getMultiAttributeSeparator(int tenantId) {
try {
RealmConfiguration realmConfiguration = null;
RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
if (realmService != null && tenantId != MultitenantConstants.INVALID_TENANT_ID) {
UserStoreManager userStoreManager = (UserStoreManager) realmService.getTenantUserRealm(tenantId).getUserStoreManager();
realmConfiguration = userStoreManager.getRealmConfiguration();
}
if (realmConfiguration != null) {
String claimSeparator = realmConfiguration.getUserStoreProperty(APIConstants.MULTI_ATTRIBUTE_SEPARATOR);
if (claimSeparator != null && !claimSeparator.trim().isEmpty()) {
return claimSeparator;
}
}
} catch (UserStoreException e) {
log.error("Error occurred while getting the realm configuration, User store properties might not be " + "returned", e);
}
return null;
}
Aggregations