org.apache.shiro.subject.support
Class DefaultSubjectContext

java.lang.Object
  extended by org.apache.shiro.util.MapContext
      extended by org.apache.shiro.subject.support.DefaultSubjectContext
All Implemented Interfaces:
Serializable, Map<String,Object>, SubjectContext

public class DefaultSubjectContext
extends MapContext
implements SubjectContext

Default implementation of the SubjectContext interface. Note that the getters and setters are not simple pass-through methods to an underlying attribute; the getters will employ numerous heuristics to acquire their data attribute as best as possible (for example, if getPrincipals() is invoked, if the principals aren't in the backing map, it might check to see if there is a subject or session in the map and attempt to acquire the principals from those objects).

Since:
1.0
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
static String AUTHENTICATED_SESSION_KEY
          The session key that is used to store whether or not the user is authenticated.
static String PRINCIPALS_SESSION_KEY
          The session key that is used to store subject principals.
static String SESSION_CREATION_ENABLED
           
 
Constructor Summary
DefaultSubjectContext()
           
DefaultSubjectContext(SubjectContext ctx)
           
 
Method Summary
 AuthenticationInfo getAuthenticationInfo()
           
 AuthenticationToken getAuthenticationToken()
           
 String getHost()
          Returns the host name or IP that should reflect the constructed Subject's originating location.
 PrincipalCollection getPrincipals()
          Returns the principals (aka identity) that the constructed Subject should reflect.
 SecurityManager getSecurityManager()
          Returns the SecurityManager instance that should be used to back the constructed Subject instance or null if one has not yet been provided to this context.
 Session getSession()
          Returns the Session to use when building the Subject instance.
 Serializable getSessionId()
          Returns the session id of the session that should be associated with the constructed Subject instance.
 Subject getSubject()
          Returns any existing Subject that may be in use at the time the new Subject instance is being created.
 boolean isAuthenticated()
          Returns true if the constructed Subject should be considered authenticated, false otherwise.
 boolean isSessionCreationEnabled()
          Returns true if the constructed Subject should be allowed to create a session, false otherwise.
 boolean resolveAuthenticated()
           
 String resolveHost()
           
 PrincipalCollection resolvePrincipals()
           
 SecurityManager resolveSecurityManager()
          Resolves the SecurityManager instance that should be used to back the constructed Subject instance (typically used to support DelegatingSubject implementations).
 Session resolveSession()
           
 void setAuthenticated(boolean authc)
          Sets whether or not the constructed Subject instance should be considered as authenticated.
 void setAuthenticationInfo(AuthenticationInfo info)
           
 void setAuthenticationToken(AuthenticationToken token)
           
 void setHost(String host)
          Sets the host name or IP that should reflect the constructed Subject's originating location.
 void setPrincipals(PrincipalCollection principals)
          Sets the principals (aka identity) that the constructed Subject should reflect.
 void setSecurityManager(SecurityManager securityManager)
          Sets the SecurityManager instance that should be used to back the constructed Subject instance (typically used to support DelegatingSubject implementations).
 void setSession(Session session)
          Sets the Session to use when building the Subject instance.
 void setSessionCreationEnabled(boolean enabled)
          Sets whether or not the constructed Subject instance should be allowed to create a session, false otherwise.
 void setSessionId(Serializable sessionId)
          Sets the session id of the session that should be associated with the constructed Subject instance.
 void setSubject(Subject subject)
          Sets the existing Subject that may be in use at the time the new Subject instance is being created.
 
Methods inherited from class org.apache.shiro.util.MapContext
clear, containsKey, containsValue, entrySet, get, getTypedValue, isEmpty, keySet, nullSafePut, put, putAll, remove, size, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Field Detail

SESSION_CREATION_ENABLED

public static final String SESSION_CREATION_ENABLED

PRINCIPALS_SESSION_KEY

public static final String PRINCIPALS_SESSION_KEY
The session key that is used to store subject principals.


AUTHENTICATED_SESSION_KEY

public static final String AUTHENTICATED_SESSION_KEY
The session key that is used to store whether or not the user is authenticated.

Constructor Detail

DefaultSubjectContext

public DefaultSubjectContext()

DefaultSubjectContext

public DefaultSubjectContext(SubjectContext ctx)
Method Detail

getSecurityManager

public SecurityManager getSecurityManager()
Description copied from interface: SubjectContext
Returns the SecurityManager instance that should be used to back the constructed Subject instance or null if one has not yet been provided to this context.

Specified by:
getSecurityManager in interface SubjectContext
Returns:
the SecurityManager instance that should be used to back the constructed Subject instance or null if one has not yet been provided to this context.

setSecurityManager

public void setSecurityManager(SecurityManager securityManager)
Description copied from interface: SubjectContext
Sets the SecurityManager instance that should be used to back the constructed Subject instance (typically used to support DelegatingSubject implementations).

Specified by:
setSecurityManager in interface SubjectContext
Parameters:
securityManager - the SecurityManager instance that should be used to back the constructed Subject instance.

resolveSecurityManager

public SecurityManager resolveSecurityManager()
Description copied from interface: SubjectContext
Resolves the SecurityManager instance that should be used to back the constructed Subject instance (typically used to support DelegatingSubject implementations).

Specified by:
resolveSecurityManager in interface SubjectContext
Returns:
the SecurityManager instance that should be used to back the constructed Subject instance

getSessionId

public Serializable getSessionId()
Description copied from interface: SubjectContext
Returns the session id of the session that should be associated with the constructed Subject instance.

The construction process is expected to resolve the session with the specified id and then construct the Subject instance based on the resolved session.

Specified by:
getSessionId in interface SubjectContext
Returns:
the session id of the session that should be associated with the constructed Subject instance.

setSessionId

public void setSessionId(Serializable sessionId)
Description copied from interface: SubjectContext
Sets the session id of the session that should be associated with the constructed Subject instance.

The construction process is expected to resolve the session with the specified id and then construct the Subject instance based on the resolved session.

Specified by:
setSessionId in interface SubjectContext
Parameters:
sessionId - the session id of the session that should be associated with the constructed Subject instance.

getSubject

public Subject getSubject()
Description copied from interface: SubjectContext
Returns any existing Subject that may be in use at the time the new Subject instance is being created.

This is typically used in the case where the existing Subject instance returned by this method is unauthenticated and a new Subject instance is being created to reflect a successful authentication - you want to return most of the state of the previous Subject instance when creating the newly authenticated instance.

Specified by:
getSubject in interface SubjectContext
Returns:
any existing Subject that may be in use at the time the new Subject instance is being created.

setSubject

public void setSubject(Subject subject)
Description copied from interface: SubjectContext
Sets the existing Subject that may be in use at the time the new Subject instance is being created.

This is typically used in the case where the existing Subject instance returned by this method is unauthenticated and a new Subject instance is being created to reflect a successful authentication - you want to return most of the state of the previous Subject instance when creating the newly authenticated instance.

Specified by:
setSubject in interface SubjectContext
Parameters:
subject - the existing Subject that may be in use at the time the new Subject instance is being created.

getPrincipals

public PrincipalCollection getPrincipals()
Description copied from interface: SubjectContext
Returns the principals (aka identity) that the constructed Subject should reflect.

Specified by:
getPrincipals in interface SubjectContext
Returns:
the principals (aka identity) that the constructed Subject should reflect.

setPrincipals

public void setPrincipals(PrincipalCollection principals)
Description copied from interface: SubjectContext
Sets the principals (aka identity) that the constructed Subject should reflect.

Specified by:
setPrincipals in interface SubjectContext
Parameters:
principals - the principals (aka identity) that the constructed Subject should reflect.

resolvePrincipals

public PrincipalCollection resolvePrincipals()
Specified by:
resolvePrincipals in interface SubjectContext

getSession

public Session getSession()
Description copied from interface: SubjectContext
Returns the Session to use when building the Subject instance. Note that it is more common to specify a sessionId to acquire the desired session rather than having to construct a Session to be returned by this method.

Specified by:
getSession in interface SubjectContext
Returns:
the Session to use when building the Subject instance.

setSession

public void setSession(Session session)
Description copied from interface: SubjectContext
Sets the Session to use when building the Subject instance. Note that it is more common to specify a sessionId to automatically resolve the desired session rather than constructing a Session to call this method.

Specified by:
setSession in interface SubjectContext
Parameters:
session - the Session to use when building the Subject instance.

resolveSession

public Session resolveSession()
Specified by:
resolveSession in interface SubjectContext

isSessionCreationEnabled

public boolean isSessionCreationEnabled()
Description copied from interface: SubjectContext
Returns true if the constructed Subject should be allowed to create a session, false otherwise. Shiro's configuration defaults to true as most applications find value in Sessions.

Specified by:
isSessionCreationEnabled in interface SubjectContext
Returns:
true if the constructed Subject should be allowed to create sessions, false otherwise.

setSessionCreationEnabled

public void setSessionCreationEnabled(boolean enabled)
Description copied from interface: SubjectContext
Sets whether or not the constructed Subject instance should be allowed to create a session, false otherwise.

Specified by:
setSessionCreationEnabled in interface SubjectContext
Parameters:
enabled - whether or not the constructed Subject instance should be allowed to create a session, false otherwise.

isAuthenticated

public boolean isAuthenticated()
Description copied from interface: SubjectContext
Returns true if the constructed Subject should be considered authenticated, false otherwise. Be careful setting this value to true - you should know what you are doing and have a good reason for ignoring Shiro's default authentication state mechanisms.

Specified by:
isAuthenticated in interface SubjectContext
Returns:
true if the constructed Subject should be considered authenticated, false otherwise.

setAuthenticated

public void setAuthenticated(boolean authc)
Description copied from interface: SubjectContext
Sets whether or not the constructed Subject instance should be considered as authenticated. Be careful when specifying true - you should know what you are doing and have a good reason for ignoring Shiro's default authentication state mechanisms.

Specified by:
setAuthenticated in interface SubjectContext
Parameters:
authc - whether or not the constructed Subject instance should be considered as authenticated.

resolveAuthenticated

public boolean resolveAuthenticated()
Specified by:
resolveAuthenticated in interface SubjectContext

getAuthenticationInfo

public AuthenticationInfo getAuthenticationInfo()
Specified by:
getAuthenticationInfo in interface SubjectContext

setAuthenticationInfo

public void setAuthenticationInfo(AuthenticationInfo info)
Specified by:
setAuthenticationInfo in interface SubjectContext

getAuthenticationToken

public AuthenticationToken getAuthenticationToken()
Specified by:
getAuthenticationToken in interface SubjectContext

setAuthenticationToken

public void setAuthenticationToken(AuthenticationToken token)
Specified by:
setAuthenticationToken in interface SubjectContext

getHost

public String getHost()
Description copied from interface: SubjectContext
Returns the host name or IP that should reflect the constructed Subject's originating location.

Specified by:
getHost in interface SubjectContext
Returns:
the host name or IP that should reflect the constructed Subject's originating location.

setHost

public void setHost(String host)
Description copied from interface: SubjectContext
Sets the host name or IP that should reflect the constructed Subject's originating location.

Specified by:
setHost in interface SubjectContext
Parameters:
host - the host name or IP that should reflect the constructed Subject's originating location.

resolveHost

public String resolveHost()
Specified by:
resolveHost in interface SubjectContext


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