private void fillUsersForRole(DirContext ctx, SortedSet<String> users, GeoServerRole role) { String roleStr = role.toString(); if (roleStr.startsWith("ROLE_")) { // remove standard role prefix roleStr = roleStr.substring(5); } DirContextOperations roleObj = LDAPUtils.getLdapTemplateInContext(ctx, template) .searchForSingleEntry( groupSearchBase, groupNameFilter, new String[] {roleStr}); if (roleObj != null) { Object[] usernames = roleObj.getObjectAttributes(groupMembershipAttribute); if (usernames != null) { for (Object username : usernames) { String user = username.toString(); Matcher m = userMembershipPattern.matcher(user); if (m.matches()) { user = m.group(1); } users.add(getUserNameFromMembership(user)); } } } }
private void checkAllRoles() throws IOException { createRoleService(false); SortedSet<GeoServerRole> roles = service.getRoles(); assertNotNull(roles); assertTrue(roles.size() > 0); GeoServerRole role = roles.first(); assertTrue(role.toString().startsWith("ROLE_")); assertEquals(role.toString().toUpperCase(), role.toString()); }
private void checkUserRoles(String username, boolean userFilter) throws IOException { createRoleService(userFilter); SortedSet<GeoServerRole> allRoles = service.getRoles(); SortedSet<GeoServerRole> roles = service.getRolesForUser(username); assertNotNull(roles); assertTrue(roles.size() > 0); assertTrue(roles.size() < allRoles.size()); GeoServerRole role = roles.first(); assertTrue(role.toString().startsWith("ROLE_")); assertEquals(role.toString().toUpperCase(), role.toString()); }