|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2021 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
55 | 55 | import com.nimbusds.jwt.proc.JWTProcessor;
|
56 | 56 | import reactor.core.publisher.Flux;
|
57 | 57 | import reactor.core.publisher.Mono;
|
| 58 | +import reactor.util.function.Tuple2; |
| 59 | +import reactor.util.function.Tuples; |
58 | 60 |
|
59 | 61 | import org.springframework.core.convert.converter.Converter;
|
60 | 62 | import org.springframework.security.oauth2.core.OAuth2Error;
|
@@ -388,15 +390,19 @@ Converter<JWT, Mono<JWTClaimsSet>> processor() {
|
388 | 390 | });
|
389 | 391 | ReactiveRemoteJWKSource source = new ReactiveRemoteJWKSource(this.jwkSetUri);
|
390 | 392 | source.setWebClient(this.webClient);
|
391 |
| - Function<JWSAlgorithm, Boolean> expectedJwsAlgorithms = getExpectedJwsAlgorithms(jwsKeySelector); |
392 |
| - Mono<ConfigurableJWTProcessor<JWKSecurityContext>> jwtProcessorMono = this.jwtProcessorCustomizer |
| 393 | + Mono<Tuple2<ConfigurableJWTProcessor<JWKSecurityContext>, Function<JWSAlgorithm, Boolean>>> jwtProcessorMono = this.jwtProcessorCustomizer |
393 | 394 | .apply(source, jwtProcessor)
|
| 395 | + .map((processor) -> Tuples.of(processor, getExpectedJwsAlgorithms(processor.getJWSKeySelector()))) |
394 | 396 | .cache((processor) -> FOREVER, (ex) -> Duration.ZERO, () -> Duration.ZERO);
|
395 | 397 | return (jwt) -> {
|
396 |
| - JWKSelector selector = createSelector(expectedJwsAlgorithms, jwt.getHeader()); |
397 |
| - return jwtProcessorMono.flatMap((processor) -> source.get(selector) |
398 |
| - .onErrorMap((ex) -> new IllegalStateException("Could not obtain the keys", ex)) |
399 |
| - .map((jwkList) -> createClaimsSet(processor, jwt, new JWKSecurityContext(jwkList)))); |
| 398 | + return jwtProcessorMono.flatMap((tuple) -> { |
| 399 | + JWTProcessor<JWKSecurityContext> processor = tuple.getT1(); |
| 400 | + Function<JWSAlgorithm, Boolean> expectedJwsAlgorithms = tuple.getT2(); |
| 401 | + JWKSelector selector = createSelector(expectedJwsAlgorithms, jwt.getHeader()); |
| 402 | + return source.get(selector) |
| 403 | + .onErrorMap((ex) -> new IllegalStateException("Could not obtain the keys", ex)) |
| 404 | + .map((jwkList) -> createClaimsSet(processor, jwt, new JWKSecurityContext(jwkList))); |
| 405 | + }); |
400 | 406 | };
|
401 | 407 | }
|
402 | 408 |
|
|
0 commit comments