Package org.apache.shiro.subject.support
Class SubjectCallable<V>
-
- org.apache.shiro.subject.support.SubjectCallable<V>
-
- All Implemented Interfaces:
<V>
public class SubjectCallable<V> extends implements <V>
ASubjectCallable
associates aSubject
with a target/delegate 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 a ), 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
is - 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, <V> delegate)
protected
SubjectCallable(ThreadState threadState, <V> delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description V
call()
protected V
<V> target)
-
-
-
Field Detail
-
threadState
protected final ThreadState threadState
-
-
Constructor Detail
-
SubjectCallable
protected SubjectCallable(ThreadState threadState, <V> delegate)
-
-