Interface SubjectContext
- All Known Implementing Classes:
DefaultSubjectContext
A
SubjectContext is a 'bucket' of data presented to a SecurityManager which interprets
this data to construct 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.
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 SecurityManager or
SubjectFactory implementation to construct Subject instances.
Data Resolution
TheSubjectContext 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 resolve*
methods can use heuristics to obtain that data in another way from other attributes.
For example, if one calls getPrincipals() and no principals are returned, perhaps the principals exist
in the session or another attribute in the context. The resolvePrincipals() will know
how to resolve the principals based on heuristics. If the resolve* methods return null then the
data could not be achieved by any heuristics and must be considered as not available in the context.
The general idea is that the normal getters can be called to see if the value was explicitly set. The
resolve* methods should be used when actually constructing the Subject instance to ensure the most
specific/accurate data can be used.
USAGE: Most Shiro end-users will never use a SubjectContext instance directly and instead will use a
Subject.Builder (which internally uses a SubjectContext) and build Subject instances that
way.- Since:
- 1.0
- See Also:
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetHost()Returns the host name or IP that should reflect the constructedSubject's originating location.Returns the principals (aka identity) that the constructedSubjectshould reflect.Returns the SecurityManager instance that should be used to back the constructedSubjectinstance ornullif one has not yet been provided to this context.Returns theSessionto use when building theSubjectinstance.Returns the session id of the session that should be associated with the constructedSubjectinstance.Returns any existingSubjectthat may be in use at the time the newSubjectinstance is being created.booleanReturnstrueif the constructedSubjectshould be considered authenticated,falseotherwise.booleanReturnstrueif the constructedSubjectshould be allowed to create a session,falseotherwise.booleanResolves theSecurityManagerinstance that should be used to back the constructedSubjectinstance (typically used to supportDelegatingSubjectimplementations).voidsetAuthenticated(boolean authc) Sets whether or not the constructedSubjectinstance should be considered as authenticated.voidvoidvoidSets the host name or IP that should reflect the constructedSubject's originating location.voidsetPrincipals(PrincipalCollection principals) Sets the principals (aka identity) that the constructedSubjectshould reflect.voidsetSecurityManager(SecurityManager securityManager) Sets the SecurityManager instance that should be used to back the constructedSubjectinstance (typically used to supportDelegatingSubjectimplementations).voidsetSession(Session session) Sets theSessionto use when building theSubjectinstance.voidsetSessionCreationEnabled(boolean enabled) Sets whether or not the constructedSubjectinstance should be allowed to create a session,falseotherwise.voidsetSessionId(Serializable sessionId) Sets the session id of the session that should be associated with the constructedSubjectinstance.voidsetSubject(Subject subject) Sets the existingSubjectthat may be in use at the time the newSubjectinstance is being created.Methods inherited from interface java.util.Map
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
-
Method Details
-
getSecurityManager
Returns the SecurityManager instance that should be used to back the constructedSubjectinstance ornullif one has not yet been provided to this context.- Returns:
- the SecurityManager instance that should be used to back the constructed
Subjectinstance ornullif one has not yet been provided to this context.
-
setSecurityManager
Sets the SecurityManager instance that should be used to back the constructedSubjectinstance (typically used to supportDelegatingSubjectimplementations).- Parameters:
securityManager- the SecurityManager instance that should be used to back the constructedSubjectinstance.
-
resolveSecurityManager
Resolves theSecurityManagerinstance that should be used to back the constructedSubjectinstance (typically used to supportDelegatingSubjectimplementations).- Returns:
- the
SecurityManagerinstance that should be used to back the constructedSubjectinstance
-
getSessionId
Returns the session id of the session that should be associated with the constructedSubjectinstance. The construction process is expected to resolve the session with the specified id and then construct the Subject instance based on the resolved session.- Returns:
- the session id of the session that should be associated with the constructed
Subjectinstance.
-
setSessionId
Sets the session id of the session that should be associated with the constructedSubjectinstance. The construction process is expected to resolve the session with the specified id and then construct the Subject instance based on the resolved session.- Parameters:
sessionId- the session id of the session that should be associated with the constructedSubjectinstance.
-
getSubject
Returns any existingSubjectthat may be in use at the time the newSubjectinstance is being created. This is typically used in the case where the existingSubjectinstance returned by this method is unauthenticated and a newSubjectinstance is being created to reflect a successful authentication - you want to return most of the state of the previousSubjectinstance when creating the newly authenticated instance.- Returns:
- any existing
Subjectthat may be in use at the time the newSubjectinstance is being created.
-
setSubject
Sets the existingSubjectthat may be in use at the time the newSubjectinstance is being created. This is typically used in the case where the existingSubjectinstance returned by this method is unauthenticated and a newSubjectinstance is being created to reflect a successful authentication - you want to return most of the state of the previousSubjectinstance when creating the newly authenticated instance.- Parameters:
subject- the existingSubjectthat may be in use at the time the newSubjectinstance is being created.
-
getPrincipals
Returns the principals (aka identity) that the constructedSubjectshould reflect.- Returns:
- the principals (aka identity) that the constructed
Subjectshould reflect.
-
resolvePrincipals
-
setPrincipals
Sets the principals (aka identity) that the constructedSubjectshould reflect.- Parameters:
principals- the principals (aka identity) that the constructedSubjectshould reflect.
-
getSession
Returns theSessionto use when building theSubjectinstance. Note that it is more common to specify asessionIdto acquire the desired session rather than having to construct aSessionto be returned by this method.- Returns:
- the
Sessionto use when building theSubjectinstance.
-
setSession
Sets theSessionto use when building theSubjectinstance. Note that it is more common to specify asessionIdto automatically resolve the desired session rather than constructing aSessionto call this method.- Parameters:
session- theSessionto use when building theSubjectinstance.
-
resolveSession
-
isAuthenticated
boolean isAuthenticated()Returnstrueif the constructedSubjectshould be considered authenticated,falseotherwise. Be careful setting this value totrue- you should know what you are doing and have a good reason for ignoring Shiro's default authentication state mechanisms.- Returns:
trueif the constructedSubjectshould be considered authenticated,falseotherwise.
-
setAuthenticated
Sets whether or not the constructedSubjectinstance should be considered as authenticated. Be careful when specifyingtrue- you should know what you are doing and have a good reason for ignoring Shiro's default authentication state mechanisms.- Parameters:
authc- whether or not the constructedSubjectinstance should be considered as authenticated.
-
isSessionCreationEnabled
boolean isSessionCreationEnabled()Returnstrueif the constructedSubjectshould be allowed to create a session,falseotherwise. Shiro's configuration defaults totrueas most applications find value in Sessions.- Returns:
trueif the constructedSubjectshould be allowed to create sessions,falseotherwise.- Since:
- 1.2
-
setSessionCreationEnabled
Sets whether or not the constructedSubjectinstance should be allowed to create a session,falseotherwise.- Parameters:
enabled- whether or not the constructedSubjectinstance should be allowed to create a session,falseotherwise.- Since:
- 1.2
-
resolveAuthenticated
boolean resolveAuthenticated() -
getAuthenticationInfo
-
setAuthenticationInfo
-
getAuthenticationToken
-
setAuthenticationToken
-
getHost
-
setHost
-
resolveHost
-