Search in sources :

Example 1 with MockUserSearch

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

the class LdapUserDetailsServiceTests method nullPopulatorConstructorReturnsEmptyAuthoritiesList.

@Test
public void nullPopulatorConstructorReturnsEmptyAuthoritiesList() throws Exception {
    DirContextAdapter userData = new DirContextAdapter(new DistinguishedName("uid=joe"));
    LdapUserDetailsService service = new LdapUserDetailsService(new MockUserSearch(userData));
    UserDetails user = service.loadUserByUsername("doesntmatterwegetjoeanyway");
    assertThat(user.getAuthorities()).isEmpty();
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) DistinguishedName(org.springframework.ldap.core.DistinguishedName) MockUserSearch(org.springframework.security.ldap.authentication.MockUserSearch) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter) Test(org.junit.Test)

Example 2 with MockUserSearch

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

the class LdapUserDetailsServiceTests method correctAuthoritiesAreReturned.

@Test
public void correctAuthoritiesAreReturned() {
    DirContextAdapter userData = new DirContextAdapter(new DistinguishedName("uid=joe"));
    LdapUserDetailsService service = new LdapUserDetailsService(new MockUserSearch(userData), new MockAuthoritiesPopulator());
    service.setUserDetailsMapper(new LdapUserDetailsMapper());
    UserDetails user = service.loadUserByUsername("doesntmatterwegetjoeanyway");
    Set<String> authorities = AuthorityUtils.authorityListToSet(user.getAuthorities());
    assertThat(authorities).hasSize(1);
    assertThat(authorities.contains("ROLE_FROM_POPULATOR")).isTrue();
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) DistinguishedName(org.springframework.ldap.core.DistinguishedName) MockUserSearch(org.springframework.security.ldap.authentication.MockUserSearch) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)2 DistinguishedName (org.springframework.ldap.core.DistinguishedName)2 UserDetails (org.springframework.security.core.userdetails.UserDetails)2 MockUserSearch (org.springframework.security.ldap.authentication.MockUserSearch)2