mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-31 09:12:14 +00:00
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.CredentialsContainer;
|
||||||
import org.springframework.security.core.AuthenticatedPrincipal;
|
import org.springframework.security.core.AuthenticatedPrincipal;
|
||||||
import org.springframework.security.core.authority.AuthorityUtils;
|
import org.springframework.security.core.authority.AuthorityUtils;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for <code>Authentication</code> objects.
|
* Base class for <code>Authentication</code> objects.
|
||||||
@ -79,12 +80,14 @@ public abstract class AbstractAuthenticationToken implements Authentication,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
if (this.getPrincipal() instanceof UserDetails) {
|
||||||
|
return ((UserDetails) this.getPrincipal()).getUsername();
|
||||||
|
}
|
||||||
if (this.getPrincipal() instanceof AuthenticatedPrincipal) {
|
if (this.getPrincipal() instanceof AuthenticatedPrincipal) {
|
||||||
return ((AuthenticatedPrincipal) this.getPrincipal()).getName();
|
return ((AuthenticatedPrincipal) this.getPrincipal()).getName();
|
||||||
}
|
}
|
||||||
|
if (this.getPrincipal() instanceof Principal) {
|
||||||
if (getPrincipal() instanceof Principal) {
|
return ((Principal) this.getPrincipal()).getName();
|
||||||
return ((Principal) getPrincipal()).getName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (this.getPrincipal() == null) ? "" : this.getPrincipal().toString();
|
return (this.getPrincipal() == null) ? "" : this.getPrincipal().toString();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user