use of com.manydesigns.portofino.security.AccessLevel in project Portofino by ManyDesigns.
the class GroupPermission method hasPermissions.
public static boolean hasPermissions(Permissions configuration, Collection<String> groups, AccessLevel level, String... permissions) {
boolean hasLevel = level == null;
boolean hasPermissions = true;
Map<String, Boolean> permMap = new HashMap<String, Boolean>(permissions.length);
for (String groupId : groups) {
AccessLevel actualLevel = configuration.getActualLevels().get(groupId);
if (actualLevel == AccessLevel.DENY) {
return false;
} else if (!hasLevel && actualLevel != null && actualLevel.isGreaterThanOrEqual(level)) {
hasLevel = true;
}
Set<String> perms = configuration.getActualPermissions().get(groupId);
if (perms != null) {
for (String permission : permissions) {
if (perms.contains(permission)) {
permMap.put(permission, true);
}
}
}
}
for (String permission : permissions) {
hasPermissions &= permMap.containsKey(permission);
}
hasPermissions = hasLevel && hasPermissions;
if (!hasPermissions) {
logger.debug("User does not have permissions. User's groups: {}", groups);
}
return hasPermissions;
}
Aggregations