SEC-1792: Fixed NullPointerException in RunAsUserToken#toString()

This commit is contained in:
Rob Winch 2011-07-29 09:24:02 -05:00
parent dfd467f26e
commit 7399c9a7a5
2 changed files with 10 additions and 2 deletions

View File

@ -71,7 +71,8 @@ public class RunAsUserToken extends AbstractAuthenticationToken {
public String toString() {
StringBuilder sb = new StringBuilder(super.toString());
sb.append("; Original Class: ").append(this.originalAuthentication.getName());
String className = this.originalAuthentication == null ? null : this.originalAuthentication.getName();
sb.append("; Original Class: ").append(className);
return sb.toString();
}

View File

@ -58,6 +58,13 @@ public class RunAsUserTokenTests extends TestCase {
public void testToString() {
RunAsUserToken token = new RunAsUserToken("my_password", "Test", "Password",
AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"), UsernamePasswordAuthenticationToken.class);
assertTrue(token.toString().lastIndexOf("Original Class:") != -1);
assertTrue(token.toString().lastIndexOf("Original Class: "+UsernamePasswordAuthenticationToken.class.getName().toString()) != -1);
}
// SEC-1792
public void testToStringNullOriginalAuthentication() {
RunAsUserToken token = new RunAsUserToken("my_password", "Test", "Password",
AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"), null);
assertTrue(token.toString().lastIndexOf("Original Class: null") != -1);
}
}