/** * returns true if parentName is a valid parent for roleName (avoiding cycles) * * @param roleName * @param parentName */ public boolean isValidParent(String roleName, String parentName) { if (parentName == null || parentName.length() == 0) return true; if (roleName.equals(parentName)) return false; if (getDescendants(roleName).contains(parentName)) return false; return true; } }
List<String> computeAllowableParentRoles(GeoServerRole role) throws IOException { Map<String, String> parentMappings = getRoleService(roleServiceName).getParentMappings(); if (role != null && StringUtils.hasLength(role.getAuthority())) { // filter out roles already used as parents RoleHierarchyHelper helper = new RoleHierarchyHelper(parentMappings); Set<String> parents = new HashSet<String>(parentMappings.keySet()); parents.removeAll(helper.getDescendants(role.getAuthority())); parents.remove(role.getAuthority()); return new ArrayList(parents); } else { // no rolename given, we are creating a new one return new ArrayList(parentMappings.keySet()); } }
List<String> computeAllowableParentRoles(GeoServerRole role) throws IOException { Map<String, String> parentMappings = getRoleService(roleServiceName).getParentMappings(); if (role != null && StringUtils.hasLength(role.getAuthority())) { //filter out roles already used as parents RoleHierarchyHelper helper = new RoleHierarchyHelper(parentMappings); Set<String> parents = new HashSet<String>(parentMappings.keySet()); parents.removeAll(helper.getDescendants(role.getAuthority())); parents.remove(role.getAuthority()); return new ArrayList(parents); } else { // no rolename given, we are creating a new one return new ArrayList(parentMappings.keySet()); } }
List<String> computeAllowableParentRoles(GeoServerRole role) throws IOException { Map<String, String> parentMappings = getRoleService(roleServiceName).getParentMappings(); if (!role.getAuthority().equals(GeoServerRole.NULL_ROLE.getAuthority()) ) { //filter out roles already used as parents RoleHierarchyHelper helper = new RoleHierarchyHelper(parentMappings); Set<String> parents = new HashSet<String>(parentMappings.keySet()); parents.removeAll(helper.getDescendants(role.getAuthority())); parents.remove(role.getAuthority()); return new ArrayList(parents); } else { // no rolename given, we are creating a new one return new ArrayList(parentMappings.keySet()); } }
assertTrue(helper.getChildren("node11").contains("node112")); assertEquals(4, helper.getDescendants("node1").size()); assertTrue(helper.getDescendants("node1").contains("node11")); assertTrue(helper.getDescendants("node1").contains("node12")); assertTrue(helper.getDescendants("node1").contains("node111")); assertTrue(helper.getDescendants("node1").contains("node112")); assertEquals(0, helper.getDescendants("node12").size()); assertEquals(2, helper.getDescendants("node11").size()); assertTrue(helper.getDescendants("node11").contains("node111")); assertTrue(helper.getDescendants("node11").contains("node112"));
helper.getDescendants("node1"); } catch (RuntimeException e) { fail = false;
helper.getDescendants("node1"); } catch (RuntimeException e) { fail = false;