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 Summary
ConstructorsConstructorDescriptionDelegatingSecurityContextRunnable(Runnable delegate) Creates a newDelegatingSecurityContextRunnablewith theSecurityContextfrom theSecurityContextHolder.DelegatingSecurityContextRunnable(Runnable delegate, SecurityContext securityContext) Creates a newDelegatingSecurityContextRunnablewith a specificSecurityContext. -
Method Summary
Modifier and TypeMethodDescriptionstatic Runnablecreate(Runnable delegate, SecurityContext securityContext) Factory method for creating aDelegatingSecurityContextRunnable.voidrun()voidsetSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use.toString()
-
Constructor Details
-
DelegatingSecurityContextRunnable
Creates a newDelegatingSecurityContextRunnablewith a specificSecurityContext.- Parameters:
delegate- the delegateRunnableto run with the specifiedSecurityContext. Cannot be null.securityContext- theSecurityContextto establish for the delegateRunnable. Cannot be null.
-
DelegatingSecurityContextRunnable
Creates a newDelegatingSecurityContextRunnablewith theSecurityContextfrom theSecurityContextHolder.- Parameters:
delegate- the delegateRunnableto run under the currentSecurityContext. Cannot be null.
-
-
Method Details
-
run
public void run() -
setSecurityContextHolderStrategy
public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use. The default action is to use theSecurityContextHolderStrategystored inSecurityContextHolder.- Since:
- 5.8
-
toString
-
create
Factory method for creating aDelegatingSecurityContextRunnable.- Parameters:
delegate- the originalRunnablethat will be delegated to after establishing aSecurityContexton theSecurityContextHolder. Cannot have null.securityContext- theSecurityContextto establish before invoking the delegateRunnable. If null, the currentSecurityContextfrom theSecurityContextHolderwill be used.- Returns:
-