Creates a new {@code SubjectThreadState} that will bind and unbind the specified {@code Subject} to the thread
Binds a {@link Subject} and {@link hunt.shiro.mgt.SecurityManager SecurityManager} to the {@link ThreadContext} so they can be retrieved later by any {@code SecurityUtils.}{@link hunt.shiro.SecurityUtils#getSubject() getSubject()} calls that might occur during the thread's execution. <p/> Prior to binding, the {@code ThreadContext}'s existing {@link ThreadContext#getResources() resources} are retained so they can be restored later via the {@link #restore restore} call.
Completely {@link ThreadContext#remove removes} the {@code ThreadContext} state. Typically this method should only be called in special cases - it is more 'correct' to {@link #restore restore} a thread to its previous state than to clear it entirely.
Returns the {@code Subject} instance managed by this {@code ThreadState} implementation.
{@link ThreadContext#remove Remove}s all thread-state that was bound by this instance. If any previous thread-bound resources existed prior to the {@link #bind bind} call, they are restored back to the {@code ThreadContext} to ensure the thread state is exactly as it was before binding.
Binds any state that should be made accessible during a thread's execution. This should typically always be called in a {@code try/finally} block paired with the {@link #restore} call to guarantee that the thread is cleanly restored back to its original state. For example: <pre> ThreadState state = //acquire or instantiate as necessary <b>try { state.bind(); doSomething(); //execute any logic downstream logic that might need to access the state } </b> finally { state.restore(); } </pre>
Restores a thread to its state before bind {@link #bind bind} was invoked. This should typically always be called in a {@code finally} block to guarantee that the thread is cleanly restored back to its original state before {@link #bind bind}'s bind was called. For example: <pre> ThreadState state = //acquire or instantiate as necessary try { state.bind(); doSomething(); //execute any logic downstream logic that might need to access the state } <b>finally { state.restore(); }</b> </pre>
Completely clears/removes the {@code ThreadContext} state. Typically this method should only be called in special cases - it is more 'correct' to {@link #restore restore} a thread to its previous state than to clear it entirely.
Manages thread-state for {@link Subject Subject} access (supporting {@code SecurityUtils.}{@link hunt.shiro.SecurityUtils#getSubject() getSubject()} calls) during a thread's execution. <p/> The {@link #bind bind} method will bind a {@link Subject} and a {@link hunt.shiro.mgt.SecurityManager SecurityManager} to the {@link ThreadContext} so they can be retrieved from the {@code ThreadContext} later by any {@code SecurityUtils.}{@link hunt.shiro.SecurityUtils#getSubject() getSubject()} calls that might occur during the thread's execution.