diff --git a/core/src/main/java/org/springframework/security/providers/preauth/PreAuthenticatedGrantedAuthoritiesUserDetailsService.java b/core/src/main/java/org/springframework/security/providers/preauth/PreAuthenticatedGrantedAuthoritiesUserDetailsService.java index ef07befde6..bcbe08116e 100755 --- a/core/src/main/java/org/springframework/security/providers/preauth/PreAuthenticatedGrantedAuthoritiesUserDetailsService.java +++ b/core/src/main/java/org/springframework/security/providers/preauth/PreAuthenticatedGrantedAuthoritiesUserDetailsService.java @@ -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 UserDetails 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); + } }