Class CachedJwkSet
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.keys.CachedJwkSet
A JSON Web Key set loaded lazily and kept in memory for a short time, so that verifying or signing a token does not
read the database every time. A rotation calls
refresh() so the next read sees the new keys at once;
otherwise the set is reloaded when it is older than the time to live.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate com.nimbusds.jose.jwk.JWKSetThe cached set, ornullwhen none is loaded.private final ClockSource of the current time.private InstantInstant at which the cached set was loaded.private final Supplier<com.nimbusds.jose.jwk.JWKSet> Loads the set.private final DurationHow long a loaded set is kept. -
Constructor Summary
ConstructorsConstructorDescriptionCachedJwkSet(Supplier<com.nimbusds.jose.jwk.JWKSet> loader, Duration ttl, Clock clock) Creates an empty cache. -
Method Summary
-
Field Details
-
loader
Loads the set. -
ttl
How long a loaded set is kept. -
clock
Source of the current time. -
cached
private com.nimbusds.jose.jwk.JWKSet cachedThe cached set, ornullwhen none is loaded. -
loadedAt
Instant at which the cached set was loaded.
-
-
Constructor Details
-
CachedJwkSet
Creates an empty cache.- Parameters:
loader- loads the set.ttl- how long a loaded set is kept.clock- source of the current time.
-
-
Method Details
-
get
public com.nimbusds.jose.jwk.JWKSet get()Gets the set, loading it when none is cached or the cached one has expired.- Returns:
- the set.
-
refresh
public void refresh()Drops the cached set, so the next read loads it again. Called after the keys rotate.
-