Package org.apache.shiro.subject.support
Class SubjectCallable<V>
- java.lang.Object
-
- org.apache.shiro.subject.support.SubjectCallable<V>
-
- All Implemented Interfaces:
Callable<V>
public class SubjectCallable<V> extends Object implements Callable<V>
ASubjectCallableassociates aSubjectwith a target/delegateCallableto ensure properSubjectthread-state management when theCallableexecutes. This ensures that any calls toSecurityUtils.getSubject()during the targetCallable's execution still work correctly even if theCallableexecutes on a different thread than the one that created it. This allowsSubjectaccess during asynchronous operations. When instances of this class execute (typically via aExecutorService), 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 aSubjectto supportSecurityUtils.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 theSubject.associateWithmethod, which will automatically return an instance of this class. An even more convenient alternative is to use aSubjectAwareExecutorService, which transparently uses instances of this class.- Since:
- 1.0
- See Also:
Subject.associateWith(Callable),SubjectAwareExecutorService
-
-
Field Summary
Fields Modifier and Type Field Description protected ThreadStatethreadState
-
Constructor Summary
Constructors Modifier Constructor Description SubjectCallable(Subject subject, Callable<V> delegate)protectedSubjectCallable(ThreadState threadState, Callable<V> delegate)
-
-
-
Field Detail
-
threadState
protected final ThreadState threadState
-
-