Package com.nimbusds.jose.jwk.source
Class RefreshAheadCachingJWKSetSource<C extends SecurityContext>
- java.lang.Object
-
- com.nimbusds.jose.jwk.source.JWKSetSourceWrapper<C>
-
- com.nimbusds.jose.jwk.source.CachingJWKSetSource<C>
-
- com.nimbusds.jose.jwk.source.RefreshAheadCachingJWKSetSource<C>
-
- All Implemented Interfaces:
JWKSetSource<C>,Closeable,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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRefreshAheadCachingJWKSetSource.RefreshNotScheduledEvent<C extends SecurityContext>JWK set refresh not scheduled event.static classRefreshAheadCachingJWKSetSource.RefreshScheduledEvent<C extends SecurityContext>New JWK set refresh scheduled event.static classRefreshAheadCachingJWKSetSource.ScheduledRefreshCompletedEvent<C extends SecurityContext>Scheduled JWK set cache refresh completed event.static classRefreshAheadCachingJWKSetSource.ScheduledRefreshFailed<C extends SecurityContext>Scheduled JWK refresh failed event.static classRefreshAheadCachingJWKSetSource.ScheduledRefreshInitiatedEvent<C extends SecurityContext>Scheduled JWK set cache refresh initiated event.static classRefreshAheadCachingJWKSetSource.UnableToRefreshAheadOfExpirationEvent<C extends SecurityContext>Unable to refresh the JWK set cache ahead of expiration event.-
Nested classes/interfaces inherited from class com.nimbusds.jose.jwk.source.CachingJWKSetSource
CachingJWKSetSource.RefreshCompletedEvent<C extends SecurityContext>, CachingJWKSetSource.RefreshInitiatedEvent<C extends SecurityContext>, CachingJWKSetSource.RefreshTimedOutEvent<C extends SecurityContext>, CachingJWKSetSource.UnableToRefreshEvent<C extends SecurityContext>, CachingJWKSetSource.WaitingForRefreshEvent<C extends SecurityContext>
-
-
Constructor Summary
Constructors Constructor Description 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.RefreshAheadCachingJWKSetSource(JWKSetSource<C> source, long timeToLive, long cacheRefreshTimeout, long refreshAheadTime, boolean scheduled, 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()ExecutorServicegetExecutorService()Returns the executor service running the updates in the background.JWKSetgetJWKSet(JWKSetCacheRefreshEvaluator refreshEvaluator, long currentTime, C context)Gets the JWK set.longgetTimeToLive()Returns the time to live of the cached JWK set.-
Methods inherited from class com.nimbusds.jose.jwk.source.CachingJWKSetSource
getCacheRefreshTimeout
-
Methods inherited from class com.nimbusds.jose.jwk.source.JWKSetSourceWrapper
getSource
-
-
-
-
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 benull.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-trueto refresh in a scheduled manner, regardless of requests.eventListener- The event listener,nullif not specified.
-
RefreshAheadCachingJWKSetSource
public RefreshAheadCachingJWKSetSource(JWKSetSource<C> source, long timeToLive, long cacheRefreshTimeout, long refreshAheadTime, boolean scheduled, 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 benull.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-trueto refresh in a scheduled manner, regardless of requests.executorService- The executor service to run the updates in the background.shutdownExecutorOnClose- Iftruethe executor service will be shut down upon closing the source.eventListener- The event listener,nullif not specified.
-
-
Method Detail
-
getJWKSet
public JWKSet getJWKSet(JWKSetCacheRefreshEvaluator refreshEvaluator, long currentTime, C context) throws KeySourceException
Description copied from interface:JWKSetSourceGets the JWK set.- Specified by:
getJWKSetin interfaceJWKSetSource<C extends SecurityContext>- Overrides:
getJWKSetin classCachingJWKSetSource<C extends SecurityContext>- Parameters:
refreshEvaluator- Controls whether refresh of the JWK set cache (if utilised by the source) is required.currentTime- The current time, in milliseconds since the Unix epoch.context- Optional context,nullif not required.- Returns:
- The JWK set.
- Throws:
KeySourceException- If JWK set retrieval failed.
-
getExecutorService
public ExecutorService getExecutorService()
Returns the executor service running the updates in the background.- Returns:
- The executor service.
-
close
public void close() throws IOException
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classJWKSetSourceWrapper<C extends SecurityContext>- Throws:
IOException
-
getTimeToLive
public long getTimeToLive()
Returns the time to live of the cached JWK set.- Returns:
- The time to live, in milliseconds.
-
-