Provide toString() method on User.

This commit is contained in:
Ben Alex 2005-03-21 05:33:51 +00:00
parent a2b9da7e22
commit 0530351f0d
3 changed files with 26 additions and 1 deletions

View File

@ -185,6 +185,29 @@ public class User implements UserDetails {
}
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();
}
}

View File

@ -120,6 +120,7 @@ public class UserTests extends TestCase {
user.getAuthorities()[0]);
assertEquals(new GrantedAuthorityImpl("ROLE_TWO"),
user.getAuthorities()[1]);
assertTrue(user.toString().indexOf("marissa") != -1);
}
public void testUserIsEnabled() throws Exception {

View File

@ -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">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">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">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>