use of org.eclipse.scout.rt.shared.security.BasicHierarchyPermission in project scout.rt by eclipse.
the class AbstractAccessControlService method getPermissionLevel.
@Override
public int getPermissionLevel(Permission p) {
if (p == null) {
return BasicHierarchyPermission.LEVEL_NONE;
}
if (!(p instanceof BasicHierarchyPermission)) {
if (checkPermission(p)) {
return BasicHierarchyPermission.LEVEL_ALL;
} else {
return BasicHierarchyPermission.LEVEL_NONE;
}
}
BasicHierarchyPermission hp = (BasicHierarchyPermission) p;
PermissionCollection c = getPermissions();
if (c == null) {
List<Integer> levels = hp.getValidLevels();
return levels.get(levels.size() - 1);
} else {
int maxLevel = BasicHierarchyPermission.LEVEL_UNDEFINED;
Enumeration<Permission> en = c.elements();
while (en.hasMoreElements()) {
Permission grantedPermission = en.nextElement();
// catch AllPermission
if (grantedPermission instanceof AllPermission) {
return BasicHierarchyPermission.LEVEL_ALL;
}
// process basic hierarchy permissions
if (grantedPermission instanceof BasicHierarchyPermission) {
BasicHierarchyPermission hgrantedPermission = (BasicHierarchyPermission) grantedPermission;
if (hgrantedPermission.getClass().isAssignableFrom(hp.getClass())) {
maxLevel = Math.max(maxLevel, hgrantedPermission.getLevel());
if (maxLevel >= BasicHierarchyPermission.LEVEL_ALL) {
break;
}
}
}
}
return maxLevel;
}
}
Aggregations