java.lang.Object
com.irurueta.authserver.authorization.infrastructure.keys.CachedJwkSet

public class CachedJwkSet extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private com.nimbusds.jose.jwk.JWKSet
    The cached set, or null when none is loaded.
    private final Clock
    Source of the current time.
    private Instant
    Instant at which the cached set was loaded.
    private final Supplier<com.nimbusds.jose.jwk.JWKSet>
    Loads the set.
    private final Duration
    How long a loaded set is kept.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CachedJwkSet(Supplier<com.nimbusds.jose.jwk.JWKSet> loader, Duration ttl, Clock clock)
    Creates an empty cache.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.nimbusds.jose.jwk.JWKSet
    get()
    Gets the set, loading it when none is cached or the cached one has expired.
    void
    Drops the cached set, so the next read loads it again.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • loader

      private final Supplier<com.nimbusds.jose.jwk.JWKSet> loader
      Loads the set.
    • ttl

      private final Duration ttl
      How long a loaded set is kept.
    • clock

      private final Clock clock
      Source of the current time.
    • cached

      private com.nimbusds.jose.jwk.JWKSet cached
      The cached set, or null when none is loaded.
    • loadedAt

      private Instant loadedAt
      Instant at which the cached set was loaded.
  • Constructor Details

    • CachedJwkSet

      public CachedJwkSet(Supplier<com.nimbusds.jose.jwk.JWKSet> loader, Duration ttl, Clock clock)
      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.