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 ClassesModifier and TypeClassDescriptionstatic class
JWK set refresh not scheduled event.static class
New JWK set refresh scheduled event.static class
Scheduled JWK set cache refresh completed event.static class
Scheduled JWK refresh failed event.static class
Scheduled JWK set cache refresh initiated event.static class
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
ConstructorsConstructorDescriptionRefreshAheadCachingJWKSetSource
(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
Modifier and TypeMethodDescriptionvoid
close()
Returns the executor service running the updates in the background.getJWKSet
(JWKSetCacheRefreshEvaluator refreshEvaluator, long currentTime, C context) Gets the JWK set.long
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 Details
-
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 Details
-
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
Returns the executor service running the updates in the background.- Returns:
- The executor service.
-
close
- 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.
-