AbstractAuthenticationToken.getName() uses UserDetails.getUsername()
Fixes gh-4877
This commit is contained in:
parent
ab6df7d154
commit
50d1a81458
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue