AbstractAuthenticationToken.getName() uses UserDetails.getUsername()

Fixes gh-4877
This commit is contained in:
Joe Grandja 2017-11-30 09:17:42 -05:00
parent ab6df7d154
commit 50d1a81458
1 changed files with 6 additions and 3 deletions

View File

@ -26,6 +26,7 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.CredentialsContainer;
import org.springframework.security.core.AuthenticatedPrincipal;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
/**
* Base class for <code>Authentication</code> objects.
@ -79,12 +80,14 @@ public abstract class AbstractAuthenticationToken implements Authentication,
}
public String getName() {
if (this.getPrincipal() instanceof UserDetails) {
return ((UserDetails) this.getPrincipal()).getUsername();
}
if (this.getPrincipal() instanceof AuthenticatedPrincipal) {
return ((AuthenticatedPrincipal) this.getPrincipal()).getName();
}
if (getPrincipal() instanceof Principal) {
return ((Principal) getPrincipal()).getName();
if (this.getPrincipal() instanceof Principal) {
return ((Principal) this.getPrincipal()).getName();
}
return (this.getPrincipal() == null) ? "" : this.getPrincipal().toString();