mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-12 05:13:33 +00:00
Provide toString() method on User.
This commit is contained in:
parent
a2b9da7e22
commit
0530351f0d
@ -185,6 +185,29 @@ public class User implements UserDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return username;
|
StringBuffer sb = new StringBuffer();
|
||||||
|
sb.append(super.toString() + ": ");
|
||||||
|
sb.append("Username: " + this.username + "; ");
|
||||||
|
sb.append("Password: [PROTECTED]; ");
|
||||||
|
sb.append("Enabled: " + this.enabled + "; ");
|
||||||
|
sb.append("AccountNonExpired: " + this.accountNonExpired + "; ");
|
||||||
|
sb.append("credentialsNonExpired: " + this.credentialsNonExpired + "; ");
|
||||||
|
sb.append("AccountNonLocked: " + this.accountNonLocked + "; ");
|
||||||
|
|
||||||
|
if (this.getAuthorities() != null) {
|
||||||
|
sb.append("Granted Authorities: ");
|
||||||
|
|
||||||
|
for (int i = 0; i < this.getAuthorities().length; i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
sb.append(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(this.getAuthorities()[i].toString());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sb.append("Not granted any authorities");
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,7 @@ public class UserTests extends TestCase {
|
|||||||
user.getAuthorities()[0]);
|
user.getAuthorities()[0]);
|
||||||
assertEquals(new GrantedAuthorityImpl("ROLE_TWO"),
|
assertEquals(new GrantedAuthorityImpl("ROLE_TWO"),
|
||||||
user.getAuthorities()[1]);
|
user.getAuthorities()[1]);
|
||||||
|
assertTrue(user.toString().indexOf("marissa") != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUserIsEnabled() throws Exception {
|
public void testUserIsEnabled() throws Exception {
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
<action dev="benalex" type="update">UserDetails now advises locked accounts, with corresponding DaoAuthenticationProvider events and enforcement</action>
|
<action dev="benalex" type="update">UserDetails now advises locked accounts, with corresponding DaoAuthenticationProvider events and enforcement</action>
|
||||||
<action dev="benalex" type="update">ContextHolderAwareRequestWrapper methods returns null if user is anonymous</action>
|
<action dev="benalex" type="update">ContextHolderAwareRequestWrapper methods returns null if user is anonymous</action>
|
||||||
<action dev="benalex" type="update">AbstractBasicAclEntry improved compatibility with Hibernate</action>
|
<action dev="benalex" type="update">AbstractBasicAclEntry improved compatibility with Hibernate</action>
|
||||||
|
<action dev="benalex" type="update">User now provides a more useful toString() method</action>
|
||||||
<action dev="benalex" type="fix">SecurityEnforcementFilter caused NullPointerException when anonymous authentication used with BasicProcessingFilterEntryPoint</action>
|
<action dev="benalex" type="fix">SecurityEnforcementFilter caused NullPointerException when anonymous authentication used with BasicProcessingFilterEntryPoint</action>
|
||||||
<action dev="benalex" type="fix">FilterChainProxy now supports replacement of ServletRequest and ServetResponse by Filter beans</action>
|
<action dev="benalex" type="fix">FilterChainProxy now supports replacement of ServletRequest and ServetResponse by Filter beans</action>
|
||||||
<action dev="fbos" type="fix">Corrected Authz parsing of whitespace in GrantedAuthoritys</action>
|
<action dev="fbos" type="fix">Corrected Authz parsing of whitespace in GrantedAuthoritys</action>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user