|
58 | 58 | import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails;
|
59 | 59 | import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
|
60 | 60 | import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
|
| 61 | +import org.springframework.security.oauth2.provider.token.TokenStore; |
61 | 62 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
|
| 63 | +import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; |
| 64 | +import org.springframework.security.oauth2.provider.token.store.jwk.JwkTokenStore; |
62 | 65 | import org.springframework.social.connect.ConnectionFactoryLocator;
|
63 | 66 | import org.springframework.stereotype.Component;
|
64 | 67 | import org.springframework.web.client.RestTemplate;
|
@@ -261,6 +264,27 @@ public void jwtAccessTokenConverterIsConfiguredWhenKeyUriIsProvided() {
|
261 | 264 | assertThat(this.context.getBeansOfType(JwtAccessTokenConverter.class)).hasSize(1);
|
262 | 265 | }
|
263 | 266 |
|
| 267 | + @Test |
| 268 | + public void jwkTokenStoreShouldBeConditionalOnMissingBean() throws Exception { |
| 269 | + TestPropertyValues |
| 270 | + .of("security.oauth2.resource.jwk.key-set-uri=http://my-auth-server/token_keys") |
| 271 | + .applyTo(this.environment); |
| 272 | + this.context = new SpringApplicationBuilder(JwkTokenStoreConfiguration.class, |
| 273 | + ResourceConfiguration.class) |
| 274 | + .environment(this.environment).web(false).run(); |
| 275 | + assertThat(this.context.getBeansOfType(JwkTokenStore.class)).hasSize(1); |
| 276 | + } |
| 277 | + |
| 278 | + @Test |
| 279 | + public void jwtTokenStoreShouldBeConditionalOnMissingBean() throws Exception { |
| 280 | + TestPropertyValues |
| 281 | + .of("security.oauth2.resource.jwt.keyValue=" + PUBLIC_KEY) |
| 282 | + .applyTo(this.environment); |
| 283 | + this.context = new SpringApplicationBuilder(JwtTokenStoreConfiguration.class, ResourceConfiguration.class) |
| 284 | + .environment(this.environment).web(false).run(); |
| 285 | + assertThat(this.context.getBeansOfType(JwtTokenStore.class)).hasSize(1); |
| 286 | + } |
| 287 | + |
264 | 288 | @Configuration
|
265 | 289 | @Import({ ResourceServerTokenServicesConfiguration.class,
|
266 | 290 | ResourceServerPropertiesConfiguration.class,
|
@@ -385,6 +409,26 @@ public JwtAccessTokenConverterRestTemplateCustomizer restTemplateCustomizer() {
|
385 | 409 |
|
386 | 410 | }
|
387 | 411 |
|
| 412 | + @Configuration |
| 413 | + static class JwtTokenStoreConfiguration { |
| 414 | + |
| 415 | + @Bean |
| 416 | + public TokenStore tokenStore(JwtAccessTokenConverter jwtTokenEnhancer) { |
| 417 | + return new JwtTokenStore(jwtTokenEnhancer); |
| 418 | + } |
| 419 | + |
| 420 | + } |
| 421 | + |
| 422 | + @Configuration |
| 423 | + static class JwkTokenStoreConfiguration { |
| 424 | + |
| 425 | + @Bean |
| 426 | + public TokenStore tokenStore() { |
| 427 | + return new JwkTokenStore("http://my.key-set.uri"); |
| 428 | + } |
| 429 | + |
| 430 | + } |
| 431 | + |
388 | 432 | private static class MockRestCallCustomizer
|
389 | 433 | implements JwtAccessTokenConverterRestTemplateCustomizer {
|
390 | 434 |
|
|
0 commit comments