Class DelegatingSecurityContextCallable<V>
- java.lang.Object
-
- org.springframework.security.concurrent.DelegatingSecurityContextCallable<V>
-
- All Implemented Interfaces:
java.util.concurrent.Callable<V>
public final class DelegatingSecurityContextCallable<V> extends java.lang.Object implements java.util.concurrent.Callable<V>
Wraps a delegate
Callable
with logic for setting up aSecurityContext
before invoking the delegateCallable
and then removing theSecurityContext
after the delegate has completed.If there is a
SecurityContext
that already exists, it will be restored after thecall()
method is invoked.- Since:
- 3.2
-
-
Constructor Summary
Constructors Constructor Description DelegatingSecurityContextCallable(java.util.concurrent.Callable<V> delegate)
Creates a newDelegatingSecurityContextCallable
with theSecurityContext
from theSecurityContextHolder
.DelegatingSecurityContextCallable(java.util.concurrent.Callable<V> delegate, SecurityContext securityContext)
Creates a newDelegatingSecurityContextCallable
with a specificSecurityContext
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description V
call()
static <V> java.util.concurrent.Callable<V>
create(java.util.concurrent.Callable<V> delegate, SecurityContext securityContext)
Creates aDelegatingSecurityContextCallable
and with the givenCallable
andSecurityContext
, but if the securityContext is null will defaults to the currentSecurityContext
on theSecurityContextHolder
void
setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy)
Sets theSecurityContextHolderStrategy
to use.java.lang.String
toString()
-
-
-
Constructor Detail
-
DelegatingSecurityContextCallable
public DelegatingSecurityContextCallable(java.util.concurrent.Callable<V> delegate, SecurityContext securityContext)
Creates a newDelegatingSecurityContextCallable
with a specificSecurityContext
.- Parameters:
delegate
- the delegateDelegatingSecurityContextCallable
to run with the specifiedSecurityContext
. Cannot be null.securityContext
- theSecurityContext
to establish for the delegateCallable
. Cannot be null.
-
DelegatingSecurityContextCallable
public DelegatingSecurityContextCallable(java.util.concurrent.Callable<V> delegate)
Creates a newDelegatingSecurityContextCallable
with theSecurityContext
from theSecurityContextHolder
.- Parameters:
delegate
- the delegateCallable
to run under the currentSecurityContext
. Cannot be null.
-
-
Method Detail
-
call
public V call() throws java.lang.Exception
- Specified by:
call
in interfacejava.util.concurrent.Callable<V>
- Throws:
java.lang.Exception
-
setSecurityContextHolderStrategy
public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy)
Sets theSecurityContextHolderStrategy
to use. The default action is to use theSecurityContextHolderStrategy
stored inSecurityContextHolder
.- Since:
- 5.8
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
create
public static <V> java.util.concurrent.Callable<V> create(java.util.concurrent.Callable<V> delegate, SecurityContext securityContext)
Creates aDelegatingSecurityContextCallable
and with the givenCallable
andSecurityContext
, but if the securityContext is null will defaults to the currentSecurityContext
on theSecurityContextHolder
- Parameters:
delegate
- the delegateDelegatingSecurityContextCallable
to run with the specifiedSecurityContext
. Cannot be null.securityContext
- theSecurityContext
to establish for the delegateCallable
. If null, defaults toSecurityContextHolder.getContext()
- Returns:
-
-