public final class OidcSessionTokenCache
extends java.lang.Object
After the callback exchanges the authorisation code for tokens, the access
and ID tokens are cached here under a random session key. The frontend then
retrieves them via the /oidc/tokens endpoint using the session key
from a cookie. Each entry is one-time-use and expires after a configurable
time-to-live.
| Modifier and Type | Class and Description |
|---|---|
static class |
OidcSessionTokenCache.CachedTokens
Immutable container for cached access and ID tokens with an expiry time.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
COOKIE_SESSION_TOKEN
The cookie name used to store the session token key.
|
static int |
DEFAULT_TTL_SECONDS
Default time-to-live for cached tokens: 60 seconds.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears all entries from the cache.
|
static OidcSessionTokenCache |
getInstance()
Returns the singleton instance.
|
boolean |
remove(java.lang.String sessionKey)
Removes the cache entry for the given session key, if present.
|
OidcSessionTokenCache.CachedTokens |
retrieve(java.lang.String sessionKey)
Retrieves and removes the cached tokens for the given session key.
|
int |
size()
Returns the current number of entries in the cache (including expired).
|
java.lang.String |
store(java.lang.String accessToken,
java.lang.String idToken)
Stores the access and ID tokens under a new random session key
with the default TTL.
|
java.lang.String |
store(java.lang.String accessToken,
java.lang.String idToken,
int ttlSeconds)
Stores the access and ID tokens under a new random session key
with a custom TTL.
|
public static final int DEFAULT_TTL_SECONDS
public static final java.lang.String COOKIE_SESSION_TOKEN
@CheckReturnValue @Nonnull public static OidcSessionTokenCache getInstance()
@CheckReturnValue
@Nonnull
public java.lang.String store(@Nonnull
java.lang.String accessToken,
@Nonnull
java.lang.String idToken)
Expired entries are purged on each call to keep the cache clean.
accessToken - the access token from CognitoidToken - the ID token from Cognito@CheckReturnValue
@Nonnull
public java.lang.String store(@Nonnull
java.lang.String accessToken,
@Nonnull
java.lang.String idToken,
int ttlSeconds)
Expired entries are purged on each call to keep the cache clean.
accessToken - the access token from CognitoidToken - the ID token from CognitottlSeconds - the time-to-live in seconds (use 0 or negative for immediate expiry)@CheckReturnValue @Nullable public OidcSessionTokenCache.CachedTokens retrieve(@Nonnull java.lang.String sessionKey)
This is a one-time-use operation — the tokens are removed from the
cache after retrieval. Returns null if the key is not found
or the entry has expired.
sessionKey - the session key from the cookienull if not found or expired@CheckReturnValue public int size()
public boolean remove(@Nullable
java.lang.String sessionKey)
Used on logout to invalidate the current browser’s one-time token handoff without affecting other users’ entries.
sessionKey - the key from COOKIE_SESSION_TOKEN; null or blank is a no-optrue if an entry was removedpublic void clear()
/oidc/logout uses remove(String) for the
current session key.stSoftware Copyright © 2001-2014 stSoftware All Rights Reserved.