use of org.springframework.security.core.authority.GrantedAuthoritiesContainer in project spring-security by spring-projects.
the class PreAuthenticatedGrantedAuthoritiesUserDetailsServiceTests method testGetUserDetails.
private void testGetUserDetails(final String userName, final List<GrantedAuthority> gas) {
PreAuthenticatedGrantedAuthoritiesUserDetailsService svc = new PreAuthenticatedGrantedAuthoritiesUserDetailsService();
PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(userName, "dummy");
token.setDetails(new GrantedAuthoritiesContainer() {
public Collection<? extends GrantedAuthority> getGrantedAuthorities() {
return gas;
}
});
UserDetails ud = svc.loadUserDetails(token);
assertThat(ud.isAccountNonExpired()).isTrue();
assertThat(ud.isAccountNonLocked()).isTrue();
assertThat(ud.isCredentialsNonExpired()).isTrue();
assertThat(ud.isEnabled()).isTrue();
assertThat(userName).isEqualTo(ud.getUsername());
// Password is not saved by
// PreAuthenticatedGrantedAuthoritiesUserDetailsService
// assertThat(password).isEqualTo(ud.getPassword());
assertThat(gas.containsAll(ud.getAuthorities()) && ud.getAuthorities().containsAll(gas)).withFailMessage("GrantedAuthority collections do not match; result: " + ud.getAuthorities() + ", expected: " + gas).isTrue();
}
Aggregations