Class SubjectCallable<V>
java.lang.Object
org.apache.shiro.subject.support.SubjectCallable<V>
- Type Parameters:
V- V
- All Implemented Interfaces:
Callable<V>
A
SubjectCallable associates a Subject with a target/delegate
Callable to ensure proper Subject thread-state management when the Callable executes.
This ensures that any calls to SecurityUtils.getSubject()
during the target Callable's execution still work correctly even if the Callable executes on a
different thread than the one that created it. This allows Subject access during asynchronous operations.
When instances of this class execute (typically via a ExecutorService),
the following occurs:
- The specified Subject any of its associated thread state is first bound to the thread that executes the
Callable. - The delegate/target
Callableisexecuted - The previous thread state that might have existed before the
Subjectwas bound is fully restored
Callable, which is often a different thread than
the one that created the instance, retains a Subject to support SecurityUtils.getSubject()
invocations. It also guarantees that the running thread remains 'clean' in any thread-pooled environments.
Usage
This is typically considered a support class and is not often directly referenced. Most people prefer to use
the Subject.associateWith method, which will automatically return
an instance of this class.
SubjectAwareExecutorService, which
transparently uses instances of this class.- Since:
- 1.0
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionSubjectCallable(Subject subject, Callable<V> delegate) protectedSubjectCallable(ThreadState threadState, Callable<V> delegate) -
Method Summary
-
Field Details
-
threadState
-
-
Constructor Details
-
SubjectCallable
-
SubjectCallable
-
-
Method Details
-
call
-
doCall
-