SEC-3031: DelegatingSecurityContext(Runnable|Callable) only modify SecurityContext on new Thread

Modifying the SecurityContext on the same Thread can cause issues. For example, with a
RejectedExecutionHandler the SecurityContext may be cleared out on the original Thread.

This change modifies both the DelegatingSecurityContextRunnable and DelegatingSecurityContextCallable to,
by default, only modify the SecurityContext if they are invoked on a new Thread. The behavior can be changed
by setting the property enableOnOrigionalThread to true.
This commit is contained in:
Rob Winch
2015-07-22 15:33:59 -05:00
parent 113b61e3a0
commit 117f892c91
5 changed files with 146 additions and 22 deletions

View File

@@ -321,7 +321,7 @@ public class SecurityContextHolderAwareRequestFilterTests {
.getValue();
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, SecurityContext.class))
.isEqualTo(context);
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, Runnable.class))
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, "delegate"))
.isEqualTo(runnable);
}
@@ -348,7 +348,7 @@ public class SecurityContextHolderAwareRequestFilterTests {
.getValue();
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, SecurityContext.class))
.isEqualTo(context);
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, Runnable.class))
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, "delegate"))
.isEqualTo(runnable);
}
@@ -375,7 +375,7 @@ public class SecurityContextHolderAwareRequestFilterTests {
.getValue();
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, SecurityContext.class))
.isEqualTo(context);
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, Runnable.class))
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, "delegate"))
.isEqualTo(runnable);
}