Class RateLimitedJWKSetSource<C extends SecurityContext>

  • 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
    • 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 be null.
        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.