Class SubjectThreadState
java.lang.Object
org.apache.shiro.subject.support.SubjectThreadState
- All Implemented Interfaces:
ThreadState
Manages thread-state for
Subject access (supporting
SecurityUtils.getSubject() calls)
during a thread's execution.
The bind method will bind a Subject and a
SecurityManager to the ThreadContext so they can be retrieved
from the ThreadContext later by any
SecurityUtils.getSubject() calls that might occur during
the thread's execution.- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionSubjectThreadState(Subject subject) Creates a newSubjectThreadStatethat will bind and unbind the specifiedSubjectto the thread -
Method Summary
Modifier and TypeMethodDescriptionvoidbind()Binds aSubjectandSecurityManagerto theThreadContextso they can be retrieved later by anySecurityUtils.getSubject()calls that might occur during the thread's execution.voidclear()CompletelyremovestheThreadContextstate.protected SubjectReturns theSubjectinstance managed by thisThreadStateimplementation.voidrestore()Removes all thread-state that was bound by this instance.
-
Constructor Details
-
SubjectThreadState
Creates a newSubjectThreadStatethat will bind and unbind the specifiedSubjectto the thread- Parameters:
subject- theSubjectinstance to bind and unbind from theThreadContext.
-
-
Method Details
-
getSubject
Returns theSubjectinstance managed by thisThreadStateimplementation.- Returns:
- the
Subjectinstance managed by thisThreadStateimplementation.
-
bind
Binds aSubjectandSecurityManagerto theThreadContextso they can be retrieved later by anySecurityUtils.getSubject()calls that might occur during the thread's execution. Prior to binding, theThreadContext's existingresourcesare retained so they can be restored later via therestorecall.- Specified by:
bindin interfaceThreadState
-
restore
Removes all thread-state that was bound by this instance. If any previous thread-bound resources existed prior to thebindcall, they are restored back to theThreadContextto ensure the thread state is exactly as it was before binding.- Specified by:
restorein interfaceThreadState
-
clear
CompletelyremovestheThreadContextstate. Typically this method should only be called in special cases - it is more 'correct' torestorea thread to its previous state than to clear it entirely.- Specified by:
clearin interfaceThreadState
-