@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { GeoServerUser user = null; try { user = getUserByUsername(username); if (user == null) throw new UsernameNotFoundException(userNotFoundMessage(username)); RoleCalculator calculator = new RoleCalculator(this, getSecurityManager().getActiveRoleService()); user.setAuthorities(calculator.calculateRoles(user)); } catch (IOException e) { throw new UsernameNotFoundException(userNotFoundMessage(username), e); } return user; }
set1.addAll(getRoleService().getRolesForUser(user.getUsername())); addInheritedRoles(set1); if (getUserGroupService() != null) { for (GeoServerUserGroup group : getUserGroupService().getGroupsForUser(user)) { if (group.isEnabled()) set1.addAll(calculateRoles(group)); SortedSet<GeoServerRole> set2 = personalizeRoles(user, set1); addMappedSystemRoles(set2);
/** * 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; }
@Override protected List<GeoServerRole> load() { List<GeoServerRole> tmp = new ArrayList<GeoServerRole>(); List<GeoServerRole> result = new ArrayList<GeoServerRole>(); try { GeoServerUserGroupService ugService = getSecurityManager() .loadUserGroupService(ugServiceName); GeoServerRoleService gaService = getSecurityManager() .getActiveRoleService(); RoleCalculator calc = new RoleCalculator(ugService, gaService); tmp.addAll(rolePalette.getSelectedRoles()); calc.addInheritedRoles(tmp); for (GeoServerUserGroup group : userGroupPalette.getSelectedGroups()) { if (group.isEnabled()) { tmp.addAll(calc.calculateRoles(group)); } } result.addAll(calc.personalizeRoles(user, tmp)); } catch (IOException e) { throw new RuntimeException(e); } Collections.sort(result); return result; } }
/** * Implements roles retrieval from the J2EE container. * * @param request * @param principal * @throws IOException */ protected Collection<GeoServerRole> getRolesFromJ2EE( HttpServletRequest request, String principal) throws IOException { Collection<GeoServerRole> roles = new ArrayList<GeoServerRole>(); boolean useActiveService = getRoleServiceName() == null || getRoleServiceName().trim().length() == 0; GeoServerRoleService service = useActiveService ? getSecurityManager().getActiveRoleService() : getSecurityManager().loadRoleService(getRoleServiceName()); for (GeoServerRole role : service.getRoles()) if (request.isUserInRole(role.getAuthority())) roles.add(role); RoleCalculator calc = new RoleCalculator(service); calc.addInheritedRoles(roles); calc.addMappedSystemRoles(roles); return roles; } }
/** * Convenience method for {@link #calculateRoles(GeoServerUser)} * * @param username * @throws IOException */ public SortedSet<GeoServerRole> calculateRoles(String username) throws IOException { return calculateRoles(new GeoServerUser(username)); }
@Override protected List<GeoServerRole> load() { List<GeoServerRole> tmp = new ArrayList<GeoServerRole>(); List<GeoServerRole> result = new ArrayList<GeoServerRole>(); try { GeoServerUserGroupService ugService = getSecurityManager().loadUserGroupService(ugServiceName); GeoServerRoleService gaService = getSecurityManager().getActiveRoleService(); RoleCalculator calc = new RoleCalculator(ugService, gaService); tmp.addAll(rolePalette.getSelectedRoles()); calc.addInheritedRoles(tmp); for (GeoServerUserGroup group : userGroupPalette.getSelectedGroups()) { if (group.isEnabled()) { tmp.addAll(calc.calculateRoles(group)); } } result.addAll(calc.personalizeRoles(user, tmp)); } catch (IOException e) { throw new RuntimeException(e); } Collections.sort(result); return result; } }
/** * Calculates roles from a {@link GeoServerRoleService} The default service is {@link * GeoServerSecurityManager#getActiveRoleService()} * * <p>The result contains all inherited roles, but no personalized roles * * @param request * @param principal * @throws IOException */ protected Collection<GeoServerRole> getRolesFromRoleService( HttpServletRequest request, String principal) throws IOException { boolean useActiveService = getRoleServiceName() == null || getRoleServiceName().trim().length() == 0; GeoServerRoleService service = useActiveService ? getSecurityManager().getActiveRoleService() : getSecurityManager().loadRoleService(getRoleServiceName()); RoleCalculator calc = new RoleCalculator(service); return calc.calculateRoles(principal); }
@Override protected List<GeoServerRole> load() { List<GeoServerRole> tmp = new ArrayList<GeoServerRole>(); List<GeoServerRole> result = new ArrayList<GeoServerRole>(); try { GeoServerUserGroupService ugService = getSecurityManager() .loadUserGroupService(ugServiceName); GeoServerRoleService gaService = getSecurityManager() .getActiveRoleService(); RoleCalculator calc = new RoleCalculator(ugService, gaService); tmp.addAll(rolePalette.getSelectedRoles()); calc.addInheritedRoles(tmp); for (GeoServerUserGroup group : userGroupPalette.getSelectedGroups()) { if (group.isEnabled()) { tmp.addAll(calc.calculateRoles(group)); } } result.addAll(calc.personalizeRoles(user, tmp)); } catch (IOException e) { throw new RuntimeException(e); } Collections.sort(result); return result; } }
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { GeoServerUser user=null; try { user = getUserByUsername(username); if (user==null) throw new UsernameNotFoundException(userNotFoundMessage(username)); RoleCalculator calculator = new RoleCalculator(this, getSecurityManager().getActiveRoleService()); user.setAuthorities(calculator.calculateRoles(user)); } catch (IOException e) { throw new UsernameNotFoundException(userNotFoundMessage(username),e); } return user; }
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { GeoServerUser user = null; try { user = getUserByUsername(username); if (user == null) { throw new UsernameNotFoundException(userNotFoundMessage(username)); } RoleCalculator calculator = new RoleCalculator(this, getSecurityManager().getActiveRoleService()); user.setAuthorities(calculator.calculateRoles(user)); } catch (IOException e) { throw new UsernameNotFoundException(userNotFoundMessage(username), e); } return user; }
new RoleCalculator(getSecurityManager().getActiveRoleService()); if (calc != null) { try { roles.addAll(calc.calculateRoles(principal)); } catch (IOException e) { LOGGER.log(
RoleCalculator calc = new RoleCalculator(getSecurityManager().getActiveRoleService()); try { roles.addAll(calc.calculateRoles(new GeoServerUser(auth.getName()))); } catch (IOException e) { throw new AuthenticationServiceException(e.getLocalizedMessage(), e);
if (getDefaultSecurityService() instanceof GeoServerRoleService) { calc = new RoleCalculator( userGroupService, (GeoServerRoleService) getDefaultSecurityService()); userGroupService.getGroupsForUser(user)) { if (group.isEnabled()) { for (GeoServerRole role : calc.calculateRoles(group)) { stringSet.add(role.getAuthority()); new RoleCalculator( userGroupService, securityManager.getActiveRoleService()); if (calc != null) { userGroupService.getGroupsForUser(user)) { if (group.isEnabled()) { for (GeoServerRole role : calc.calculateRoles(group)) { stringSet.add(role.getAuthority());
roles.addAll(details.getAuthorities()); } else { RoleCalculator calc = new RoleCalculator(getSecurityManager().getActiveRoleService()); try { roles.addAll(calc.calculateRoles(new GeoServerUser(user))); } catch (IOException e) { throw new AuthenticationServiceException(e.getLocalizedMessage(),e);
ugService.initializeFromConfig(ugconfig); RoleCalculator calc = new RoleCalculator(ugService, service); SortedSet<GeoServerRole> roles; roles = calc.calculateRoles(ugService.createUserObject("user1", "abc", true)); assertTrue(roles.size() == 4); assertTrue(roles.contains(adminRole)); assertTrue(roles.contains(GeoServerRole.GROUP_ADMIN_ROLE)); roles = calc.calculateRoles(ugService.createUserObject("user2", "abc", true)); assertTrue(roles.size() == 2); assertTrue(roles.contains(adminRole)); assertTrue(roles.contains(GeoServerRole.ADMIN_ROLE)); roles = calc.calculateRoles(ugService.createUserObject("user3", "abc", true)); assertTrue(roles.size() == 1); assertTrue(roles.contains(role1));