Package com.nimbusds.jose.jwk.source
Class RateLimitedJWKSetSource<C extends SecurityContext>
- java.lang.Object
-
- com.nimbusds.jose.jwk.source.JWKSetSourceWrapper<C>
-
- com.nimbusds.jose.jwk.source.RateLimitedJWKSetSource<C>
-
- All Implemented Interfaces:
JWKSetSource<C>
,Closeable
,AutoCloseable
@ThreadSafe public class RateLimitedJWKSetSource<C extends SecurityContext> extends JWKSetSourceWrapper<C>
JWKSetSource that limits the number of requests in a time period. Intended to guard against frequent, potentially costly, downstream calls.Two invocations per time period are allowed, so that, under normal operation, there is always one invocation left in case the keys are rotated and this results in triggering a refresh of the JWK set. The other request is (sometimes) consumed by background refreshes.
- Version:
- 2022-11-22
- Author:
- Thomas Rørvik Skjølberg, Vladimir Dzhuvinov
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RateLimitedJWKSetSource.RateLimitedEvent<C extends SecurityContext>
Rate limited event.
-
Constructor Summary
Constructors Constructor Description RateLimitedJWKSetSource(JWKSetSource<C> source, long minTimeInterval, EventListener<RateLimitedJWKSetSource<C>,C> eventListener)
Creates a new JWK set source that limits the number of requests.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JWKSet
getJWKSet(JWKSetCacheRefreshEvaluator refreshEvaluator, long currentTime, C context)
Gets the JWK set.long
getMinTimeInterval()
Returns the minimum allowed time interval between two JWK set retrievals.-
Methods inherited from class com.nimbusds.jose.jwk.source.JWKSetSourceWrapper
close, getSource
-
-
-
-
Constructor Detail
-
RateLimitedJWKSetSource
public RateLimitedJWKSetSource(JWKSetSource<C> source, long minTimeInterval, EventListener<RateLimitedJWKSetSource<C>,C> eventListener)
Creates a new JWK set source that limits the number of requests.- Parameters:
source
- The JWK set source to decorate. Must not benull
.minTimeInterval
- The minimum allowed time interval between two JWK set retrievals, in milliseconds.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.- 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.
-
getMinTimeInterval
public long getMinTimeInterval()
Returns the minimum allowed time interval between two JWK set retrievals.- Returns:
- The minimum allowed time interval between two JWK set retrievals, in milliseconds.
-
-