Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.

Commit 87af26d

Browse files
tomcruise81jzheaux
authored andcommitted
Add missing @ConditionalOnMissingBean annotations
Seems to be necessary as a result of the changes related to spring-projects/spring-boot#13609
1 parent b97728f commit 87af26d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ public TokenStore jwtTokenStore() {
276276
}
277277

278278
@Bean
279+
@ConditionalOnMissingBean(JwtAccessTokenConverter.class)
279280
public JwtAccessTokenConverter jwtTokenEnhancer() {
280281
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
281282
String keyValue = this.resource.getJwt().getKeyValue();
@@ -353,6 +354,7 @@ public TokenStore tokenStore() {
353354
}
354355

355356
@Bean
357+
@ConditionalOnMissingBean(JwtAccessTokenConverter.class)
356358
public JwtAccessTokenConverter accessTokenConverter() {
357359
Assert.notNull(this.resource.getJwt().getKeyStore(), "keyStore cannot be null");
358360
Assert.notNull(this.resource.getJwt().getKeyStorePassword(), "keyStorePassword cannot be null");

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

+24
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,30 @@ public void jwtTokenStoreShouldBeConditionalOnMissingBean() throws Exception {
282282
assertThat(this.context.getBeansOfType(JwtTokenStore.class)).hasSize(1);
283283
}
284284

285+
@Test
286+
public void jwtAccessTokenConverterForKeyValueShouldBeConditionalOnMissingBean()
287+
throws Exception {
288+
TestPropertyValues.of("security.oauth2.resource.jwt.keyValue=" + PUBLIC_KEY)
289+
.applyTo(this.environment);
290+
this.context = new SpringApplicationBuilder(JwtTokenStoreConfiguration.class,
291+
ResourceConfiguration.class).environment(this.environment)
292+
.web(WebApplicationType.NONE).run();
293+
assertThat(this.context.getBeansOfType(JwtAccessTokenConverter.class)).hasSize(1);
294+
}
295+
296+
@Test
297+
public void jwtAccessTokenConverterForKeyStoreShouldBeConditionalOnMissingBean()
298+
throws Exception {
299+
TestPropertyValues.of("security.oauth2.resource.jwt.key-store=classpath:"
300+
+ "org/springframework/boot/autoconfigure/security/oauth2/resource/keystore.jks",
301+
"security.oauth2.resource.jwt.key-store-password=changeme",
302+
"security.oauth2.resource.jwt.key-alias=jwt").applyTo(this.environment);
303+
this.context = new SpringApplicationBuilder(JwtTokenStoreConfiguration.class,
304+
ResourceConfiguration.class).environment(this.environment)
305+
.web(WebApplicationType.NONE).run();
306+
assertThat(this.context.getBeansOfType(JwtAccessTokenConverter.class)).hasSize(1);
307+
}
308+
285309
@Test
286310
public void configureWhenKeyStoreIsProvidedThenExposesJwtTokenStore() {
287311
TestPropertyValues.of(

0 commit comments

Comments
 (0)