Class RefreshAheadCachingJWKSetSource<C extends SecurityContext>

  • All Implemented Interfaces:
    JWKSetSource<C>, java.io.Closeable, java.lang.AutoCloseable

    @ThreadSafe
    public class RefreshAheadCachingJWKSetSource<C extends SecurityContext>
    extends CachingJWKSetSource<C>
    Caching JWKSetSource that refreshes the JWK set prior to its expiration. The updates run on a separate, dedicated thread. Updates can be repeatedly scheduled, or (lazily) triggered by incoming requests for the JWK set.

    This class is intended for uninterrupted operation under high-load, to avoid a potentially large number of threads blocking when the cache expires (and must be refreshed).

    Version:
    2022-11-22
    Author:
    Thomas Rørvik Skjølberg, Vladimir Dzhuvinov
    • Constructor Detail

      • RefreshAheadCachingJWKSetSource

        public RefreshAheadCachingJWKSetSource​(JWKSetSource<C> source,
                                               long timeToLive,
                                               long cacheRefreshTimeout,
                                               long refreshAheadTime,
                                               boolean scheduled,
                                               EventListener<CachingJWKSetSource<C>,​C> eventListener)
        Creates a new refresh-ahead caching JWK set source.
        Parameters:
        source - The JWK set source to decorate. Must not be null.
        timeToLive - The time to live of the cached JWK set, in milliseconds.
        cacheRefreshTimeout - The cache refresh timeout, in milliseconds.
        refreshAheadTime - The refresh ahead time, in milliseconds.
        scheduled - true to refresh in a scheduled manner, regardless of requests.
        eventListener - The event listener, null if not specified.
      • RefreshAheadCachingJWKSetSource

        public RefreshAheadCachingJWKSetSource​(JWKSetSource<C> source,
                                               long timeToLive,
                                               long cacheRefreshTimeout,
                                               long refreshAheadTime,
                                               boolean scheduled,
                                               java.util.concurrent.ExecutorService executorService,
                                               boolean shutdownExecutorOnClose,
                                               EventListener<CachingJWKSetSource<C>,​C> eventListener)
        Creates a new refresh-ahead caching JWK set source with the specified executor service to run the updates in the background.
        Parameters:
        source - The JWK set source to decorate. Must not be null.
        timeToLive - The time to live of the cached JWK set, in milliseconds.
        cacheRefreshTimeout - The cache refresh timeout, in milliseconds.
        refreshAheadTime - The refresh ahead time, in milliseconds.
        scheduled - true to refresh in a scheduled manner, regardless of requests.
        executorService - The executor service to run the updates in the background.
        shutdownExecutorOnClose - If true the executor service will be shut down upon closing the source.
        eventListener - The event listener, null if not specified.
    • Method Detail

      • getExecutorService

        public java.util.concurrent.ExecutorService getExecutorService()
        Returns the executor service running the updates in the background.
        Returns:
        The executor service.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class JWKSetSourceWrapper<C extends SecurityContext>
        Throws:
        java.io.IOException
      • getTimeToLive

        public long getTimeToLive()
        Returns the time to live of the cached JWK set.
        Returns:
        The time to live, in milliseconds.