Class DefaultSubjectContext
java.lang.Object
org.apache.shiro.util.MapContext
org.apache.shiro.subject.support.DefaultSubjectContext
- All Implemented Interfaces:
Serializable,Map<String,,Object> 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:
-
Nested Class Summary
-
Field Summary
Fields -
Constructor Summary
Constructors -
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 class org.apache.shiro.util.MapContext
clear, containsKey, containsValue, entrySet, get, getTypedValue, isEmpty, keySet, nullSafePut, put, putAll, remove, size, valuesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
-
Field Details
-
SESSION_CREATION_ENABLED
session creation enabled key. -
PRINCIPALS_SESSION_KEY
The session key that is used to store subject principals. -
AUTHENTICATED_SESSION_KEY
The session key that is used to store whether or not the user is authenticated.
-
-
Constructor Details
-
DefaultSubjectContext
public DefaultSubjectContext() -
DefaultSubjectContext
-
-
Method Details
-
getSecurityManager
Description copied from interface:SubjectContextReturns the SecurityManager instance that should be used to back the constructedSubjectinstance ornullif one has not yet been provided to this context.- Specified by:
getSecurityManagerin interfaceSubjectContext- Returns:
- the SecurityManager instance that should be used to back the constructed
Subjectinstance ornullif one has not yet been provided to this context.
-
setSecurityManager
Description copied from interface:SubjectContextSets the SecurityManager instance that should be used to back the constructedSubjectinstance (typically used to supportDelegatingSubjectimplementations).- Specified by:
setSecurityManagerin interfaceSubjectContext- Parameters:
securityManager- the SecurityManager instance that should be used to back the constructedSubjectinstance.
-
resolveSecurityManager
Description copied from interface:SubjectContextResolves theSecurityManagerinstance that should be used to back the constructedSubjectinstance (typically used to supportDelegatingSubjectimplementations).- Specified by:
resolveSecurityManagerin interfaceSubjectContext- Returns:
- the
SecurityManagerinstance that should be used to back the constructedSubjectinstance
-
getSessionId
Description copied from interface:SubjectContextReturns 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.- Specified by:
getSessionIdin interfaceSubjectContext- Returns:
- the session id of the session that should be associated with the constructed
Subjectinstance.
-
setSessionId
Description copied from interface:SubjectContextSets 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.- Specified by:
setSessionIdin interfaceSubjectContext- Parameters:
sessionId- the session id of the session that should be associated with the constructedSubjectinstance.
-
getSubject
Description copied from interface:SubjectContextReturns 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.- Specified by:
getSubjectin interfaceSubjectContext- Returns:
- any existing
Subjectthat may be in use at the time the newSubjectinstance is being created.
-
setSubject
Description copied from interface:SubjectContextSets 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.- Specified by:
setSubjectin interfaceSubjectContext- Parameters:
subject- the existingSubjectthat may be in use at the time the newSubjectinstance is being created.
-
getPrincipals
Description copied from interface:SubjectContextReturns the principals (aka identity) that the constructedSubjectshould reflect.- Specified by:
getPrincipalsin interfaceSubjectContext- Returns:
- the principals (aka identity) that the constructed
Subjectshould reflect.
-
setPrincipals
Description copied from interface:SubjectContextSets the principals (aka identity) that the constructedSubjectshould reflect.- Specified by:
setPrincipalsin interfaceSubjectContext- Parameters:
principals- the principals (aka identity) that the constructedSubjectshould reflect.
-
resolvePrincipals
- Specified by:
resolvePrincipalsin interfaceSubjectContext
-
getSession
Description copied from interface:SubjectContextReturns 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.- Specified by:
getSessionin interfaceSubjectContext- Returns:
- the
Sessionto use when building theSubjectinstance.
-
setSession
Description copied from interface:SubjectContextSets 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.- Specified by:
setSessionin interfaceSubjectContext- Parameters:
session- theSessionto use when building theSubjectinstance.
-
resolveSession
- Specified by:
resolveSessionin interfaceSubjectContext
-
isSessionCreationEnabled
Description copied from interface:SubjectContextReturnstrueif the constructedSubjectshould be allowed to create a session,falseotherwise. Shiro's configuration defaults totrueas most applications find value in Sessions.- Specified by:
isSessionCreationEnabledin interfaceSubjectContext- Returns:
trueif the constructedSubjectshould be allowed to create sessions,falseotherwise.
-
setSessionCreationEnabled
Description copied from interface:SubjectContextSets whether or not the constructedSubjectinstance should be allowed to create a session,falseotherwise.- Specified by:
setSessionCreationEnabledin interfaceSubjectContext- Parameters:
enabled- whether or not the constructedSubjectinstance should be allowed to create a session,falseotherwise.
-
isAuthenticated
Description copied from interface:SubjectContextReturnstrueif 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.- Specified by:
isAuthenticatedin interfaceSubjectContext- Returns:
trueif the constructedSubjectshould be considered authenticated,falseotherwise.
-
setAuthenticated
Description copied from interface:SubjectContextSets 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.- Specified by:
setAuthenticatedin interfaceSubjectContext- Parameters:
authc- whether or not the constructedSubjectinstance should be considered as authenticated.
-
resolveAuthenticated
- Specified by:
resolveAuthenticatedin interfaceSubjectContext
-
getAuthenticationInfo
- Specified by:
getAuthenticationInfoin interfaceSubjectContext
-
setAuthenticationInfo
- Specified by:
setAuthenticationInfoin interfaceSubjectContext
-
getAuthenticationToken
- Specified by:
getAuthenticationTokenin interfaceSubjectContext
-
setAuthenticationToken
- Specified by:
setAuthenticationTokenin interfaceSubjectContext
-
getHost
Description copied from interface:SubjectContextReturns the host name or IP that should reflect the constructedSubject's originating location.- Specified by:
getHostin interfaceSubjectContext- Returns:
- the host name or IP that should reflect the constructed
Subject's originating location.
-
setHost
Description copied from interface:SubjectContextSets the host name or IP that should reflect the constructedSubject's originating location.- Specified by:
setHostin interfaceSubjectContext- Parameters:
host- the host name or IP that should reflect the constructedSubject's originating location.
-
resolveHost
- Specified by:
resolveHostin interfaceSubjectContext
-