Skip to content

Commit 39ec335

Browse files
committed
Merge branch '1.5.x'
2 parents eb4fc16 + 6381b88 commit 39ec335

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,14 @@ public JwkTokenStoreConfiguration(ResourceServerProperties resource) {
222222

223223
@Bean
224224
@ConditionalOnMissingBean(ResourceServerTokenServices.class)
225-
public DefaultTokenServices jwkTokenServices() {
225+
public DefaultTokenServices jwkTokenServices(TokenStore jwkTokenStore) {
226226
DefaultTokenServices services = new DefaultTokenServices();
227-
services.setTokenStore(jwkTokenStore());
227+
services.setTokenStore(jwkTokenStore);
228228
return services;
229229
}
230230

231231
@Bean
232+
@ConditionalOnMissingBean(TokenStore.class)
232233
public TokenStore jwkTokenStore() {
233234
return new JwkTokenStore(this.resource.getJwk().getKeySetUri());
234235
}
@@ -254,13 +255,14 @@ public JwtTokenServicesConfiguration(ResourceServerProperties resource,
254255

255256
@Bean
256257
@ConditionalOnMissingBean(ResourceServerTokenServices.class)
257-
public DefaultTokenServices jwtTokenServices() {
258+
public DefaultTokenServices jwtTokenServices(TokenStore jwtTokenStore) {
258259
DefaultTokenServices services = new DefaultTokenServices();
259-
services.setTokenStore(jwtTokenStore());
260+
services.setTokenStore(jwtTokenStore);
260261
return services;
261262
}
262263

263264
@Bean
265+
@ConditionalOnMissingBean(TokenStore.class)
264266
public TokenStore jwtTokenStore() {
265267
return new JwtTokenStore(jwtTokenEnhancer());
266268
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@
5858
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails;
5959
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
6060
import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
61+
import org.springframework.security.oauth2.provider.token.TokenStore;
6162
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;
6265
import org.springframework.social.connect.ConnectionFactoryLocator;
6366
import org.springframework.stereotype.Component;
6467
import org.springframework.web.client.RestTemplate;
@@ -261,6 +264,27 @@ public void jwtAccessTokenConverterIsConfiguredWhenKeyUriIsProvided() {
261264
assertThat(this.context.getBeansOfType(JwtAccessTokenConverter.class)).hasSize(1);
262265
}
263266

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+
264288
@Configuration
265289
@Import({ ResourceServerTokenServicesConfiguration.class,
266290
ResourceServerPropertiesConfiguration.class,
@@ -385,6 +409,26 @@ public JwtAccessTokenConverterRestTemplateCustomizer restTemplateCustomizer() {
385409

386410
}
387411

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+
388432
private static class MockRestCallCustomizer
389433
implements JwtAccessTokenConverterRestTemplateCustomizer {
390434

0 commit comments

Comments
 (0)