public class CacheSessionService extends Object implements SessionService, LifeCycle
SessionInfo
.
The cache is an AsyncLoadingCache
, 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.
Modifier and Type | Class and Description |
---|---|
static class |
CacheSessionService.DisconnectionStrategy
The different behaviors that can be applied in case of notifications disconnections.
|
Constructor and Description |
---|
CacheSessionService(SessionService sessionService,
NotificationService notificationService,
com.github.benmanes.caffeine.cache.Caffeine<Object,Object> caffeine,
Supplier<String> generator,
Clock clock,
Duration maximumTimeout,
CacheSessionService.DisconnectionStrategy disconnectionStrategy)
Creates a new CacheSessionService.
|
Modifier and Type | Method and Description |
---|---|
Promise<Optional<SessionInfo>,SessionException> |
getSessionInfo(Context context,
String ssoToken)
Returns a promise that will be completed with an optional
SessionInfo or with an SessionException
in case of errors. |
Promise<Void,SessionException> |
logout(Context context,
String ssoToken)
Returns a promise that will be completed with a
Void or with an SessionException in case
of errors. |
void |
start()
Starts this object.
|
void |
stop()
Stops this object.
|
public CacheSessionService(SessionService sessionService, NotificationService notificationService, com.github.benmanes.caffeine.cache.Caffeine<Object,Object> caffeine, Supplier<String> generator, Clock clock, Duration maximumTimeout, CacheSessionService.DisconnectionStrategy disconnectionStrategy)
sessionService
- The SessionService
to execute when a SessionInfo
is not found in the cachenotificationService
- The notification service used for entry eviction, can be null
if none.caffeine
- The parameters of the underlying cachegenerator
- The generator to provide the cache idsclock
- 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.NullPointerException
- if sessionService or caffeine or clock are null
.public Promise<Optional<SessionInfo>,SessionException> getSessionInfo(Context context, String ssoToken)
SessionService
SessionInfo
or with an SessionException
in case of errors. The optional SessionInfo
will be empty only when the given ssoToken
is
invalid or expired.getSessionInfo
in interface SessionService
context
- The request context.ssoToken
- The ssoToken used to retrieve the session information about.SessionInfo
or with an SessionException
in case
of errors.public Promise<Void,SessionException> logout(Context context, String ssoToken)
SessionService
Void
or with an SessionException
in case
of errors.logout
in interface SessionService
context
- The request context.ssoToken
- The ssoToken to logout.Void
or with an SessionException
in case
of errors.public void start()
LifeCycle
Copyright 2011-2017 ForgeRock AS.