Package org.apache.shiro.subject.support
Class SubjectThreadState
- java.lang.Object
-
- org.apache.shiro.subject.support.SubjectThreadState
-
- All Implemented Interfaces:
ThreadState
public class SubjectThreadState extends Object implements ThreadState
Manages thread-state forSubjectaccess (supportingSecurityUtils.getSubject()calls) during a thread's execution. Thebindmethod will bind aSubjectand aSecurityManagerto theThreadContextso they can be retrieved from theThreadContextlater by anySecurityUtils.getSubject()calls that might occur during the thread's execution.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description SubjectThreadState(Subject subject)Creates a newSubjectThreadStatethat will bind and unbind the specifiedSubjectto the thread
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind()Binds aSubjectandSecurityManagerto theThreadContextso they can be retrieved later by anySecurityUtils.getSubject()calls that might occur during the thread's execution.voidclear()CompletelyremovestheThreadContextstate.protected SubjectgetSubject()Returns theSubjectinstance managed by thisThreadStateimplementation.voidrestore()Removes all thread-state that was bound by this instance.
-
-
-
Constructor Detail
-
SubjectThreadState
public SubjectThreadState(Subject subject)
Creates a newSubjectThreadStatethat will bind and unbind the specifiedSubjectto the thread- Parameters:
subject- theSubjectinstance to bind and unbind from theThreadContext.
-
-
Method Detail
-
getSubject
protected Subject getSubject()
Returns theSubjectinstance managed by thisThreadStateimplementation.- Returns:
- the
Subjectinstance managed by thisThreadStateimplementation.
-
bind
public void 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
public void 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
public void 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
-
-