public boolean removeRole(GeoServerRole role) throws IOException { if (helper.roleMap.containsKey(role.getAuthority()) == false) // nothing to do return false; for (SortedSet<GeoServerRole> set : helper.user_roleMap.values()) { set.remove(role); } for (SortedSet<GeoServerRole> set : helper.group_roleMap.values()) { set.remove(role); } // role hierarchy helper.role_parentMap.remove(role); Set<GeoServerRole> toBeRemoved = new HashSet<GeoServerRole>(); for (Entry<GeoServerRole, GeoServerRole> entry : helper.role_parentMap.entrySet()) { if (role.equals(entry.getValue())) toBeRemoved.add(entry.getKey()); } for (GeoServerRole ga : toBeRemoved) { helper.role_parentMap.put(ga, null); } // remove role helper.roleMap.remove(role.getAuthority()); setModified(true); return true; }
/** * Checks if the roles is mapped to a system role, see * * <p>{@link SecurityRoleServiceConfig#getAdminRoleName()} {@link * SecurityRoleServiceConfig#getGroupAdminRoleName()} * * @param role * @throws IOException */ public void checkRoleIsMapped(GeoServerRole role) throws IOException { GeoServerRole mappedRole = service.getAdminRole(); if (mappedRole != null && mappedRole.equals(role)) throw createSecurityException(ADMIN_ROLE_NOT_REMOVABLE_$1, role.getAuthority()); mappedRole = service.getGroupAdminRole(); if (mappedRole != null && mappedRole.equals(role)) throw createSecurityException(GROUP_ADMIN_ROLE_NOT_REMOVABLE_$1, role.getAuthority()); }
assertTrue(anonymousRole.isAnonymous()); assertFalse(role == anonymousRole); assertFalse(role.equals(anonymousRole)); assertTrue(theUser.getUsername().equals(role.getUserName())); assertNull(anonymousRole.getUserName());