|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2012-2021 the original author or authors. |
|
|
|
* Copyright 2012-2022 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -17,6 +17,7 @@ |
|
|
|
package org.springframework.boot.autoconfigure.security.oauth2.resource.reactive; |
|
|
|
package org.springframework.boot.autoconfigure.security.oauth2.resource.reactive; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.time.Duration; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
@ -83,6 +84,8 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
private MockWebServer server; |
|
|
|
private MockWebServer server; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Duration TIMEOUT = Duration.ofSeconds(5); |
|
|
|
|
|
|
|
|
|
|
|
private static final String JWK_SET = "{\"keys\":[{\"kty\":\"RSA\",\"e\":\"AQAB\",\"use\":\"sig\"," |
|
|
|
private static final String JWK_SET = "{\"keys\":[{\"kty\":\"RSA\",\"e\":\"AQAB\",\"use\":\"sig\"," |
|
|
|
+ "\"kid\":\"one\",\"n\":\"oXJ8OyOv_eRnce4akdanR4KYRfnC2zLV4uYNQpcFn6oHL0dj7D6kxQmsXoYgJV8ZVDn71KGm" |
|
|
|
+ "\"kid\":\"one\",\"n\":\"oXJ8OyOv_eRnce4akdanR4KYRfnC2zLV4uYNQpcFn6oHL0dj7D6kxQmsXoYgJV8ZVDn71KGm" |
|
|
|
+ "uLvolxsDncc2UrhyMBY6DVQVgMSVYaPCTgW76iYEKGgzTEw5IBRQL9w3SRJWd3VJTZZQjkXef48Ocz06PGF3lhbz4t5UEZtd" |
|
|
|
+ "uLvolxsDncc2UrhyMBY6DVQVgMSVYaPCTgW76iYEKGgzTEw5IBRQL9w3SRJWd3VJTZZQjkXef48Ocz06PGF3lhbz4t5UEZtd" |
|
|
|
@ -148,7 +151,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests { |
|
|
|
.getBean(SupplierReactiveJwtDecoder.class); |
|
|
|
.getBean(SupplierReactiveJwtDecoder.class); |
|
|
|
Mono<ReactiveJwtDecoder> reactiveJwtDecoderSupplier = (Mono<ReactiveJwtDecoder>) ReflectionTestUtils |
|
|
|
Mono<ReactiveJwtDecoder> reactiveJwtDecoderSupplier = (Mono<ReactiveJwtDecoder>) ReflectionTestUtils |
|
|
|
.getField(supplierReactiveJwtDecoder, "jwtDecoderMono"); |
|
|
|
.getField(supplierReactiveJwtDecoder, "jwtDecoderMono"); |
|
|
|
ReactiveJwtDecoder reactiveJwtDecoder = reactiveJwtDecoderSupplier.block(); |
|
|
|
ReactiveJwtDecoder reactiveJwtDecoder = reactiveJwtDecoderSupplier.block(TIMEOUT); |
|
|
|
}); |
|
|
|
}); |
|
|
|
// The last request is to the JWK Set endpoint to look up the algorithm
|
|
|
|
// The last request is to the JWK Set endpoint to look up the algorithm
|
|
|
|
assertThat(this.server.getRequestCount()).isEqualTo(1); |
|
|
|
assertThat(this.server.getRequestCount()).isEqualTo(1); |
|
|
|
@ -171,7 +174,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests { |
|
|
|
.getBean(SupplierReactiveJwtDecoder.class); |
|
|
|
.getBean(SupplierReactiveJwtDecoder.class); |
|
|
|
Mono<ReactiveJwtDecoder> reactiveJwtDecoderSupplier = (Mono<ReactiveJwtDecoder>) ReflectionTestUtils |
|
|
|
Mono<ReactiveJwtDecoder> reactiveJwtDecoderSupplier = (Mono<ReactiveJwtDecoder>) ReflectionTestUtils |
|
|
|
.getField(supplierReactiveJwtDecoder, "jwtDecoderMono"); |
|
|
|
.getField(supplierReactiveJwtDecoder, "jwtDecoderMono"); |
|
|
|
ReactiveJwtDecoder reactiveJwtDecoder = reactiveJwtDecoderSupplier.block(); |
|
|
|
ReactiveJwtDecoder reactiveJwtDecoder = reactiveJwtDecoderSupplier.block(TIMEOUT); |
|
|
|
}); |
|
|
|
}); |
|
|
|
// The last request is to the JWK Set endpoint to look up the algorithm
|
|
|
|
// The last request is to the JWK Set endpoint to look up the algorithm
|
|
|
|
assertThat(this.server.getRequestCount()).isEqualTo(2); |
|
|
|
assertThat(this.server.getRequestCount()).isEqualTo(2); |
|
|
|
@ -194,7 +197,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests { |
|
|
|
.getBean(SupplierReactiveJwtDecoder.class); |
|
|
|
.getBean(SupplierReactiveJwtDecoder.class); |
|
|
|
Mono<ReactiveJwtDecoder> reactiveJwtDecoderSupplier = (Mono<ReactiveJwtDecoder>) ReflectionTestUtils |
|
|
|
Mono<ReactiveJwtDecoder> reactiveJwtDecoderSupplier = (Mono<ReactiveJwtDecoder>) ReflectionTestUtils |
|
|
|
.getField(supplierReactiveJwtDecoder, "jwtDecoderMono"); |
|
|
|
.getField(supplierReactiveJwtDecoder, "jwtDecoderMono"); |
|
|
|
ReactiveJwtDecoder reactiveJwtDecoder = reactiveJwtDecoderSupplier.block(); |
|
|
|
ReactiveJwtDecoder reactiveJwtDecoder = reactiveJwtDecoderSupplier.block(TIMEOUT); |
|
|
|
}); |
|
|
|
}); |
|
|
|
// The last request is to the JWK Set endpoint to look up the algorithm
|
|
|
|
// The last request is to the JWK Set endpoint to look up the algorithm
|
|
|
|
assertThat(this.server.getRequestCount()).isEqualTo(3); |
|
|
|
assertThat(this.server.getRequestCount()).isEqualTo(3); |
|
|
|
@ -395,7 +398,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests { |
|
|
|
.filter((f) -> f instanceof AuthenticationWebFilter).findFirst().orElse(null); |
|
|
|
.filter((f) -> f instanceof AuthenticationWebFilter).findFirst().orElse(null); |
|
|
|
ReactiveAuthenticationManagerResolver<?> authenticationManagerResolver = (ReactiveAuthenticationManagerResolver<?>) ReflectionTestUtils |
|
|
|
ReactiveAuthenticationManagerResolver<?> authenticationManagerResolver = (ReactiveAuthenticationManagerResolver<?>) ReflectionTestUtils |
|
|
|
.getField(webFilter, "authenticationManagerResolver"); |
|
|
|
.getField(webFilter, "authenticationManagerResolver"); |
|
|
|
Object authenticationManager = authenticationManagerResolver.resolve(null).block(); |
|
|
|
Object authenticationManager = authenticationManagerResolver.resolve(null).block(TIMEOUT); |
|
|
|
assertThat(authenticationManager).isInstanceOf(JwtReactiveAuthenticationManager.class); |
|
|
|
assertThat(authenticationManager).isInstanceOf(JwtReactiveAuthenticationManager.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -408,7 +411,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests { |
|
|
|
.filter((f) -> f instanceof AuthenticationWebFilter).findFirst().orElse(null); |
|
|
|
.filter((f) -> f instanceof AuthenticationWebFilter).findFirst().orElse(null); |
|
|
|
ReactiveAuthenticationManagerResolver<?> authenticationManagerResolver = (ReactiveAuthenticationManagerResolver<?>) ReflectionTestUtils |
|
|
|
ReactiveAuthenticationManagerResolver<?> authenticationManagerResolver = (ReactiveAuthenticationManagerResolver<?>) ReflectionTestUtils |
|
|
|
.getField(webFilter, "authenticationManagerResolver"); |
|
|
|
.getField(webFilter, "authenticationManagerResolver"); |
|
|
|
Object authenticationManager = authenticationManagerResolver.resolve(null).block(); |
|
|
|
Object authenticationManager = authenticationManagerResolver.resolve(null).block(TIMEOUT); |
|
|
|
assertThat(authenticationManager).isInstanceOf(OpaqueTokenReactiveAuthenticationManager.class); |
|
|
|
assertThat(authenticationManager).isInstanceOf(OpaqueTokenReactiveAuthenticationManager.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|