org.apache.shiro.subject.support
Class SubjectThreadState

java.lang.Object
  extended by org.apache.shiro.subject.support.SubjectThreadState
All Implemented Interfaces:
ThreadState

public class SubjectThreadState
extends Object
implements 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
SubjectThreadState(Subject subject)
          Creates a new SubjectThreadState that will bind and unbind the specified Subject to the thread
 
Method Summary
 void bind()
          Binds a Subject and SecurityManager to the ThreadContext so they can be retrieved later by any SecurityUtils.getSubject() calls that might occur during the thread's execution.
 void clear()
          Completely removes the ThreadContext state.
protected  Subject getSubject()
          Returns the Subject instance managed by this ThreadState implementation.
 void restore()
          Removes all thread-state that was bound by this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SubjectThreadState

public SubjectThreadState(Subject subject)
Creates a new SubjectThreadState that will bind and unbind the specified Subject to the thread

Parameters:
subject - the Subject instance to bind and unbind from the ThreadContext.
Method Detail

getSubject

protected Subject getSubject()
Returns the Subject instance managed by this ThreadState implementation.

Returns:
the Subject instance managed by this ThreadState implementation.

bind

public void bind()
Binds a Subject and SecurityManager to the ThreadContext so they can be retrieved later by any SecurityUtils.getSubject() calls that might occur during the thread's execution.

Prior to binding, the ThreadContext's existing resources are retained so they can be restored later via the restore call.

Specified by:
bind in interface ThreadState

restore

public void restore()
Removes all thread-state that was bound by this instance. If any previous thread-bound resources existed prior to the bind call, they are restored back to the ThreadContext to ensure the thread state is exactly as it was before binding.

Specified by:
restore in interface ThreadState

clear

public void clear()
Completely removes the ThreadContext state. Typically this method should only be called in special cases - it is more 'correct' to restore a thread to its previous state than to clear it entirely.

Specified by:
clear in interface ThreadState


Copyright © 2004-2014 The Apache Software Foundation. All Rights Reserved.