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 class
RefreshAheadCachingJWKSetSource.RefreshNotScheduledEvent<C extends SecurityContext>
JWK set refresh not scheduled event.static class
RefreshAheadCachingJWKSetSource.RefreshScheduledEvent<C extends SecurityContext>
New JWK set refresh scheduled event.static class
RefreshAheadCachingJWKSetSource.ScheduledRefreshCompletedEvent<C extends SecurityContext>
Scheduled JWK set cache refresh completed event.static class
RefreshAheadCachingJWKSetSource.ScheduledRefreshFailed<C extends SecurityContext>
Scheduled JWK refresh failed event.static class
RefreshAheadCachingJWKSetSource.ScheduledRefreshInitiatedEvent<C extends SecurityContext>
Scheduled JWK set cache refresh initiated event.static class
RefreshAheadCachingJWKSetSource.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 void
close()
ExecutorService
getExecutorService()
Returns the executor service running the updates in the background.JWKSet
getJWKSet(JWKSetCacheRefreshEvaluator refreshEvaluator, long currentTime, C context)
Gets the JWK set.long
getTimeToLive()
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
-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, 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
-true
to refresh in a scheduled manner, regardless of requests.executorService
- The executor service to run the updates in the background.shutdownExecutorOnClose
- Iftrue
the executor service will be shut down upon closing the source.eventListener
- The event listener,null
if not specified.
-
-
Method Detail
-
getJWKSet
public JWKSet getJWKSet(JWKSetCacheRefreshEvaluator refreshEvaluator, long currentTime, C context) throws KeySourceException
Description copied from interface:JWKSetSource
Gets the JWK set.- Specified by:
getJWKSet
in interfaceJWKSetSource<C extends SecurityContext>
- Overrides:
getJWKSet
in 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,null
if 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in 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.
-
-