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

Commit cd44dc3

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 1912610 commit cd44dc3

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
@@ -277,6 +277,7 @@ public TokenStore jwtTokenStore() {
277277
}
278278

279279
@Bean
280+
@ConditionalOnMissingBean(JwtAccessTokenConverter.class)
280281
public JwtAccessTokenConverter jwtTokenEnhancer() {
281282
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
282283
String keyValue = this.resource.getJwt().getKeyValue();
@@ -356,6 +357,7 @@ public TokenStore tokenStore() {
356357
}
357358

358359
@Bean
360+
@ConditionalOnMissingBean(JwtAccessTokenConverter.class)
359361
public JwtAccessTokenConverter accessTokenConverter() {
360362
Assert.notNull(this.resource.getJwt().getKeyStore(),
361363
"keyStore 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
@@ -278,6 +278,30 @@ public void jwtTokenStoreShouldBeConditionalOnMissingBean() throws Exception {
278278
assertThat(this.context.getBeansOfType(JwtTokenStore.class)).hasSize(1);
279279
}
280280

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

0 commit comments

Comments
 (0)