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 forSubject
access (supportingSecurityUtils.
getSubject()
calls) during a thread's execution. Thebind
method will bind aSubject
and aSecurityManager
to theThreadContext
so they can be retrieved from theThreadContext
later 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 newSubjectThreadState
that will bind and unbind the specifiedSubject
to the thread
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bind()
Binds aSubject
andSecurityManager
to theThreadContext
so they can be retrieved later by anySecurityUtils.
getSubject()
calls that might occur during the thread's execution.void
clear()
Completelyremoves
theThreadContext
state.protected Subject
getSubject()
Returns theSubject
instance managed by thisThreadState
implementation.void
restore()
Remove
s all thread-state that was bound by this instance.
-
-
-
Constructor Detail
-
SubjectThreadState
public SubjectThreadState(Subject subject)
Creates a newSubjectThreadState
that will bind and unbind the specifiedSubject
to the thread- Parameters:
subject
- theSubject
instance to bind and unbind from theThreadContext
.
-
-
Method Detail
-
getSubject
protected Subject getSubject()
Returns theSubject
instance managed by thisThreadState
implementation.- Returns:
- the
Subject
instance managed by thisThreadState
implementation.
-
bind
public void bind()
Binds aSubject
andSecurityManager
to theThreadContext
so they can be retrieved later by anySecurityUtils.
getSubject()
calls that might occur during the thread's execution. Prior to binding, theThreadContext
's existingresources
are retained so they can be restored later via therestore
call.- Specified by:
bind
in interfaceThreadState
-
restore
public void restore()
Remove
s all thread-state that was bound by this instance. If any previous thread-bound resources existed prior to thebind
call, they are restored back to theThreadContext
to ensure the thread state is exactly as it was before binding.- Specified by:
restore
in interfaceThreadState
-
clear
public void clear()
Completelyremoves
theThreadContext
state. Typically this method should only be called in special cases - it is more 'correct' torestore
a thread to its previous state than to clear it entirely.- Specified by:
clear
in interfaceThreadState
-
-