mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-24 04:52:16 +00:00
Fix for SEC-111. Added a try/finally block to make sure context is always reset after the invocation.
This commit is contained in:
parent
58922e666a
commit
7847af2664
@ -117,7 +117,11 @@ public class ContextPropagatingRemoteInvocation extends RemoteInvocation {
|
|||||||
+ securityContext);
|
+ securityContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object result = super.invoke(targetObject);
|
try {
|
||||||
|
|
||||||
|
return super.invoke(targetObject);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
|
||||||
SecurityContextHolder.setContext(new SecurityContextImpl());
|
SecurityContextHolder.setContext(new SecurityContextImpl());
|
||||||
|
|
||||||
@ -125,7 +129,6 @@ public class ContextPropagatingRemoteInvocation extends RemoteInvocation {
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
"Set SecurityContext to new instance of SecurityContextImpl");
|
"Set SecurityContext to new instance of SecurityContextImpl");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,28 @@ public class ContextPropagatingRemoteInvocationTests extends TestCase {
|
|||||||
remoteInvocation.invoke(new TargetObject()));
|
remoteInvocation.invoke(new TargetObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testContextIsResetEvenIfExceptionOccurs() throws Exception {
|
||||||
|
// Setup client-side context
|
||||||
|
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("marissa",
|
||||||
|
"koala");
|
||||||
|
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
|
||||||
|
|
||||||
|
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Set up the wrong arguments.
|
||||||
|
remoteInvocation.setArguments(new Object[] {});
|
||||||
|
remoteInvocation.invoke(TargetObject.class.newInstance());
|
||||||
|
fail("Expected IllegalArgumentException");
|
||||||
|
} catch(IllegalArgumentException e) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
assertNull("Authentication must be null ", SecurityContextHolder.getContext().getAuthentication());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private ContextPropagatingRemoteInvocation getRemoteInvocation()
|
private ContextPropagatingRemoteInvocation getRemoteInvocation()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Class clazz = TargetObject.class;
|
Class clazz = TargetObject.class;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user