Search in sources :

Example 1 with BasicHierarchyPermission

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;
    }
}
Also used : PermissionCollection(java.security.PermissionCollection) AllPermission(java.security.AllPermission) BasicHierarchyPermission(org.eclipse.scout.rt.shared.security.BasicHierarchyPermission) Permission(java.security.Permission) BasicHierarchyPermission(org.eclipse.scout.rt.shared.security.BasicHierarchyPermission) AllPermission(java.security.AllPermission)

Aggregations

AllPermission (java.security.AllPermission)1 Permission (java.security.Permission)1 PermissionCollection (java.security.PermissionCollection)1 BasicHierarchyPermission (org.eclipse.scout.rt.shared.security.BasicHierarchyPermission)1