NestedLdapAuthoritiesPopulator extends DefaultLdapAuthoritiesPopulator implements InitializingBean { public Set getGroupMembershipRoles( String userDn, String username ) { Set roles = super.getGroupMembershipRoles( userDn, username ); Set newRolesFromPreviousPass = new HashSet( roles ); Set allNewRoles = new HashSet(); while ( !newRolesFromPreviousPass.isEmpty() ) { newRolesFromPreviousPass = getParentRoles( newRolesFromPreviousPass ); allNewRoles.addAll( newRolesFromPreviousPass ); } roles.addAll( toGrantedAuthorities( allNewRoles ) ); return roles; } 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 testGetGroupMembershipRoles() throws Exception { NestedLdapAuthoritiesPopulator authPop = spy( authoritiesPopulator ); when( contextSource.getReadOnlyContext() ).thenReturn( dirContext ); NamingEnumeration<SearchResult> namingEnumeration = mock( NamingEnumeration.class ); when( dirContext.search( anyString(), anyString(), any( SearchControls.class ) ) ).thenReturn( namingEnumeration ); Set roles = authoritiesPopulator.getGroupMembershipRoles( "uid=suzy,ou=users,dc=pentaho,dc=org", "suzy" ); assertNotNull( roles ); assertEquals( 0, roles.size() ); }