diff --git a/core/src/main/java/org/acegisecurity/context/SecureContextImpl.java b/core/src/main/java/org/acegisecurity/context/SecureContextImpl.java index e1d0d1ba07..6e46525869 100644 --- a/core/src/main/java/org/acegisecurity/context/SecureContextImpl.java +++ b/core/src/main/java/org/acegisecurity/context/SecureContextImpl.java @@ -39,6 +39,19 @@ public class SecureContextImpl extends ContextImpl implements SecureContext { return this.authentication; } + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append(super.toString()); + + if (this.authentication == null) { + sb.append(": Null authentication"); + } else { + sb.append(": Authentication: " + this.authentication); + } + + return sb.toString(); + } + public void validate() throws ContextInvalidException { super.validate(); diff --git a/core/src/test/java/org/acegisecurity/context/SecureContextImplTests.java b/core/src/test/java/org/acegisecurity/context/SecureContextImplTests.java index 80617ceffb..838553b61c 100644 --- a/core/src/test/java/org/acegisecurity/context/SecureContextImplTests.java +++ b/core/src/test/java/org/acegisecurity/context/SecureContextImplTests.java @@ -55,11 +55,14 @@ public class SecureContextImplTests extends TestCase { context.setAuthentication(auth); context.validate(); assertEquals(auth, context.getAuthentication()); + assertTrue(context.toString().lastIndexOf("marissa") != -1); } public void testSecureContextDetectsMissingAuthenticationObject() { SecureContext context = new SecureContextImpl(); + assertTrue(context.toString().lastIndexOf("Null authentication") != -1); + try { context.validate(); fail("Should have thrown ContextInvalidException");