public final class DelegatingSecurityContextRunnable extends Object implements Runnable
Wraps a delegate Runnable with logic for setting up a SecurityContext
before invoking the delegate Runnable and then removing the
SecurityContext after the delegate has completed.
By default the SecurityContext is only setup if run() is
invoked on a separate Thread than the
DelegatingSecurityContextRunnable was created on. This can be
overridden by setting setEnableOnOriginalThread(boolean) to true.
| Constructor and Description |
|---|
DelegatingSecurityContextRunnable(Runnable delegate)
Creates a new
DelegatingSecurityContextRunnable with the SecurityContext from the
SecurityContextHolder. |
DelegatingSecurityContextRunnable(Runnable delegate,
SecurityContext securityContext)
Creates a new
DelegatingSecurityContextRunnable with a specific SecurityContext. |
| Modifier and Type | Method and Description |
|---|---|
static Runnable |
create(Runnable delegate,
SecurityContext securityContext)
Factory method for creating a
DelegatingSecurityContextRunnable. |
void |
run() |
void |
setEnableOnOriginalThread(boolean enableOnOriginalThread)
Determines if the SecurityContext should be transfered if
#call()
is invoked on the same Thread the
DelegatingSecurityContextCallable was created on. |
String |
toString() |
public DelegatingSecurityContextRunnable(Runnable delegate, SecurityContext securityContext)
DelegatingSecurityContextRunnable with a specific SecurityContext.delegate - the delegate Runnable to run with the specified SecurityContext. Cannot be null.securityContext - the SecurityContext to establish for the delegate Runnable. Cannot be
null.public DelegatingSecurityContextRunnable(Runnable delegate)
DelegatingSecurityContextRunnable with the SecurityContext from the
SecurityContextHolder.delegate - the delegate Runnable to run under the current SecurityContext. Cannot be null.public void setEnableOnOriginalThread(boolean enableOnOriginalThread)
#call()
is invoked on the same Thread the
DelegatingSecurityContextCallable was created on.enableOnOriginalThread - if false (default), will only transfer the
SecurityContext if #call() is invoked on a
different Thread than the
DelegatingSecurityContextCallable was created on.public static Runnable create(Runnable delegate, SecurityContext securityContext)
DelegatingSecurityContextRunnable.delegate - the original Runnable that will be delegated to after establishing a
SecurityContext on the SecurityContextHolder. Cannot have null.securityContext - the SecurityContext to establish before invoking the delegate Runnable. If
null, the current SecurityContext from the SecurityContextHolder will be used.