public class DefaultSubjectContext extends MapContext implements SubjectContext
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).Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
DefaultSubjectContext() |
DefaultSubjectContext(SubjectContext ctx) |
Modifier and Type | Method and Description |
---|---|
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. |
clear, containsKey, containsValue, entrySet, get, getTypedValue, isEmpty, keySet, nullSafePut, put, putAll, remove, size, values
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
public static final String SESSION_CREATION_ENABLED
public static final String PRINCIPALS_SESSION_KEY
public static final String AUTHENTICATED_SESSION_KEY
public DefaultSubjectContext()
public DefaultSubjectContext(SubjectContext ctx)
public SecurityManager getSecurityManager()
SubjectContext
Subject
instance or
null
if one has not yet been provided to this context.getSecurityManager
in interface SubjectContext
Subject
instance or
null
if one has not yet been provided to this context.public void setSecurityManager(SecurityManager securityManager)
SubjectContext
Subject
instance
(typically used to support DelegatingSubject
implementations).setSecurityManager
in interface SubjectContext
securityManager
- the SecurityManager instance that should be used to back the constructed Subject
instance.public SecurityManager resolveSecurityManager()
SubjectContext
SecurityManager
instance that should be used to back the constructed Subject
instance (typically used to support DelegatingSubject
implementations).resolveSecurityManager
in interface SubjectContext
SecurityManager
instance that should be used to back the constructed Subject
instancepublic Serializable getSessionId()
SubjectContext
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.getSessionId
in interface SubjectContext
Subject
instance.public void setSessionId(Serializable sessionId)
SubjectContext
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.setSessionId
in interface SubjectContext
sessionId
- the session id of the session that should be associated with the constructed Subject
instance.public Subject getSubject()
SubjectContext
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.getSubject
in interface SubjectContext
Subject
that may be in use at the time the new Subject
instance is
being created.public void setSubject(Subject subject)
SubjectContext
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.setSubject
in interface SubjectContext
subject
- the existing Subject
that may be in use at the time the new Subject
instance is
being created.public PrincipalCollection getPrincipals()
SubjectContext
Subject
should reflect.getPrincipals
in interface SubjectContext
Subject
should reflect.public void setPrincipals(PrincipalCollection principals)
SubjectContext
Subject
should reflect.setPrincipals
in interface SubjectContext
principals
- the principals (aka identity) that the constructed Subject
should reflect.public PrincipalCollection resolvePrincipals()
resolvePrincipals
in interface SubjectContext
public Session getSession()
SubjectContext
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.getSession
in interface SubjectContext
Session
to use when building the Subject
instance.public void setSession(Session session)
SubjectContext
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.setSession
in interface SubjectContext
session
- the Session
to use when building the Subject
instance.public Session resolveSession()
resolveSession
in interface SubjectContext
public boolean isSessionCreationEnabled()
SubjectContext
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.isSessionCreationEnabled
in interface SubjectContext
true
if the constructed Subject
should be allowed to create sessions, false
otherwise.public void setSessionCreationEnabled(boolean enabled)
SubjectContext
Subject
instance should be allowed to create a session,
false
otherwise.setSessionCreationEnabled
in interface SubjectContext
enabled
- whether or not the constructed Subject
instance should be allowed to create a session,
false
otherwise.public boolean isAuthenticated()
SubjectContext
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.isAuthenticated
in interface SubjectContext
true
if the constructed Subject
should be considered authenticated, false
otherwise.public void setAuthenticated(boolean authc)
SubjectContext
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.setAuthenticated
in interface SubjectContext
authc
- whether or not the constructed Subject
instance should be considered as authenticated.public boolean resolveAuthenticated()
resolveAuthenticated
in interface SubjectContext
public AuthenticationInfo getAuthenticationInfo()
getAuthenticationInfo
in interface SubjectContext
public void setAuthenticationInfo(AuthenticationInfo info)
setAuthenticationInfo
in interface SubjectContext
public AuthenticationToken getAuthenticationToken()
getAuthenticationToken
in interface SubjectContext
public void setAuthenticationToken(AuthenticationToken token)
setAuthenticationToken
in interface SubjectContext
public String getHost()
SubjectContext
Subject
's originating location.getHost
in interface SubjectContext
Subject
's originating location.public void setHost(String host)
SubjectContext
Subject
's originating location.setHost
in interface SubjectContext
host
- the host name or IP that should reflect the constructed Subject
's originating location.public String resolveHost()
resolveHost
in interface SubjectContext
Copyright © 2004-2016 The Apache Software Foundation. All Rights Reserved.