SEC-720: Design for extension: PreAuthenticatedGrantedAuthoritiesUserDetailsService
http://jira.springframework.org/browse/SEC-720. Added createUserDetails method to allow custom UserDetails object t be created.
This commit is contained in:
parent
f3a6f768ba
commit
8f379768a8
|
@ -34,12 +34,21 @@ public class PreAuthenticatedGrantedAuthoritiesUserDetailsService implements Aut
|
|||
* GrantedAuthoritiesContainer implementation as returned by
|
||||
* the token.getDetails() method.
|
||||
*/
|
||||
public UserDetails loadUserDetails(Authentication token) throws AuthenticationException {
|
||||
public final UserDetails loadUserDetails(Authentication token) throws AuthenticationException {
|
||||
Assert.notNull(token.getDetails());
|
||||
Assert.isInstanceOf(GrantedAuthoritiesContainer.class, token.getDetails());
|
||||
GrantedAuthority[] preAuthenticatedGrantedAuthorities = ((GrantedAuthoritiesContainer) token.getDetails())
|
||||
.getGrantedAuthorities();
|
||||
UserDetails ud = new User(token.getName(), "N/A", true, true, true, true, preAuthenticatedGrantedAuthorities);
|
||||
GrantedAuthority[] authorities = ((GrantedAuthoritiesContainer) token.getDetails()).getGrantedAuthorities();
|
||||
UserDetails ud = createuserDetails(token, authorities);
|
||||
return ud;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the final <tt>UserDetails</tt> object. Can be overridden to customize the contents.
|
||||
*
|
||||
* @param token the authentication request token
|
||||
* @param authorities the pre-authenticated authorities.
|
||||
*/
|
||||
protected UserDetails createuserDetails(Authentication token, GrantedAuthority[] authorities) {
|
||||
return new User(token.getName(), "N/A", true, true, true, true, authorities);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue