SEC-252: Stop NPE if principal object is null.
This commit is contained in:
parent
fba45cb19e
commit
de4af379cc
|
@ -141,30 +141,32 @@ public abstract class AbstractAuthenticationToken implements Authentication {
|
||||||
return ((UserDetails) this.getPrincipal()).getUsername();
|
return ((UserDetails) this.getPrincipal()).getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.getPrincipal().toString();
|
return (this.getPrincipal() == null) ? "" : this.getPrincipal()
|
||||||
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int code = 31;
|
int code = 31;
|
||||||
|
|
||||||
// Copy authorities to local variable for performance (SEC-223)
|
// Copy authorities to local variable for performance (SEC-223)
|
||||||
GrantedAuthority[] authorities = this.getAuthorities();
|
GrantedAuthority[] authorities = this.getAuthorities();
|
||||||
|
|
||||||
if (authorities != null) {
|
if (authorities != null) {
|
||||||
for (int i = 0; i < authorities.length; i++) {
|
for (int i = 0; i < authorities.length; i++) {
|
||||||
code ^= authorities[i].hashCode();
|
code ^= authorities[i].hashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getPrincipal() != null) {
|
if (this.getPrincipal() != null) {
|
||||||
code ^= this.getPrincipal().hashCode();
|
code ^= this.getPrincipal().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getCredentials() != null) {
|
if (this.getCredentials() != null) {
|
||||||
code ^= this.getCredentials().hashCode();
|
code ^= this.getCredentials().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getDetails() != null) {
|
if (this.getDetails() != null) {
|
||||||
code ^= this.getDetails().hashCode();
|
code ^= this.getDetails().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isAuthenticated()) {
|
if (this.isAuthenticated()) {
|
||||||
|
|
Loading…
Reference in New Issue