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
ConstructorDescriptionDelegatingSecurityContextRunnable
(Runnable delegate) Creates a newDelegatingSecurityContextRunnable
with theSecurityContext
from theSecurityContextHolder
.DelegatingSecurityContextRunnable
(Runnable delegate, SecurityContext securityContext) Creates a newDelegatingSecurityContextRunnable
with a specificSecurityContext
. -
Method Summary
Modifier and TypeMethodDescriptionstatic Runnable
create
(Runnable delegate, SecurityContext securityContext) Factory method for creating aDelegatingSecurityContextRunnable
.void
run()
void
setSecurityContextHolderStrategy
(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategy
to use.toString()
-
Constructor Details
-
DelegatingSecurityContextRunnable
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
Creates a newDelegatingSecurityContextRunnable
with theSecurityContext
from theSecurityContextHolder
.- Parameters:
delegate
- the delegateRunnable
to run under the currentSecurityContext
. Cannot be null.
-
-
Method Details
-
run
public void run() -
setSecurityContextHolderStrategy
public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategy
to use. The default action is to use theSecurityContextHolderStrategy
stored inSecurityContextHolder
.- Since:
- 5.8
-
toString
-
create
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:
-