Search in sources :

Example 1 with GrantedAuthoritiesContainer

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();
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) GrantedAuthoritiesContainer(org.springframework.security.core.authority.GrantedAuthoritiesContainer) GrantedAuthority(org.springframework.security.core.GrantedAuthority)

Aggregations

GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 GrantedAuthoritiesContainer (org.springframework.security.core.authority.GrantedAuthoritiesContainer)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1