Class CacheSessionService

  • All Implemented Interfaces:
    LifeCycle, SessionService

    public class CacheSessionService
    extends Object
    implements SessionService, LifeCycle
    Create a CacheSessionService which is responsible to manage the cache for the SessionInfo. The cache is an AsyncCache, which loads entries asynchronously.

    By default a cached entry will expire once the duration (now - SessionInfo's attribute: 'getMaxSessionExpirationTime()') has elapsed. But it is possible to cap that duration to a maximum through the parametermaximumTimeout. In that case, the cached entry will expire once the smallest duration between the maximumTimeout and (now - SessionInfo's attribute: 'getMaxSessionExpirationTime()') has elapsed.

    • Constructor Detail

      • CacheSessionService

        public CacheSessionService​(SessionService sessionService,
                                   NotificationService notificationService,
                                   String sessionNotificationTopic,
                                   com.github.benmanes.caffeine.cache.Caffeine<Object,​Object> caffeine,
                                   Supplier<String> generator,
                                   Clock clock,
                                   Duration maximumTimeout,
                                   DisconnectionStrategy disconnectionStrategy,
                                   boolean sessionIdleRefreshEnabled)
        Creates a new CacheSessionService.
        Parameters:
        sessionService - The SessionService to execute when a SessionInfo is not found in the cache
        notificationService - The notification service used for entry eviction, can be null if none.
        sessionNotificationTopic - The topic to subscribe to receive session notifications
        caffeine - The parameters of the underlying cache
        generator - The generator to provide the cache ids
        clock - A clock providing access to the current instant, date and time using a time-zone, not null.
        maximumTimeout - The maximum time to cache a session. Can be null, and in that case the time to cache for a SessionInfo is not capped.
        disconnectionStrategy - The strategy to apply in case of notifications' disconnection.
        sessionIdleRefreshEnabled - If true, the session idle refresh service has been enabled.
        Throws:
        NullPointerException - if sessionService or caffeine or clock are null.
    • Method Detail

      • getSessionInfo

        public Promise<Optional<SessionInfo>,​SessionException> getSessionInfo​(Context context,
                                                                                    String ssoToken)
        Description copied from interface: SessionService
        Returns a promise that will be completed with an optional SessionInfo or with an SessionException in case of errors. The optional SessionInfo will be empty only when the given ssoToken is invalid or expired.
        Specified by:
        getSessionInfo in interface SessionService
        Parameters:
        context - The request context.
        ssoToken - The ssoToken used to retrieve the session information about.
        Returns:
        a promise that will be completed with SessionInfo or with an SessionException in case of errors.
      • logout

        public Promise<Void,​SessionException> logout​(Context context,
                                                           String ssoToken)
        Description copied from interface: SessionService
        Returns a promise that will be completed with a Void or with an SessionException in case of errors.
        Specified by:
        logout in interface SessionService
        Parameters:
        context - The request context.
        ssoToken - The ssoToken to logout.
        Returns:
        a promise that will be completed with a Void or with an SessionException in case of errors.
      • start

        public Promise<Void,​Exception> start()
        Description copied from interface: LifeCycle
        Starts this object.
        Specified by:
        start in interface LifeCycle
        Returns:
        The promise of a started object or an exception if it has failed.