/** * Check if the role is a root role * * @param roleName */ public boolean isRoot(String roleName) { checkRole(roleName); return parentMappings.get(roleName) == null; }
/** * return the parent role name, null if role has no parent * * @param roleName */ public String getParent(String roleName) { checkRole(roleName); String parentRole = parentMappings.get(roleName); if (roleName.equals(parentRole)) cycleDetected(roleName, null); return parentRole; }
/** * Calculate an ordered list of ancestors, starting with the parent * * @param roleName */ public List<String> getAncestors(String roleName) { checkRole(roleName); List<String> ancestors = new ArrayList<String>(); fillAncestors(parentMappings.get(roleName), ancestors); return ancestors; }
/** * Return child roles * * @param roleName */ public List<String> getChildren(String roleName) { checkRole(roleName); List<String> children = new ArrayList<String>(); for (Entry<String, String> entry : parentMappings.entrySet()) { if (entry.getValue() != null && entry.getValue().equals(roleName)) { if (roleName.equals(entry.getKey())) cycleDetected(roleName, null); children.add(entry.getKey()); } } return children; }
/** * Get all descendant roles, the order is randomly * * @param roleName */ public List<String> getDescendants(String roleName) { checkRole(roleName); Set<String> descendants = new HashSet<String>(); fillDescendents(getChildren(roleName), descendants); List<String> result = new ArrayList<String>(); result.addAll(descendants); return result; }