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
Callablewith logic for setting up aSecurityContextbefore invoking the delegateCallableand then removing theSecurityContextafter the delegate has completed.If there is a
SecurityContextthat 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 newDelegatingSecurityContextCallablewith theSecurityContextfrom theSecurityContextHolder.DelegatingSecurityContextCallable(java.util.concurrent.Callable<V> delegate, SecurityContext securityContext)Creates a newDelegatingSecurityContextCallablewith a specificSecurityContext.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Vcall()static <V> java.util.concurrent.Callable<V>create(java.util.concurrent.Callable<V> delegate, SecurityContext securityContext)Creates aDelegatingSecurityContextCallableand with the givenCallableandSecurityContext, but if the securityContext is null will defaults to the currentSecurityContexton theSecurityContextHolderjava.lang.StringtoString()
-
-
-
Constructor Detail
-
DelegatingSecurityContextCallable
public DelegatingSecurityContextCallable(java.util.concurrent.Callable<V> delegate, SecurityContext securityContext)
Creates a newDelegatingSecurityContextCallablewith a specificSecurityContext.- Parameters:
delegate- the delegateDelegatingSecurityContextCallableto run with the specifiedSecurityContext. Cannot be null.securityContext- theSecurityContextto establish for the delegateCallable. Cannot be null.
-
DelegatingSecurityContextCallable
public DelegatingSecurityContextCallable(java.util.concurrent.Callable<V> delegate)
Creates a newDelegatingSecurityContextCallablewith theSecurityContextfrom theSecurityContextHolder.- Parameters:
delegate- the delegateCallableto run under the currentSecurityContext. Cannot be null.
-
-
Method Detail
-
call
public V call() throws java.lang.Exception
- Specified by:
callin interfacejava.util.concurrent.Callable<V>- Throws:
java.lang.Exception
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
create
public static <V> java.util.concurrent.Callable<V> create(java.util.concurrent.Callable<V> delegate, SecurityContext securityContext)Creates aDelegatingSecurityContextCallableand with the givenCallableandSecurityContext, but if the securityContext is null will defaults to the currentSecurityContexton theSecurityContextHolder- Parameters:
delegate- the delegateDelegatingSecurityContextCallableto run with the specifiedSecurityContext. Cannot be null.securityContext- theSecurityContextto establish for the delegateCallable. If null, defaults toSecurityContextHolder.getContext()- Returns:
-
-