public class SubjectRunnable extends Object implements Runnable
SubjectRunnableensures that a target/delegate
Runnablewill execute such that any call to
Runnable's execution will return the associated
SubjectRunnableinstance can be run on any thread (the current thread or asynchronously on another thread) and the
SecurityUtils.getSubject()call will still work properly. This implementation also guarantees that Shiro's thread state will be identical before and after execution to ensure threads remain clean in any thread-pooled environment. When instances of this class
run(), the following occurs:
Subjectwas bound is fully restored
associateWithmethods, which transparently perform the necessary association logic. An even more convenient alternative is to use a
SubjectAwareExecutor, which transparently uses instances of this class but does not require referencing Shiro's API at all.
|Modifier||Constructor and Description|
Creates a new
public SubjectRunnable(Subject subject, Runnable delegate)
SubjectRunnablethat, when executed, will execute the target
delegate, but guarantees that it will run associated with the specified
subject- the Subject to associate with the delegate's execution.
delegate- the runnable to run.
protected SubjectRunnable(ThreadState threadState, Runnable delegate) throws IllegalArgumentException
SubjectRunnablethat, when executed, will perform thread state
restorationbefore and after the
Runnable's execution, respectively.
public void run()
Binds the Subject thread state, executes the target
Runnableand then guarantees the previous thread state's
Copyright © 2004-2013 The Apache Software Foundation. All Rights Reserved.