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>
ASubjectCallable
associates aSubject
with a target/delegateCallable
to ensure properSubject
thread-state management when theCallable
executes. This ensures that any calls toSecurityUtils.
getSubject()
during the targetCallable
's execution still work correctly even if theCallable
executes on a different thread than the one that created it. This allowsSubject
access 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
Callable
isexecuted
- The previous thread state that might have existed before the
Subject
was bound is fully restored
Callable
, which is often a different thread than the one that created the instance, retains aSubject
to 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.
associateWith
method, 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 ThreadState
threadState
-
Constructor Summary
Constructors Modifier Constructor Description SubjectCallable(Subject subject, Callable<V> delegate)
protected
SubjectCallable(ThreadState threadState, Callable<V> delegate)
-
-
-
Field Detail
-
threadState
protected final ThreadState threadState
-
-