NestedLdapAuthoritiesPopulator extends DefaultLdapAuthoritiesPopulator implements InitializingBean { protected Set toGrantedAuthorities( final Set rolesAsStringsSet ) { Set grantedAuthorities = new HashSet(); Iterator iter = rolesAsStringsSet.iterator(); while ( iter.hasNext() ) { String auth = (String) iter.next(); grantedAuthorities.add( new SimpleGrantedAuthority( auth ) ); } return grantedAuthorities; } NestedLdapAuthoritiesPopulator( final ContextSource contextSource, final String groupSearchBase ); Set getGroupMembershipRoles( String userDn, String username ); Map getExtraRolesMapping(); void setExtraRolesMapping( final Map extraRolesMapping ); void afterPropertiesSet();  }
@Test public void testToGrantedAuthorities() throws Exception { Set<String> roles = new HashSet<>(); roles.add( "authenticated" ); roles.add( "power user" ); Set authorities = authoritiesPopulator.toGrantedAuthorities( roles ); assertNotNull( authorities ); assertEquals( 2, authorities.size() ); for ( Object authority : authorities ) { assertTrue( authority instanceof GrantedAuthority ); GrantedAuthority ga = (GrantedAuthority) authority; assertTrue( "authenticated".equals( ga.getAuthority() ) || "power user".equals( ga.getAuthority() ) ); } }