Class AbstractIdPSession

  • All Implemented Interfaces:
    IdPSession, Component, IdentifiedComponent

    @ThreadSafe
    public abstract class AbstractIdPSession
    extends Object
    implements IdPSession
    Abstract base for implementations of IdPSession, handles basic management of the instance data without addressing persistence.

    Data that can change post-construction can be modified using doSet/doAdd/doRemove methods that maintain the object state. Abstract methods defined here or left unimplemented from the interface should be implemented to call these methods and perform any additional work required to maintain the coherence of the underlying store, if any.

    The checkAddress(String) method is implemented by calling into other abstract and defined methods to check session state and update address information as required.

    • Field Detail

      • log

        @Nonnull
        private final org.slf4j.Logger log
        Class logger.
      • id

        @Nonnull
        @NotEmpty
        private final String id
        Unique ID of this session.
      • principalName

        @Nonnull
        @NotEmpty
        private final String principalName
        A canonical name for the subject of the session.
      • creationInstant

        @Nonnull
        private final Instant creationInstant
        Time when this session was created.
      • lastActivityInstant

        @Nonnull
        private Instant lastActivityInstant
        Last activity instant for this session.
      • ipV4Address

        @Nullable
        private String ipV4Address
        Addresses to which the session is bound.
      • ipV6Address

        @Nullable
        private String ipV6Address
        An IPv6 address to which the session is bound.
    • Constructor Detail

      • AbstractIdPSession

        public AbstractIdPSession​(@Nonnull @NotEmpty
                                  String sessionId,
                                  @Nonnull @NotEmpty
                                  String canonicalName,
                                  @Nonnull
                                  Instant creationTime)
        Constructor.
        Parameters:
        sessionId - identifier for this session
        canonicalName - canonical name of subject
        creationTime - creation time of session
    • Method Detail

      • getPrincipalName

        @Nonnull
        @NotEmpty
        public String getPrincipalName()
        Get the canonical principal name for the session.
        Specified by:
        getPrincipalName in interface IdPSession
        Returns:
        the principal name
      • getCreationInstant

        @Nonnull
        public Instant getCreationInstant()
        Get the time when this session was created.
        Specified by:
        getCreationInstant in interface IdPSession
        Returns:
        time this session was created
      • getLastActivityInstant

        @Nonnull
        public Instant getLastActivityInstant()
        Get the last activity instant for the session.
        Specified by:
        getLastActivityInstant in interface IdPSession
        Returns:
        last activity instant for the session
      • setLastActivityInstant

        public void setLastActivityInstant​(@Nonnull
                                           Instant instant)
                                    throws SessionException
        Set the last activity instant for the session.
        Parameters:
        instant - last activity instant for the session
        Throws:
        SessionException - if an error occurs updating the session
      • doSetLastActivityInstant

        public void doSetLastActivityInstant​(@Nonnull
                                             Instant instant)
        Set the last activity instant for the session.

        This manipulates only the internal state of the object. The setLastActivityInstant(Instant) method must be overridden to support other persistence requirements.

        Parameters:
        instant - last activity instant for the session
      • checkAddress

        public boolean checkAddress​(@Nonnull @NotEmpty
                                    String address)
                             throws SessionException
        Test the session's validity based on the supplied client address, possibly binding it to the session if appropriate.
        Specified by:
        checkAddress in interface IdPSession
        Parameters:
        address - client address for validation
        Returns:
        true iff the session is valid for the specified client address
        Throws:
        SessionException - if an error occurs binding the address to the session
      • getAddress

        @Nullable
        public String getAddress​(@Nonnull
                                 AbstractIdPSession.AddressFamily family)
        Get an address to which this session is bound.
        Parameters:
        family - the address family to inquire
        Returns:
        bound address or null
      • bindToAddress

        public void bindToAddress​(@Nonnull @NotEmpty
                                  String address)
                           throws SessionException
        Associate an address with this session.
        Parameters:
        address - the address to associate
        Throws:
        SessionException - if an error occurs binding the address to the session
      • doBindToAddress

        public void doBindToAddress​(@Nonnull @NotEmpty
                                    String address)
        Associate an address with this session.

        This manipulates only the internal state of the object. The bindToAddress(String) method must be overridden to support other persistence requirements.

        Parameters:
        address - the address to associate
      • checkTimeout

        public boolean checkTimeout()
                             throws SessionException
        Test the session's validity based on inactivity, while updating the last activity time.
        Specified by:
        checkTimeout in interface IdPSession
        Returns:
        true iff the session is still valid
        Throws:
        SessionException - if an error occurs updating the activity time
      • doRemoveAuthenticationResult

        public boolean doRemoveAuthenticationResult​(@Nonnull
                                                    AuthenticationResult result)
        Disassociate an AuthenticationResult from this IdP session.

        This manipulates only the internal state of the object. The removeAuthenticationResult(AuthenticationResult) method must be implemented to support other persistence requirements.

        Parameters:
        result - the result to disassociate
        Returns:
        true iff the given result had been associated with this IdP session and now is not
      • getSPSession

        @Nullable
        public SPSession getSPSession​(@Nonnull @NotEmpty
                                      String serviceId)
        Get the SPSession for a given service.
        Specified by:
        getSPSession in interface IdPSession
        Parameters:
        serviceId - ID of the service
        Returns:
        the session service or null if no session exists for that service, may be null
      • addSPSession

        @Nullable
        public SPSession addSPSession​(@Nonnull
                                      SPSession spSession)
                               throws SessionException
        Add a new SP session to this IdP session, replacing any existing session for the same service.
        Specified by:
        addSPSession in interface IdPSession
        Parameters:
        spSession - the SP session
        Returns:
        a previously existing SPSession replaced by the new one, if any
        Throws:
        SessionException - if an error occurs accessing the session
      • removeSPSession

        public boolean removeSPSession​(@Nonnull
                                       SPSession spSession)
                                throws SessionException
        Disassociate the given SP session from this IdP session.
        Specified by:
        removeSPSession in interface IdPSession
        Parameters:
        spSession - the SP session
        Returns:
        true iff the given SP session had been associated with this IdP session and now is not
        Throws:
        SessionException - if an error occurs accessing the SP session
      • doAddSPSession

        @Nullable
        public SPSession doAddSPSession​(@Nonnull
                                        SPSession spSession)
        Add a new SP session to this IdP session, replacing any existing session for the same service.

        This manipulates only the internal state of the object. The addSPSession(SPSession) method must be implemented to support other persistence requirements.

        Parameters:
        spSession - the SP session
        Returns:
        a previously existing SPSession replaced by the new one, if any
      • doRemoveSPSession

        public boolean doRemoveSPSession​(@Nonnull
                                         SPSession spSession)
        Disassociate the given SP session from this IdP session.

        This manipulates only the internal state of the object. The removeSPSession(SPSession) method must be implemented to support other persistence requirements.

        Parameters:
        spSession - the SP session
        Returns:
        true iff the given SP session had been associated with this IdP session and now is not
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getAddressFamily

        @Nonnull
        protected static AbstractIdPSession.AddressFamily getAddressFamily​(@Nonnull @NotEmpty
                                                                           String address)
        Returns the address family for an input address.
        Parameters:
        address - the string to check
        Returns:
        the address family