Package org.springframework.security.concurrent

# Class DelegatingSecurityContextCallable<V>

java.lang.Object
org.springframework.security.concurrent.DelegatingSecurityContextCallable<V>

All Implemented Interfaces:
  `Callable<V>`

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.

If there is a `SecurityContext` that already exists, it will be restored after the `call()` method is invoked.

Since:
  3.2

## Constructor Summary

Constructors
Constructor
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`.

## Method Summary

Modifier and Type
Method
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`
`setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy)`
Sets the `SecurityContextHolderStrategy` to use.
`String`
`toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### DelegatingSecurityContextCallable

public DelegatingSecurityContextCallable(Callable<V> delegate, SecurityContext securityContext)
Creates a new `DelegatingSecurityContextCallable` with a specific `SecurityContext`.

Parameters:
  `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.

### DelegatingSecurityContextCallable

public DelegatingSecurityContextCallable(Callable<V> delegate)
Creates a new `DelegatingSecurityContextCallable` with the `SecurityContext` from the `SecurityContextHolder`.

Parameters:
  `delegate` - the delegate `Callable` to run under the current `SecurityContext`. Cannot be null.

## Method Details

### call

public V call() throws Exception

Specified by:
  `call` in interface `Callable<V>`
Throws:
  `Exception`

### setSecurityContextHolderStrategy

public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy)
Sets the `SecurityContextHolderStrategy` to use. The default action is to use the `SecurityContextHolderStrategy` stored in `SecurityContextHolder`.

Since:
  5.8

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### create

public 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`

Parameters:
  `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()`
Returns: