|
54 | 54 | import org.springframework.security.web.FilterChainProxy;
|
55 | 55 | import org.springframework.security.web.SecurityFilterChain;
|
56 | 56 | import org.springframework.test.util.ReflectionTestUtils;
|
| 57 | +import org.springframework.web.client.RestTemplate; |
57 | 58 |
|
58 | 59 | import static org.assertj.core.api.Assertions.assertThat;
|
59 | 60 | import static org.mockito.Mockito.mock;
|
@@ -90,6 +91,24 @@ void autoConfigurationShouldConfigureResourceServer() {
|
90 | 91 | });
|
91 | 92 | }
|
92 | 93 |
|
| 94 | + @Test |
| 95 | + void autoConfigurationShouldUseApplicationsRestTemplate() { |
| 96 | + this.contextRunner |
| 97 | + .withPropertyValues("spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://jwk-set-uri.com") |
| 98 | + .withUserConfiguration(RestTemplateConfig.class) |
| 99 | + .run((context) -> { |
| 100 | + assertThat(context).hasSingleBean(JwtDecoder.class); |
| 101 | + JwtDecoder jwtDecoder = context.getBean(JwtDecoder.class); |
| 102 | + Object processor = ReflectionTestUtils.getField(jwtDecoder, "jwtProcessor"); |
| 103 | + Object keySelector = ReflectionTestUtils.getField(processor, "jwsKeySelector"); |
| 104 | + Object jwkSource = ReflectionTestUtils.getField(keySelector, "jwkSource"); |
| 105 | + Object jwkSetRetriever = ReflectionTestUtils.getField(jwkSource, "jwkSetRetriever"); |
| 106 | + Object restOperations = ReflectionTestUtils.getField(jwkSetRetriever, "restOperations"); |
| 107 | + assertThat(restOperations).isNotNull(); |
| 108 | + assertThat(restOperations).isEqualTo(RestTemplateConfig.configuredRestTemplate); |
| 109 | + }); |
| 110 | + } |
| 111 | + |
93 | 112 | @Test
|
94 | 113 | void autoConfigurationShouldMatchDefaultJwsAlgorithm() {
|
95 | 114 | this.contextRunner
|
@@ -424,6 +443,19 @@ JwtDecoder decoder() {
|
424 | 443 |
|
425 | 444 | }
|
426 | 445 |
|
| 446 | + @Configuration(proxyBeanMethods = false) |
| 447 | + @EnableWebSecurity |
| 448 | + static class RestTemplateConfig { |
| 449 | + |
| 450 | + private static RestTemplate configuredRestTemplate = new RestTemplate(); |
| 451 | + |
| 452 | + @Bean |
| 453 | + RestTemplate restTemplate() { |
| 454 | + return configuredRestTemplate; |
| 455 | + } |
| 456 | + |
| 457 | + } |
| 458 | + |
427 | 459 | @Configuration(proxyBeanMethods = false)
|
428 | 460 | @EnableWebSecurity
|
429 | 461 | static class OpaqueTokenIntrospectorConfig {
|
|
0 commit comments