Interface TokenCache
- All Known Implementing Classes:
BoundedLruTokenCache
public interface TokenCache
SPI for caching the result of an OAuth introspection or token-acquisition call.
Two value shapes are supported via dedicated entry types: validator-side caches store
CachedPrincipal (used by OAuthIntrospectionValidator); flow-side caches store
OAuthToken. Implementations are not required to support both surfaces — a Redis-backed
impl can serialize either via JSON, an in-memory impl can hold both. The default impl
BoundedLruTokenCache supports both.
Implementations must be thread-safe.
- Since:
- 10.0.0
-
Method Summary
Modifier and TypeMethodDescriptiongetPrincipal(String key) Retrieves a non-expired principal entry.Retrieves a non-expired token entry.voidinvalidate(String key) Removes the entry under the supplied key.voidputPrincipal(String key, Principal principal, Duration ttl) Stores or replaces a principal entry.voidputToken(String key, OAuthToken token) Stores or replaces a token entry.intsize()Returns the current entry count.
-
Method Details
-
putPrincipal
Stores or replaces a principal entry.- Parameters:
key- The cache key (typically the opaque token string). Nevernull.principal- The principal to cache. Nevernull.ttl- The maximum cache lifetime relative to "now". Must be positive.
-
getPrincipal
Retrieves a non-expired principal entry.- Parameters:
key- The cache key.- Returns:
- The cached principal, or
Optional.empty()if absent or expired.
-
putToken
Stores or replaces a token entry.- Parameters:
key- The cache key (typically a stable key derived from the flow parameters).token- The token to cache. Nevernull.
-
getToken
Retrieves a non-expired token entry.- Parameters:
key- The cache key.now- The reference instant for expiry comparison.skew- Skew tolerance subtracted from the entry's expiry. Must be non-negative.- Returns:
- The cached token, or
Optional.empty()if absent or expired.
-
invalidate
Removes the entry under the supplied key. No-op if absent.- Parameters:
key- The cache key.
-
size
int size()Returns the current entry count. Primarily for tests and metrics.- Returns:
- The entry count.
-