Class DefaultSubjectContext

  • All Implemented Interfaces:
    , <,​>, 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
    • Field Detail

      • SESSION_CREATION_ENABLED

        public static final  SESSION_CREATION_ENABLED
      • PRINCIPALS_SESSION_KEY

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

        public static final  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.
      • getSessionId

        public  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​( 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.
      • 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.
      • 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.
      • getHost

        public  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​( 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.