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.Runnable
Wraps a delegate
Runnable
with logic for setting up aSecurityContext
before invoking the delegateRunnable
and then removing theSecurityContext
after the delegate has completed.If there is a
SecurityContext
that 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 newDelegatingSecurityContextRunnable
with theSecurityContext
from theSecurityContextHolder
.DelegatingSecurityContextRunnable(java.lang.Runnable delegate, SecurityContext securityContext)
Creates a newDelegatingSecurityContextRunnable
with a specificSecurityContext
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.Runnable
create(java.lang.Runnable delegate, SecurityContext securityContext)
Factory method for creating aDelegatingSecurityContextRunnable
.void
run()
java.lang.String
toString()
-
-
-
Constructor Detail
-
DelegatingSecurityContextRunnable
public DelegatingSecurityContextRunnable(java.lang.Runnable delegate, SecurityContext securityContext)
Creates a newDelegatingSecurityContextRunnable
with a specificSecurityContext
.- Parameters:
delegate
- the delegateRunnable
to run with the specifiedSecurityContext
. Cannot be null.securityContext
- theSecurityContext
to establish for the delegateRunnable
. Cannot be null.
-
DelegatingSecurityContextRunnable
public DelegatingSecurityContextRunnable(java.lang.Runnable delegate)
Creates a newDelegatingSecurityContextRunnable
with theSecurityContext
from theSecurityContextHolder
.- Parameters:
delegate
- the delegateRunnable
to run under the currentSecurityContext
. Cannot be null.
-
-
Method Detail
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
create
public static java.lang.Runnable create(java.lang.Runnable delegate, SecurityContext securityContext)
Factory method for creating aDelegatingSecurityContextRunnable
.- Parameters:
delegate
- the originalRunnable
that will be delegated to after establishing aSecurityContext
on theSecurityContextHolder
. Cannot have null.securityContext
- theSecurityContext
to establish before invoking the delegateRunnable
. If null, the currentSecurityContext
from theSecurityContextHolder
will be used.- Returns:
-
-