Class DelegatingSecurityContextRunnable
java.lang.Object
org.springframework.security.concurrent.DelegatingSecurityContextRunnable
- All Implemented Interfaces:
- Runnable
 Wraps a delegate Runnable with logic for setting up a SecurityContext
 before invoking the delegate Runnable and then removing the
 SecurityContext after the delegate has completed.
 
 If there is a SecurityContext that already exists, it will be restored after
 the run() method is invoked.
 
- Since:
- 3.2
- 
Constructor SummaryConstructorsConstructorDescriptionDelegatingSecurityContextRunnable(Runnable delegate) Creates a newDelegatingSecurityContextRunnablewith theSecurityContextfrom theSecurityContextHolder.DelegatingSecurityContextRunnable(Runnable delegate, SecurityContext securityContext) Creates a newDelegatingSecurityContextRunnablewith a specificSecurityContext.
- 
Method SummaryModifier and TypeMethodDescriptionstatic Runnablecreate(Runnable delegate, @Nullable SecurityContext securityContext) Factory method for creating aDelegatingSecurityContextRunnable.voidrun()voidsetSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use.toString()
- 
Constructor Details- 
DelegatingSecurityContextRunnableCreates a newDelegatingSecurityContextRunnablewith a specificSecurityContext.- Parameters:
- delegate- the delegate- Runnableto run with the specified- SecurityContext. Cannot be null.
- securityContext- the- SecurityContextto establish for the delegate- Runnable. Cannot be null.
 
- 
DelegatingSecurityContextRunnableCreates a newDelegatingSecurityContextRunnablewith theSecurityContextfrom theSecurityContextHolder.- Parameters:
- delegate- the delegate- Runnableto run under the current- SecurityContext. Cannot be null.
 
 
- 
- 
Method Details- 
runpublic void run()
- 
setSecurityContextHolderStrategypublic void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use. The default action is to use theSecurityContextHolderStrategystored inSecurityContextHolder.- Since:
- 5.8
 
- 
toString
- 
createFactory method for creating aDelegatingSecurityContextRunnable.- Parameters:
- delegate- the original- Runnablethat will be delegated to after establishing a- SecurityContexton the- SecurityContextHolder. Cannot have null.
- securityContext- the- SecurityContextto establish before invoking the delegate- Runnable. If null, the current- SecurityContextfrom the- SecurityContextHolderwill be used.
- Returns:
 
 
-