001package com.nimbusds.jose.jwk.source;
002
003import com.nimbusds.jose.jwk.JWKSet;
004
005
006/**
007 * Evaluates whether a JWK set cache requires refreshing.
008 *
009 * @author Thomas Rørvik Skjølberg
010 * @author Vladimir Dzhuvinov
011 * @version 2022-11-23
012 */
013public abstract class JWKSetCacheRefreshEvaluator {
014        
015        
016        private static final ForceRefreshJWKSetCacheEvaluator FORCE_REFRESH = new ForceRefreshJWKSetCacheEvaluator();
017        
018        private static final NoRefreshJWKSetCacheEvaluator NO_REFRESH = new NoRefreshJWKSetCacheEvaluator();
019        
020        
021        /**
022         * Returns a force-refresh evaluator.
023         *
024         * @return The force-refresh evaluator.
025         */
026        public static JWKSetCacheRefreshEvaluator forceRefresh() {
027                return FORCE_REFRESH;
028        }
029        
030        
031        /**
032         * Returns a no-refresh evaluator.
033         *
034         * @return The no-refresh evaluator.
035         */
036        public static JWKSetCacheRefreshEvaluator noRefresh() {
037                return NO_REFRESH;
038        }
039        
040        
041        /**
042         * Returns a reference comparison evaluator for the specified JWK set.
043         *
044         * @param jwtSet The JWK set.
045         *
046         * @return The reference comparison evaluator.
047         */
048        public static JWKSetCacheRefreshEvaluator referenceComparison(final JWKSet jwtSet) {
049                return new ReferenceComparisonRefreshJWKSetEvaluator(jwtSet);
050        }
051        
052        
053        /**
054         * Returns {@code true} if refresh of the JWK set is required.
055         *
056         * @param jwkSet The JWK set. Must not be {@code null}.
057         *
058         * @return {@code true} if refresh is required, {@code false} if not.
059         */
060        public abstract boolean requiresRefresh(final JWKSet jwkSet);
061}