Class DelegatingSecurityContextRunnable
- java.lang.Object
-
- org.springframework.security.concurrent.DelegatingSecurityContextRunnable
-
- All Implemented Interfaces:
java.lang.Runnable
public final class DelegatingSecurityContextRunnable extends java.lang.Object implements java.lang.RunnableWraps a delegate
Runnablewith logic for setting up aSecurityContextbefore invoking the delegateRunnableand then removing theSecurityContextafter the delegate has completed.If there is a
SecurityContextthat already exists, it will be restored after therun()method is invoked.- Since:
- 3.2
-
-
Constructor Summary
Constructors Constructor Description DelegatingSecurityContextRunnable(java.lang.Runnable delegate)Creates a newDelegatingSecurityContextRunnablewith theSecurityContextfrom theSecurityContextHolder.DelegatingSecurityContextRunnable(java.lang.Runnable delegate, SecurityContext securityContext)Creates a newDelegatingSecurityContextRunnablewith a specificSecurityContext.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.Runnablecreate(java.lang.Runnable delegate, SecurityContext securityContext)Factory method for creating aDelegatingSecurityContextRunnable.voidrun()voidsetSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy)Sets theSecurityContextHolderStrategyto use.java.lang.StringtoString()
-
-
-
Constructor Detail
-
DelegatingSecurityContextRunnable
public DelegatingSecurityContextRunnable(java.lang.Runnable delegate, SecurityContext securityContext)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
public DelegatingSecurityContextRunnable(java.lang.Runnable delegate)
Creates a newDelegatingSecurityContextRunnablewith theSecurityContextfrom theSecurityContextHolder.- Parameters:
delegate- the delegateRunnableto run under the currentSecurityContext. Cannot be null.
-
-
Method Detail
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
setSecurityContextHolderStrategy
public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy)
Sets theSecurityContextHolderStrategyto use. The default action is to use theSecurityContextHolderStrategystored inSecurityContextHolder.- Since:
- 5.8
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
create
public static java.lang.Runnable create(java.lang.Runnable delegate, SecurityContext securityContext)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:
-
-