NestedLdapAuthoritiesPopulator extends DefaultLdapAuthoritiesPopulator implements InitializingBean { protected Set getParentRoles( final Set children ) { Set parents = new HashSet(); Iterator iter = children.iterator(); while ( iter.hasNext() ) { Object parent = extraRolesMapping.get( iter.next() ); if ( null != parent ) { parents.add( parent ); } } return parents; } 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 testGetParentRoles() throws Exception { Map<String, String> rolesMap = new HashMap<>(); rolesMap.put( "child", "parentA" ); rolesMap.put( "grandchild", "child" ); authoritiesPopulator.setExtraRolesMapping( rolesMap ); assertEquals( rolesMap, authoritiesPopulator.getExtraRolesMapping() ); Set<String> children = new HashSet<>(); children.add( "child" ); Set parentRoles = authoritiesPopulator.getParentRoles( children ); assertNotNull( parentRoles ); assertEquals( 1, parentRoles.size() ); assertTrue( parentRoles.contains( "parentA" ) ); }