|
57 | 57 | import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails;
|
58 | 58 | import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
|
59 | 59 | import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
|
| 60 | +import org.springframework.security.oauth2.provider.token.TokenStore; |
60 | 61 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
|
| 62 | +import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; |
| 63 | +import org.springframework.security.oauth2.provider.token.store.jwk.JwkTokenStore; |
61 | 64 | import org.springframework.social.connect.ConnectionFactoryLocator;
|
62 | 65 | import org.springframework.stereotype.Component;
|
63 | 66 | import org.springframework.web.client.RestTemplate;
|
@@ -256,6 +259,25 @@ public void jwtAccessTokenConverterIsConfiguredWhenKeyUriIsProvided() {
|
256 | 259 | assertThat(this.context.getBeansOfType(JwtAccessTokenConverter.class)).hasSize(1);
|
257 | 260 | }
|
258 | 261 |
|
| 262 | + @Test |
| 263 | + public void jwkTokenStoreShouldBeConditionalOnMissingBean() throws Exception { |
| 264 | + EnvironmentTestUtils.addEnvironment(this.environment, |
| 265 | + "security.oauth2.resource.jwk.key-set-uri=http://my-auth-server/token_keys"); |
| 266 | + this.context = new SpringApplicationBuilder(JwkTokenStoreConfiguration.class, |
| 267 | + ResourceConfiguration.class) |
| 268 | + .environment(this.environment).web(false).run(); |
| 269 | + assertThat(this.context.getBeansOfType(JwkTokenStore.class)).hasSize(1); |
| 270 | + } |
| 271 | + |
| 272 | + @Test |
| 273 | + public void jwtTokenStoreShouldBeConditionalOnMissingBean() throws Exception { |
| 274 | + EnvironmentTestUtils.addEnvironment(this.environment, |
| 275 | + "security.oauth2.resource.jwt.keyValue=" + PUBLIC_KEY); |
| 276 | + this.context = new SpringApplicationBuilder(JwtTokenStoreConfiguration.class, ResourceConfiguration.class) |
| 277 | + .environment(this.environment).web(false).run(); |
| 278 | + assertThat(this.context.getBeansOfType(JwtTokenStore.class)).hasSize(1); |
| 279 | + } |
| 280 | + |
259 | 281 | @Configuration
|
260 | 282 | @Import({ ResourceServerTokenServicesConfiguration.class,
|
261 | 283 | ResourceServerPropertiesConfiguration.class,
|
@@ -380,6 +402,26 @@ public JwtAccessTokenConverterRestTemplateCustomizer restTemplateCustomizer() {
|
380 | 402 |
|
381 | 403 | }
|
382 | 404 |
|
| 405 | + @Configuration |
| 406 | + static class JwtTokenStoreConfiguration { |
| 407 | + |
| 408 | + @Bean |
| 409 | + public TokenStore tokenStore(JwtAccessTokenConverter jwtTokenEnhancer) { |
| 410 | + return new JwtTokenStore(jwtTokenEnhancer); |
| 411 | + } |
| 412 | + |
| 413 | + } |
| 414 | + |
| 415 | + @Configuration |
| 416 | + static class JwkTokenStoreConfiguration { |
| 417 | + |
| 418 | + @Bean |
| 419 | + public TokenStore tokenStore() { |
| 420 | + return new JwkTokenStore("http://my.key-set.uri"); |
| 421 | + } |
| 422 | + |
| 423 | + } |
| 424 | + |
383 | 425 | private static class MockRestCallCustomizer
|
384 | 426 | implements JwtAccessTokenConverterRestTemplateCustomizer {
|
385 | 427 |
|
|
0 commit comments