mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-24 04:52:16 +00:00
Add toString() method so more informative when context propagation takes place, such as via ContextPropagatingRemoteInvocation.
This commit is contained in:
parent
ae86435a9e
commit
ba16c01b90
@ -39,6 +39,19 @@ public class SecureContextImpl extends ContextImpl implements SecureContext {
|
|||||||
return this.authentication;
|
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 {
|
public void validate() throws ContextInvalidException {
|
||||||
super.validate();
|
super.validate();
|
||||||
|
|
||||||
|
@ -55,11 +55,14 @@ public class SecureContextImplTests extends TestCase {
|
|||||||
context.setAuthentication(auth);
|
context.setAuthentication(auth);
|
||||||
context.validate();
|
context.validate();
|
||||||
assertEquals(auth, context.getAuthentication());
|
assertEquals(auth, context.getAuthentication());
|
||||||
|
assertTrue(context.toString().lastIndexOf("marissa") != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSecureContextDetectsMissingAuthenticationObject() {
|
public void testSecureContextDetectsMissingAuthenticationObject() {
|
||||||
SecureContext context = new SecureContextImpl();
|
SecureContext context = new SecureContextImpl();
|
||||||
|
|
||||||
|
assertTrue(context.toString().lastIndexOf("Null authentication") != -1);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context.validate();
|
context.validate();
|
||||||
fail("Should have thrown ContextInvalidException");
|
fail("Should have thrown ContextInvalidException");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user