public final class DelegatingSecurityContextCallable<V> extends Object implements Callable<V>
Wraps a delegate Callable
with logic for setting up a
SecurityContext
before invoking the delegate Callable
and
then removing the SecurityContext
after the delegate has completed.
By default the SecurityContext
is only setup if call()
is
invoked on a separate Thread
than the
DelegatingSecurityContextCallable
was created on. This can be
overridden by setting setEnableOnOriginalThread(boolean)
to true.
Constructor and Description |
---|
DelegatingSecurityContextCallable(Callable<V> delegate)
Creates a new
DelegatingSecurityContextCallable with the
SecurityContext from the SecurityContextHolder . |
DelegatingSecurityContextCallable(Callable<V> delegate,
SecurityContext securityContext)
Creates a new
DelegatingSecurityContextCallable with a specific
SecurityContext . |
Modifier and Type | Method and Description |
---|---|
V |
call() |
static <V> Callable<V> |
create(Callable<V> delegate,
SecurityContext securityContext)
Creates a
DelegatingSecurityContextCallable and with the given
Callable and SecurityContext , but if the securityContext is null
will defaults to the current SecurityContext on the
SecurityContextHolder |
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 DelegatingSecurityContextCallable(Callable<V> delegate, SecurityContext securityContext)
DelegatingSecurityContextCallable
with a specific
SecurityContext
.delegate
- the delegate DelegatingSecurityContextCallable
to run with
the specified SecurityContext
. Cannot be null.securityContext
- the SecurityContext
to establish for the delegate
Callable
. Cannot be null.public DelegatingSecurityContextCallable(Callable<V> delegate)
DelegatingSecurityContextCallable
with the
SecurityContext
from the SecurityContextHolder
.delegate
- the delegate Callable
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 <V> Callable<V> create(Callable<V> delegate, SecurityContext securityContext)
DelegatingSecurityContextCallable
and with the given
Callable
and SecurityContext
, but if the securityContext is null
will defaults to the current SecurityContext
on the
SecurityContextHolder
delegate
- the delegate DelegatingSecurityContextCallable
to run with
the specified SecurityContext
. Cannot be null.securityContext
- the SecurityContext
to establish for the delegate
Callable
. If null, defaults to SecurityContextHolder.getContext()