001/*
002 * Copyright 2026 Revetware LLC.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package com.revetsec.oauth;
017
018import static java.util.Objects.requireNonNull;
019import com.google.errorprone.annotations.CheckReturnValue;
020import com.revetsec.OutboundUriPolicy;
021import com.revetsec.internal.Limits;
022import com.revetsec.internal.ObserverDispatch;
023import com.revetsec.internal.http.*;
024import com.revetsec.internal.jose.*;
025import com.revetsec.jose.*;
026import com.revetsec.json.*;
027import java.net.URI;
028import java.net.http.HttpClient;
029import java.time.*;
030import java.util.*;
031import java.util.concurrent.locks.ReentrantLock;
032import javax.annotation.concurrent.NotThreadSafe;
033import javax.annotation.concurrent.ThreadSafe;
034import org.jspecify.annotations.NonNull;
035import org.jspecify.annotations.Nullable;
036
037/**
038 * RFC9068 JWT bearer-access-token validator for exact issuer and explicitly configured audiences.
039 * Build performs no I/O. Header/signature-shape checks precede lazy discovery and JWKS; no incoming credential is retained in proof.
040 * @author <a href="https://www.revetkn.com">Mark Allen</a>
041 * @since 1.0.0
042 */
043@ThreadSafe
044public final class JwtAccessTokenValidator implements AccessTokenValidator {
045
046        private final Builder settings;
047
048        private final JoseHeaderPolicy header;
049
050        private final ReentrantLock stateLock = new ReentrantLock();
051
052        @Nullable
053        private State state;
054
055        @Nullable
056        private final ResourceServerMetadataCache<State> cache;
057
058        private JwtAccessTokenValidator(@NonNull Builder settings) {
059                this.settings = settings;
060                this.header = JoseHeaderPolicy.fromSettings(settings.maximumTokenLength, settings.allowedAlgorithms, settings.compatibility == null ? Set.of("at+jwt") : Set.of("at+jwt", "JWT"), settings.compatibility == null);
061                if (settings.jwksSource != null) {
062                        this.state = stateFor(null);
063                        this.cache = null;
064                } else {
065                        this.cache = new ResourceServerMetadataCache<>(URI.create(settings.issuer), ResourceServerMetadata.Role.JWT, HttpExchange.fromHttpClient(settings.httpClient, settings.outboundUriPolicy, settings.allowInsecureLoopback), settings.outboundUriPolicy, settings.allowInsecureLoopback, settings.requestTimeout, settings.clock, settings.observer, settings.minimumTimeToLive, settings.defaultTimeToLive, settings.maximumTimeToLive, settings.discoveryCooldown, this::stateFor, System::nanoTime, this::publish);
066                }
067        }
068
069        private @NonNull State stateFor(@Nullable ResourceServerMetadata metadata) {
070                if (this.settings.jwksSource == null && !UriChecks.isPermitted(requireNonNull(metadata).endpoint(), this.settings.outboundUriPolicy, this.settings.allowInsecureLoopback))
071                        throw OAuthValidationException.fromReason(OAuthException.Reason.METADATA_INVALID);
072                this.stateLock.lock();
073                try {
074                        State previous = this.state;
075                        JwksSource source = this.settings.jwksSource;
076                        if (source == null && previous != null && previous.endpoint != null && previous.endpoint.toString().equals(requireNonNull(metadata).endpoint().toString()))
077                                source = previous.source;
078                        if (source == null)
079                                source = RemoteJwksSource.withUri(requireNonNull(metadata).endpoint()).httpClient(this.settings.httpClient).outboundUriPolicy(this.settings.outboundUriPolicy).clock(this.settings.clock).observer(this.settings.observer).allowInsecureLoopback(this.settings.allowInsecureLoopback).acknowledgeUnpatchedRuntime(this.settings.acknowledgeUnpatchedRuntime).requestTimeout(this.settings.requestTimeout).build();
080                        Set<String> required = new HashSet<>(this.settings.requiredClaims);
081                        required.addAll(Set.of("exp", "iat", "sub"));
082                        if (this.settings.compatibility == null)
083                                required.addAll(Set.of("client_id", "jti"));
084                        JwtValidator validator = JwtValidator.withIssuer(this.settings.issuer).jwksSource(source).expectedAudiences(this.settings.expectedAudiences).allowedAlgorithms(this.settings.allowedAlgorithms).allowedTypes(this.header.getAllowedTypes()).typeRequired(this.header.isTypeRequired()).requiredClaims(required).clockSkew(this.settings.clockSkew).clock(this.settings.clock).maximumTokenLength(this.settings.maximumTokenLength).observer(this.settings.observer).build();
085                        return new State(metadata == null ? null : metadata.endpoint(), source, validator);
086                } finally {
087                        this.stateLock.unlock();
088                }
089        }
090
091        private void publish(@NonNull State ready) {
092                this.stateLock.lock();
093                try {
094                        this.state = ready;
095                } finally {
096                        this.stateLock.unlock();
097                }
098        }
099
100        private @NonNull State state(@NonNull Deadline deadline) {
101                if (this.cache != null)
102                        return this.cache.get(deadline);
103                this.stateLock.lock();
104                try {
105                        return requireNonNull(this.state);
106                } finally {
107                        this.stateLock.unlock();
108                }
109        }
110
111        private record State(@Nullable URI endpoint, @NonNull JwksSource source, @NonNull JwtValidator validator) {
112
113                @Override
114                public @NonNull String toString() {
115                        return "State{data=<redacted>}";
116                }
117        }
118
119        /**
120         * Starts a validator for one exact issuer.
121         * @param issuer expected issuer, never normalized
122         * @return builder
123         * @since 1.0.0
124         */
125        @NonNull
126        public static Builder withIssuer(@NonNull String issuer) {
127                return new Builder(issuer);
128        }
129
130        /**
131         * Warms discovery and remote signing keys using one total deadline.
132         * @since 1.0.0
133         */
134        public void warmUp() {
135                Deadline deadline = Deadline.fromNow(this.settings.totalDeadline);
136                State ready = state(deadline);
137                if (ready.source instanceof RemoteJwksSource remote)
138                        JwtValidationAccess.get().warmUp(remote, deadline::remainingNanos);
139        }
140
141 /** Shared issuer transaction path; no new deadline or public proof factory. */
142 @NonNull VerifiedAccessToken validate(@NonNull BearerToken token,@NonNull Deadline deadline) {
143  requireNonNull(token);requireNonNull(deadline);
144  checkBudget(deadline);
145                try {
146                        if (token.value().length() > this.settings.maximumTokenLength)
147                                throw AccessTokenValidationException.fromReason(AccessTokenValidationException.Reason.MALFORMED_REQUEST);
148                        PreparedJws prepared;
149                        try {
150                                prepared = JwtProcessor.prepare(token.value(), this.header);
151                        } catch (JoseFailure failure) {
152                                throw AccessTokenValidationException.fromJoseReason(failure.getReason());
153                        }
154                        boolean untyped = prepared.findType().map(t -> JoseHeaderPolicy.normalizeType(t).orElse("").equals("application/jwt")).orElse(true);
155                        if (untyped)
156                                ObserverDispatch.dispatch(this.settings.observer, o -> o.didUseCompatibilityMode(AccessTokenCompatibilityMode.UNTYPED_ACCESS_TOKENS));
157                        Jwt jwt;
158                        try {
159                                jwt = JwtValidationAccess.get().validatePrepared(state(deadline).validator, prepared, deadline::remainingNanos);
160                        } catch (JoseException failure) {
161                                throw AccessTokenValidationException.fromJoseReason(failure.getReason());
162                        }
163                        JsonObject claims = jwt.getClaims().toJsonObject();
164                        if (untyped)
165                                for (String name : Set.of("nonce", "at_hash", "c_hash", "auth_time")) if (claims.getMembers().containsKey(name))
166                                        throw AccessTokenValidationException.fromReason(AccessTokenValidationException.Reason.UNTYPED_IDENTITY_CLAIM_PRESENT);
167                        String subject = AccessTokenClaims.requiredString(claims, "sub");
168                        String client = claims.getMembers().containsKey("client_id") ? AccessTokenClaims.requiredString(claims, "client_id") : null;
169                        if (this.settings.compatibility == null) {
170                                AccessTokenClaims.requiredString(claims, "client_id");
171                                AccessTokenClaims.requiredString(claims, "jti");
172                        }
173                        Set<String> scopes = AccessTokenClaims.scopes(claims.getMembers().get(this.settings.scopeClaimName), this.settings.scopeClaimName.equals("scp"));
174                        VerifiedAccessToken result = new VerifiedAccessToken(this.settings.issuer, subject, client, scopes, jwt.getClaims().getAudiences(), jwt.getClaims().getExpiresAt().orElse(null), claims);
175   checkBudget(deadline);
176                        ObserverDispatch.dispatch(this.settings.observer, AccessTokenObserver::didValidateAccessToken);
177                        return result;
178                } catch (AccessTokenValidationException rejection) {
179                        ObserverDispatch.dispatch(this.settings.observer, o -> o.didRejectAccessToken(rejection));
180                        throw rejection;
181                }
182        }
183
184 private static void checkBudget(@NonNull Deadline deadline) {
185  if(Thread.currentThread().isInterrupted()) throw OAuthTransportException.fromReason(OAuthException.Reason.INTERRUPTED,null);
186  if(deadline.isExpired()) throw OAuthTransportException.fromReason(OAuthException.Reason.NETWORK_FAILURE,null);
187 }
188
189        /**
190         * Returns a local credential verdict; provider failures remain exceptions.
191         * @param token unverified bearer credential
192         * @return outcome
193         * @since 1.0.0
194         */
195        @Override
196        @CheckReturnValue
197        @NonNull
198        public AccessTokenValidationResult validateResult(@NonNull BearerToken token) {
199                try {
200                        return AccessTokenValidationResult.fromToken(validate(token, Deadline.fromNow(this.settings.totalDeadline)));
201                } catch (AccessTokenValidationException rejection) {
202                        return AccessTokenValidationResult.fromRejection(rejection);
203                }
204        }
205
206        /**
207         * Returns a redacted configuration description.
208         * @return description
209         * @since 1.0.0
210         */
211        @Override
212        @NonNull
213        public String toString() {
214                return "JwtAccessTokenValidator{data=<redacted>}";
215        }
216
217        /**
218         * Configures an immutable resource validator. Nullable setters restore defaults; missing audiences fail at build.
219         * @author <a href="https://www.revetkn.com">Mark Allen</a>
220         * @since 1.0.0
221         */
222        @NotThreadSafe
223        @CheckReturnValue
224        public static final class Builder {
225
226                private final String issuer;
227
228                @Nullable
229                private Set<@NonNull String> expectedAudiences;
230
231                private Set<@NonNull JwsAlgorithm> allowedAlgorithms = Set.of(JwsAlgorithm.RS256);
232
233                private Set<@NonNull String> requiredClaims = Set.of();
234
235                private String scopeClaimName = "scope";
236
237                @Nullable
238                private AccessTokenCompatibilityMode compatibility;
239
240                private int maximumTokenLength = Limits.BEARER_CREDENTIAL_SIZE.getDefaultIntValue();
241
242                private Duration clockSkew = Limits.JOSE_CLOCK_SKEW.getDefaultDuration();
243
244                private Clock clock = Clock.systemUTC();
245
246                @Nullable
247                private JwksSource jwksSource;
248
249                @Nullable
250                private HttpClient httpClient;
251
252                private OutboundUriPolicy outboundUriPolicy = OutboundUriPolicy.defaultInstance();
253
254                private Duration requestTimeout = Limits.REQUEST_TIMEOUT.getDefaultDuration();
255
256                private Duration totalDeadline = Limits.TOTAL_DEADLINE.getDefaultDuration();
257
258                private Duration minimumTimeToLive = Limits.DISCOVERY_MINIMUM_TIME_TO_LIVE.getDefaultDuration();
259
260                private Duration defaultTimeToLive = Limits.DISCOVERY_DEFAULT_TIME_TO_LIVE.getDefaultDuration();
261
262                private Duration maximumTimeToLive = Limits.DISCOVERY_MAXIMUM_TIME_TO_LIVE.getDefaultDuration();
263
264                private Duration discoveryCooldown = Limits.DISCOVERY_COOLDOWN.getDefaultDuration();
265
266                private boolean allowInsecureLoopback;
267
268                private boolean acknowledgeUnpatchedRuntime;
269
270                private AccessTokenObserver observer = AccessTokenObserver.disabledInstance();
271
272                private Builder(@NonNull String issuer) {
273                        this.issuer = requireNonNull(issuer);
274                        if (issuer.isEmpty())
275                                throw new IllegalArgumentException("An issuer is required.");
276                }
277
278                private Builder(@NonNull Builder original) {
279                        this.issuer = original.issuer;
280                        this.expectedAudiences = original.expectedAudiences;
281                        this.allowedAlgorithms = original.allowedAlgorithms;
282                        this.requiredClaims = original.requiredClaims;
283                        this.scopeClaimName = original.scopeClaimName;
284                        this.compatibility = original.compatibility;
285                        this.maximumTokenLength = original.maximumTokenLength;
286                        this.clockSkew = original.clockSkew;
287                        this.clock = original.clock;
288                        this.jwksSource = original.jwksSource;
289                        this.httpClient = original.httpClient;
290                        this.outboundUriPolicy = original.outboundUriPolicy;
291                        this.requestTimeout = original.requestTimeout;
292                        this.totalDeadline = original.totalDeadline;
293                        this.minimumTimeToLive = original.minimumTimeToLive;
294                        this.defaultTimeToLive = original.defaultTimeToLive;
295                        this.maximumTimeToLive = original.maximumTimeToLive;
296                        this.discoveryCooldown = original.discoveryCooldown;
297                        this.allowInsecureLoopback = original.allowInsecureLoopback;
298                        this.acknowledgeUnpatchedRuntime = original.acknowledgeUnpatchedRuntime;
299                        this.observer = original.observer;
300                }
301
302                /**
303                 * Sets required exact audiences.
304                 * @param value setting, or null to restore its default or absence
305                 * @return this builder
306                 * @since 1.0.0
307                 */
308                @NonNull
309                public Builder expectedAudiences(@Nullable Set<@NonNull String> value) {
310                        this.expectedAudiences = value == null ? null : AccessTokenClaims.names(value, true);
311                        return this;
312                }
313
314                /**
315                 * Sets public-key algorithm set.
316                 * @param value setting, or null to restore its default or absence
317                 * @return this builder
318                 * @since 1.0.0
319                 */
320                @NonNull
321                public Builder allowedAlgorithms(@Nullable Set<@NonNull JwsAlgorithm> value) {
322                        this.allowedAlgorithms = value == null ? Set.of(JwsAlgorithm.RS256) : Set.copyOf(value);
323                        return this;
324                }
325
326                /**
327                 * Sets additional required claims.
328                 * @param value setting, or null to restore its default or absence
329                 * @return this builder
330                 * @since 1.0.0
331                 */
332                @NonNull
333                public Builder requiredClaims(@Nullable Set<@NonNull String> value) {
334                        this.requiredClaims = value == null ? Set.of() : AccessTokenClaims.names(value, false);
335                        return this;
336                }
337
338                /**
339                 * Sets scope claim name.
340                 * @param value setting, or null to restore its default or absence
341                 * @return this builder
342                 * @since 1.0.0
343                 */
344                @NonNull
345                public Builder scopeClaimName(@Nullable String value) {
346                        if (value != null && !Set.of("scope", "scp").contains(value))
347                                throw new IllegalArgumentException("The scope claim must be scope or scp.");
348                        this.scopeClaimName = value == null ? "scope" : value;
349                        return this;
350                }
351
352                /**
353                 * Sets explicit compatibility mode.
354                 * @param value setting, or null to restore its default or absence
355                 * @return this builder
356                 * @since 1.0.0
357                 */
358                @NonNull
359                public Builder compatibility(@Nullable AccessTokenCompatibilityMode value) {
360                        this.compatibility = value;
361                        return this;
362                }
363
364                /**
365                 * Sets credential cap.
366                 * @param value setting, or null to restore its default or absence
367                 * @return this builder
368                 * @since 1.0.0
369                 */
370                @NonNull
371                public Builder maximumTokenLength(@Nullable Integer value) {
372                        this.maximumTokenLength = value == null ? Limits.BEARER_CREDENTIAL_SIZE.getDefaultIntValue() : Limits.BEARER_CREDENTIAL_SIZE.require(value);
373                        return this;
374                }
375
376                /**
377                 * Sets clock skew.
378                 * @param value setting, or null to restore its default or absence
379                 * @return this builder
380                 * @since 1.0.0
381                 */
382                @NonNull
383                public Builder clockSkew(@Nullable Duration value) {
384                        this.clockSkew = value == null ? Limits.JOSE_CLOCK_SKEW.getDefaultDuration() : Limits.JOSE_CLOCK_SKEW.require(value);
385                        return this;
386                }
387
388                /**
389                 * Sets clock.
390                 * @param value setting, or null to restore its default or absence
391                 * @return this builder
392                 * @since 1.0.0
393                 */
394                @NonNull
395                public Builder clock(@Nullable Clock value) {
396                        this.clock = value == null ? Clock.systemUTC() : value;
397                        return this;
398                }
399
400                /**
401                 * Sets key source that bypasses discovery.
402                 * @param value setting, or null to restore its default or absence
403                 * @return this builder
404                 * @since 1.0.0
405                 */
406                @NonNull
407                public Builder jwksSource(@Nullable JwksSource value) {
408                        this.jwksSource = value;
409                        return this;
410                }
411
412                /**
413                 * Sets transport. An injected client must use Redirect.NEVER and have no Authenticator or CookieHandler;
414                 * build rejects noncompliance without sending a request. The application owns injected TLS/proxy
415                 * configuration and network egress beyond the URI policy.
416                 * @param value injected client meeting these restrictions, or null for the lazy default
417                 * @return this builder
418                 * @since 1.0.0
419                 */
420                @NonNull
421                public Builder httpClient(@Nullable HttpClient value) {
422                        this.httpClient = value;
423                        return this;
424                }
425
426                /**
427                 * Sets outbound URI policy.
428                 * @param value setting, or null to restore its default or absence
429                 * @return this builder
430                 * @since 1.0.0
431                 */
432                @NonNull
433                public Builder outboundUriPolicy(@Nullable OutboundUriPolicy value) {
434                        this.outboundUriPolicy = value == null ? OutboundUriPolicy.defaultInstance() : value;
435                        return this;
436                }
437
438                /**
439                 * Sets request timeout.
440                 * @param value setting, or null to restore its default or absence
441                 * @return this builder
442                 * @since 1.0.0
443                 */
444                @NonNull
445                public Builder requestTimeout(@Nullable Duration value) {
446                        this.requestTimeout = value == null ? Limits.REQUEST_TIMEOUT.getDefaultDuration() : Limits.REQUEST_TIMEOUT.require(value);
447                        return this;
448                }
449
450                /**
451                 * Sets shared deadline.
452                 * @param value setting, or null to restore its default or absence
453                 * @return this builder
454                 * @since 1.0.0
455                 */
456                @NonNull
457                public Builder totalDeadline(@Nullable Duration value) {
458                        this.totalDeadline = value == null ? Limits.TOTAL_DEADLINE.getDefaultDuration() : Limits.TOTAL_DEADLINE.require(value);
459                        return this;
460                }
461
462                /**
463                 * Sets minimum metadata TTL.
464                 * @param value setting, or null to restore its default or absence
465                 * @return this builder
466                 * @since 1.0.0
467                 */
468                @NonNull
469                public Builder minimumTimeToLive(@Nullable Duration value) {
470                        this.minimumTimeToLive = value == null ? Limits.DISCOVERY_MINIMUM_TIME_TO_LIVE.getDefaultDuration() : Limits.DISCOVERY_MINIMUM_TIME_TO_LIVE.require(value);
471                        return this;
472                }
473
474                /**
475                 * Sets fallback metadata TTL.
476                 * @param value setting, or null to restore its default or absence
477                 * @return this builder
478                 * @since 1.0.0
479                 */
480                @NonNull
481                public Builder defaultTimeToLive(@Nullable Duration value) {
482                        this.defaultTimeToLive = value == null ? Limits.DISCOVERY_DEFAULT_TIME_TO_LIVE.getDefaultDuration() : Limits.DISCOVERY_DEFAULT_TIME_TO_LIVE.require(value);
483                        return this;
484                }
485
486                /**
487                 * Sets maximum metadata TTL.
488                 * @param value setting, or null to restore its default or absence
489                 * @return this builder
490                 * @since 1.0.0
491                 */
492                @NonNull
493                public Builder maximumTimeToLive(@Nullable Duration value) {
494                        this.maximumTimeToLive = value == null ? Limits.DISCOVERY_MAXIMUM_TIME_TO_LIVE.getDefaultDuration() : Limits.DISCOVERY_MAXIMUM_TIME_TO_LIVE.require(value);
495                        return this;
496                }
497
498                /**
499                 * Sets discovery attempt window.
500                 * @param value setting, or null to restore its default or absence
501                 * @return this builder
502                 * @since 1.0.0
503                 */
504                @NonNull
505                public Builder discoveryCooldown(@Nullable Duration value) {
506                        this.discoveryCooldown = value == null ? Limits.DISCOVERY_COOLDOWN.getDefaultDuration() : Limits.DISCOVERY_COOLDOWN.require(value);
507                        return this;
508                }
509
510                /**
511                 * Sets explicit local HTTP opt-in.
512                 * @param value setting, or null to restore its default or absence
513                 * @return this builder
514                 * @since 1.0.0
515                 */
516                @NonNull
517                public Builder allowInsecureLoopback(@Nullable Boolean value) {
518                        this.allowInsecureLoopback = Boolean.TRUE.equals(value);
519                        return this;
520                }
521
522                /**
523                 * Sets explicit unpatched network-runtime acknowledgement.
524                 * @param value setting, or null to restore its default or absence
525                 * @return this builder
526                 * @since 1.0.0
527                 */
528                @NonNull
529                public Builder acknowledgeUnpatchedRuntime(@Nullable Boolean value) {
530                        this.acknowledgeUnpatchedRuntime = Boolean.TRUE.equals(value);
531                        return this;
532                }
533
534                /**
535                 * Sets observer.
536                 * @param value setting, or null to restore its default or absence
537                 * @return this builder
538                 * @since 1.0.0
539                 */
540                @NonNull
541                public Builder observer(@Nullable AccessTokenObserver value) {
542                        this.observer = value == null ? AccessTokenObserver.disabledInstance() : value;
543                        return this;
544                }
545
546                /**
547                 * Builds without I/O or new threads.
548                 * @return validator
549                 * @since 1.0.0
550                 */
551                @NonNull
552                public JwtAccessTokenValidator build() {
553                        return build(Runtime.version());
554                }
555
556                @NonNull JwtAccessTokenValidator build(Runtime.@NonNull Version runtime) {
557                        if (this.expectedAudiences == null)
558                                throw new IllegalStateException("Expected audiences are required.");
559                        if (this.allowedAlgorithms.isEmpty() || this.allowedAlgorithms.stream().anyMatch(a -> Algorithms.familyOf(a) == Algorithms.Family.HMAC))
560                                throw new IllegalArgumentException("At least one public-key algorithm is required.");
561                        if (this.compatibility != null && this.requiredClaims.stream().noneMatch(n -> !Set.of("iss", "aud", "sub", "client_id", "jti", "exp", "iat", "nbf").contains(n)))
562                                throw new IllegalArgumentException("Untyped access tokens require an additional required claim.");
563                        Limits.requireRequestTimeoutWithinTotalDeadline(this.requestTimeout, this.totalDeadline);
564                        Limits.requireDiscoveryTimeToLiveOrder(this.minimumTimeToLive, this.defaultTimeToLive, this.maximumTimeToLive, this.discoveryCooldown);
565                        if (!(this.jwksSource instanceof StaticJwksSource)) {
566                                RuntimeFloor.require(runtime, this.acknowledgeUnpatchedRuntime);
567                                if (this.jwksSource == null) {
568                                        URI issuerUri = URI.create(this.issuer);
569                                        if (issuerUri.getRawQuery() != null || issuerUri.getRawFragment() != null)
570                                                throw new IllegalArgumentException("Issuer query/fragment is invalid.");
571                                        UriChecks.requirePermitted(issuerUri, this.outboundUriPolicy, this.allowInsecureLoopback);
572                                }
573                        }
574                        JwtAccessTokenValidator validator = new JwtAccessTokenValidator(new Builder(this));
575                        AccessTokenCompatibilityMode mode = this.compatibility;
576                        if (mode != null)
577                                ObserverDispatch.dispatch(this.observer, o -> o.didEnableCompatibilityMode(mode));
578                        if (!(this.jwksSource instanceof StaticJwksSource) && RuntimeFloor.isBelowFloor(runtime) && this.acknowledgeUnpatchedRuntime)
579                                ObserverDispatch.dispatch(this.observer, o -> o.didUseUnpatchedRuntime(runtime.toString()));
580                        return validator;
581                }
582        }
583}