Search in sources :

Example 1 with UserDetailsServiceLdapAuthoritiesPopulator

use of org.springframework.security.ldap.authentication.UserDetailsServiceLdapAuthoritiesPopulator in project spring-security by spring-projects.

the class UserDetailsServiceLdapAuthoritiesPopulatorTests method delegationToUserDetailsServiceReturnsCorrectRoles.

@Test
public void delegationToUserDetailsServiceReturnsCorrectRoles() throws Exception {
    UserDetailsService uds = mock(UserDetailsService.class);
    UserDetails user = mock(UserDetails.class);
    when(uds.loadUserByUsername("joe")).thenReturn(user);
    List authorities = AuthorityUtils.createAuthorityList("ROLE_USER");
    when(user.getAuthorities()).thenReturn(authorities);
    UserDetailsServiceLdapAuthoritiesPopulator populator = new UserDetailsServiceLdapAuthoritiesPopulator(uds);
    Collection<? extends GrantedAuthority> auths = populator.getGrantedAuthorities(new DirContextAdapter(), "joe");
    assertThat(auths).hasSize(1);
    assertThat(AuthorityUtils.authorityListToSet(auths).contains("ROLE_USER")).isTrue();
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) UserDetailsServiceLdapAuthoritiesPopulator(org.springframework.security.ldap.authentication.UserDetailsServiceLdapAuthoritiesPopulator) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) List(java.util.List) Test(org.junit.Test)

Aggregations

List (java.util.List)1 Test (org.junit.Test)1 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)1 UserDetailsServiceLdapAuthoritiesPopulator (org.springframework.security.ldap.authentication.UserDetailsServiceLdapAuthoritiesPopulator)1