public final class DelegatingSecurityContextCallable<V>
extends java.lang.Object
implements java.util.concurrent.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.
If there is a SecurityContext
that already exists, it will be
restored after the call()
method is invoked.
Constructor and Description |
---|
DelegatingSecurityContextCallable(java.util.concurrent.Callable<V> delegate)
Creates a new
DelegatingSecurityContextCallable with the
SecurityContext from the SecurityContextHolder . |
DelegatingSecurityContextCallable(java.util.concurrent.Callable<V> delegate,
SecurityContext securityContext)
Creates a new
DelegatingSecurityContextCallable with a specific
SecurityContext . |
Modifier and Type | Method and Description |
---|---|
V |
call() |
static <V> java.util.concurrent.Callable<V> |
create(java.util.concurrent.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 |
java.lang.String |
toString() |
public DelegatingSecurityContextCallable(java.util.concurrent.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(java.util.concurrent.Callable<V> delegate)
DelegatingSecurityContextCallable
with the
SecurityContext
from the SecurityContextHolder
.delegate
- the delegate Callable
to run under the current
SecurityContext
. Cannot be null.public V call() throws java.lang.Exception
call
in interface java.util.concurrent.Callable<V>
java.lang.Exception
public java.lang.String toString()
toString
in class java.lang.Object
public static <V> java.util.concurrent.Callable<V> create(java.util.concurrent.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()