/** * Collects the ascendents for a {@link GeoServerRole} object * * @param role * @param inherited */ protected void addParentRole(GeoServerRole role, Collection<GeoServerRole> inherited) throws IOException { GeoServerRole parentRole = getRoleService().getParentRole(role); if (parentRole == null) return; // end of recursion if (inherited.contains(parentRole)) return; // end of recursion inherited.add(parentRole); // recursion addParentRole(parentRole, inherited); }
/** * Calculate the {@link GeoServerRole} objects for a group including inherited roles * * @param group * @throws IOException */ public SortedSet<GeoServerRole> calculateRoles(GeoServerUserGroup group) throws IOException { SortedSet<GeoServerRole> roles = new TreeSet<GeoServerRole>(); roles.addAll(getRoleService().getRolesForGroup(group.getGroupname())); addInheritedRoles(roles); return roles; }
/** * Takes the role set for a user and personalizes the roles (matching user properties and role * parameters) * * @param user * @param roles * @throws IOException */ public SortedSet<GeoServerRole> personalizeRoles( GeoServerUser user, Collection<GeoServerRole> roles) throws IOException { SortedSet<GeoServerRole> set = new TreeSet<GeoServerRole>(); for (GeoServerRole role : roles) { Properties personalizedProps = getRoleService() .personalizeRoleParams( role.getAuthority(), role.getProperties(), user.getUsername(), user.getProperties()); if (personalizedProps == null) { set.add(role); } else { // create personalized role GeoServerRole pRole = getRoleService().createRoleObject(role.getAuthority()); pRole.setUserName(user.getUsername()); for (Object key : personalizedProps.keySet()) pRole.getProperties().put(key, personalizedProps.get(key)); set.add(pRole); } } return set; } }
set1.addAll(getRoleService().getRolesForUser(user.getUsername())); addInheritedRoles(set1);