Package org.springframework.security.web.context.request.async

# Class SecurityContextCallableProcessingInterceptor

java.lang.Object
org.springframework.security.web.context.request.async.SecurityContextCallableProcessingInterceptor

All Implemented Interfaces:
  `org.springframework.web.context.request.async.CallableProcessingInterceptor`

public final class SecurityContextCallableProcessingInterceptor extends Object implements org.springframework.web.context.request.async.CallableProcessingInterceptor

Allows for integration with Spring MVC's `Callable` support.

A `CallableProcessingInterceptor` that establishes the injected `SecurityContext` on the `SecurityContextHolder` when `preProcess(NativeWebRequest, Callable)` is invoked. It also clear out the `SecurityContextHolder` by invoking `SecurityContextHolder.clearContext()` in the `postProcess(NativeWebRequest, Callable, Object)` method.

Since:
  3.2

## Field Summary

### Fields inherited from interface org.springframework.web.context.request.async.CallableProcessingInterceptor

`RESPONSE_HANDLED, RESULT_NONE`

## Constructor Summary

Constructors
Constructor
Description
`SecurityContextCallableProcessingInterceptor()`
Create a new `SecurityContextCallableProcessingInterceptor` that uses the `SecurityContext` from the `SecurityContextHolder` at the time `beforeConcurrentHandling(NativeWebRequest, Callable)` is invoked.
`SecurityContextCallableProcessingInterceptor(org.springframework.security.core.context.SecurityContext securityContext)`
Creates a new `SecurityContextCallableProcessingInterceptor` with the specified `SecurityContext`.

## Method Summary

Modifier and Type
Method
Description
`<T> void`
`beforeConcurrentHandling(org.springframework.web.context.request.NativeWebRequest request, Callable<T> task)`
`<T> void`
`postProcess(org.springframework.web.context.request.NativeWebRequest request, Callable<T> task, Object concurrentResult)`
`<T> void`
`preProcess(org.springframework.web.context.request.NativeWebRequest request, Callable<T> task)`
`void`
`setSecurityContextHolderStrategy(org.springframework.security.core.context.SecurityContextHolderStrategy securityContextHolderStrategy)`
Sets the `SecurityContextHolderStrategy` to use.

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

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

### Methods inherited from interface org.springframework.web.context.request.async.CallableProcessingInterceptor

`afterCompletion, handleError, handleTimeout`

## Constructor Details

### SecurityContextCallableProcessingInterceptor

public SecurityContextCallableProcessingInterceptor()
Create a new `SecurityContextCallableProcessingInterceptor` that uses the `SecurityContext` from the `SecurityContextHolder` at the time `beforeConcurrentHandling(NativeWebRequest, Callable)` is invoked.

### SecurityContextCallableProcessingInterceptor

public SecurityContextCallableProcessingInterceptor(org.springframework.security.core.context.SecurityContext securityContext)
Creates a new `SecurityContextCallableProcessingInterceptor` with the specified `SecurityContext`.

Parameters:
  `securityContext` - the `SecurityContext` to set on the `SecurityContextHolder` in `preProcess(NativeWebRequest, Callable)`. Cannot be null.
Throws:
  `IllegalArgumentException` - if `SecurityContext` is null.

## Method Details

### beforeConcurrentHandling

public <T> void beforeConcurrentHandling(org.springframework.web.context.request.NativeWebRequest request, Callable<T> task)

Specified by:
  `beforeConcurrentHandling` in interface `org.springframework.web.context.request.async.CallableProcessingInterceptor`

### preProcess

public <T> void preProcess(org.springframework.web.context.request.NativeWebRequest request, Callable<T> task)

Specified by:
  `preProcess` in interface `org.springframework.web.context.request.async.CallableProcessingInterceptor`

### postProcess

public <T> void postProcess(org.springframework.web.context.request.NativeWebRequest request, Callable<T> task, Object concurrentResult)

Specified by:
  `postProcess` in interface `org.springframework.web.context.request.async.CallableProcessingInterceptor`

### setSecurityContextHolderStrategy

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

Since:
  5.8