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();
}
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();
}
Aggregations