SubjectContext

A {@code SubjectContext} is a 'bucket' of data presented to a {@link SecurityManager} which interprets this data to construct {@link hunt.shiro.subject.Subject Subject} instances. It is essentially a Map of data with a few additional type-safe methods for easy retrieval of objects commonly used to construct Subject instances. <p/> While this interface contains type-safe setters and getters for common data types, the map can contain anything additional that might be needed by the {@link SecurityManager} or {@link hunt.shiro.mgt.SubjectFactory SubjectFactory} implementation to construct {@code Subject} instances. <h2>Data Resolution</h2> The {@link SubjectContext} interface also allows for heuristic resolution of data used to construct a subject instance. That is, if an attribute has not been explicitly provided via a setter method, the {@code resolve*} methods can use heuristics to obtain that data in another way from other attributes. <p/> For example, if one calls {@link #getPrincipals()} and no principals are returned, perhaps the principals exist in the {@link #getSession() session} or another attribute in the context. The {@link #resolvePrincipals()} will know how to resolve the principals based on heuristics. If the {@code resolve*} methods return {@code null} then the data could not be achieved by any heuristics and must be considered as not available in the context. <p/> The general idea is that the normal getters can be called to see if the value was explicitly set. The {@code resolve*} methods should be used when actually constructing the {@code Subject} instance to ensure the most specific/accurate data can be used. <p/> <b>USAGE</b>: Most Shiro end-users will never use a {@code SubjectContext} instance directly and instead will use a {@link Subject.Builder} (which internally uses a {@code SubjectContext}) and build {@code Subject} instances that way.

@see hunt.shiro.mgt.SecurityManager#createSubject SecurityManager.createSubject @see hunt.shiro.mgt.SubjectFactory SubjectFactory

Members

Functions

getAuthenticationInfo
AuthenticationInfo getAuthenticationInfo()
Undocumented in source.
getAuthenticationToken
AuthenticationToken getAuthenticationToken()
Undocumented in source.
getHost
string getHost()

Returns the host name or IP that should reflect the constructed {@code Subject}'s originating location.

getPrincipals
PrincipalCollection getPrincipals()

Returns the principals (aka identity) that the constructed {@code Subject} should reflect.

getSecurityManager
SecurityManager getSecurityManager()

Returns the SecurityManager instance that should be used to back the constructed {@link Subject} instance or {@code null} if one has not yet been provided to this context.

getSession
Session getSession()

Returns the {@code Session} to use when building the {@code Subject} instance. Note that it is more common to specify a {@link #setSessionId sessionId} to acquire the desired session rather than having to construct a {@code Session} to be returned by this method.

getSessionId
string getSessionId()

Returns the session id of the session that should be associated with the constructed {@link Subject} instance. <p/> The construction process is expected to resolve the session with the specified id and then construct the Subject instance based on the resolved session.

getSubject
Subject getSubject()

Returns any existing {@code Subject} that may be in use at the time the new {@code Subject} instance is being created. <p/> This is typically used in the case where the existing {@code Subject} instance returned by this method is unauthenticated and a new {@code Subject} instance is being created to reflect a successful authentication - you want to return most of the state of the previous {@code Subject} instance when creating the newly authenticated instance.

isAuthenticated
bool isAuthenticated()

Returns {@code true} if the constructed {@code Subject} should be considered authenticated, {@code false} otherwise. Be careful setting this value to {@code true} - you should know what you are doing and have a good reason for ignoring Shiro's default authentication state mechanisms.

isSessionCreationEnabled
bool isSessionCreationEnabled()

Returns {@code true} if the constructed {@code Subject} should be allowed to create a session, {@code false} otherwise. Shiro's configuration defaults to {@code true} as most applications find value in Sessions.

resolveAuthenticated
bool resolveAuthenticated()
Undocumented in source.
resolveHost
string resolveHost()
Undocumented in source.
resolvePrincipals
PrincipalCollection resolvePrincipals()
Undocumented in source.
resolveSecurityManager
SecurityManager resolveSecurityManager()

Resolves the {@code SecurityManager} instance that should be used to back the constructed {@link Subject} instance (typically used to support {@link hunt.shiro.subject.support.DelegatingSubject DelegatingSubject} implementations).

resolveSession
Session resolveSession()
Undocumented in source.
setAuthenticated
void setAuthenticated(bool authc)

Sets whether or not the constructed {@code Subject} instance should be considered as authenticated. Be careful when specifying {@code true} - you should know what you are doing and have a good reason for ignoring Shiro's default authentication state mechanisms.

setAuthenticationInfo
void setAuthenticationInfo(AuthenticationInfo info)
Undocumented in source.
setAuthenticationToken
void setAuthenticationToken(AuthenticationToken token)
Undocumented in source.
setHost
void setHost(string host)

Sets the host name or IP that should reflect the constructed {@code Subject}'s originating location.

setPrincipals
void setPrincipals(PrincipalCollection principals)

Sets the principals (aka identity) that the constructed {@code Subject} should reflect.

setSecurityManager
void setSecurityManager(SecurityManager securityManager)

Sets the SecurityManager instance that should be used to back the constructed {@link Subject} instance (typically used to support {@link hunt.shiro.subject.support.DelegatingSubject DelegatingSubject} implementations).

setSession
void setSession(Session session)

Sets the {@code Session} to use when building the {@code Subject} instance. Note that it is more common to specify a {@link #setSessionId sessionId} to automatically resolve the desired session rather than constructing a {@code Session} to call this method.

setSessionCreationEnabled
void setSessionCreationEnabled(bool enabled)

Sets whether or not the constructed {@code Subject} instance should be allowed to create a session, {@code false} otherwise.

setSessionId
void setSessionId(string sessionId)

Sets the session id of the session that should be associated with the constructed {@link Subject} instance. <p/> The construction process is expected to resolve the session with the specified id and then construct the Subject instance based on the resolved session.

setSubject
void setSubject(Subject subject)

Sets the existing {@code Subject} that may be in use at the time the new {@code Subject} instance is being created. <p/> This is typically used in the case where the existing {@code Subject} instance returned by this method is unauthenticated and a new {@code Subject} instance is being created to reflect a successful authentication - you want to return most of the state of the previous {@code Subject} instance when creating the newly authenticated instance.

Meta