Skip to content

Commit 0df13ba

Browse files
committed
Polish "Add configurable property for JWK encryption algorithm"
Closes gh-15145
1 parent 460fdaf commit 0df13ba

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/OAuth2ResourceServerJwkConfiguration.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,25 @@
3636
@Configuration
3737
class OAuth2ResourceServerJwkConfiguration {
3838

39-
private final OAuth2ResourceServerProperties properties;
39+
private final OAuth2ResourceServerProperties.Jwt properties;
4040

4141
OAuth2ResourceServerJwkConfiguration(OAuth2ResourceServerProperties properties) {
42-
this.properties = properties;
42+
this.properties = properties.getJwt();
4343
}
4444

4545
@Bean
4646
@ConditionalOnProperty(name = "spring.security.oauth2.resourceserver.jwt.jwk-set-uri")
4747
@ConditionalOnMissingBean
4848
public JwtDecoder jwtDecoderByJwkKeySetUri() {
49-
return new NimbusJwtDecoderJwkSupport(this.properties.getJwt().getJwkSetUri(),
50-
this.properties.getJwt().getJwsAlgorithm());
49+
return new NimbusJwtDecoderJwkSupport(this.properties.getJwkSetUri(),
50+
this.properties.getJwsAlgorithm());
5151
}
5252

5353
@Bean
5454
@Conditional(IssuerUriCondition.class)
5555
@ConditionalOnMissingBean
5656
public JwtDecoder jwtDecoderByIssuerUri() {
57-
return JwtDecoders
58-
.fromOidcIssuerLocation(this.properties.getJwt().getIssuerUri());
57+
return JwtDecoders.fromOidcIssuerLocation(this.properties.getIssuerUri());
5958
}
6059

6160
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/OAuth2ResourceServerAutoConfigurationTests.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,34 @@ public void cleanup() throws Exception {
7676

7777
@Test
7878
public void autoConfigurationShouldConfigureResourceServer() {
79+
this.contextRunner.withPropertyValues(
80+
"spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://jwk-set-uri.com")
81+
.run((context) -> {
82+
assertThat(context.getBean(JwtDecoder.class))
83+
.isInstanceOf(NimbusJwtDecoderJwkSupport.class);
84+
assertThat(getBearerTokenFilter(context)).isNotNull();
85+
});
86+
}
87+
88+
@Test
89+
public void autoConfigurationShouldMatchDefaultJwsAlgorithm() {
7990
this.contextRunner.withPropertyValues(
8091
"spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://jwk-set-uri.com")
8192
.run((context) -> {
8293
JwtDecoder jwtDecoder = context.getBean(JwtDecoder.class);
83-
assertThat(jwtDecoder).isInstanceOf(NimbusJwtDecoderJwkSupport.class);
84-
NimbusJwtDecoderJwkSupport decoder = (NimbusJwtDecoderJwkSupport) jwtDecoder;
85-
assertThat(decoder).hasFieldOrPropertyWithValue("jwsAlgorithm",
94+
assertThat(jwtDecoder).hasFieldOrPropertyWithValue("jwsAlgorithm",
8695
JWSAlgorithm.RS256);
87-
assertThat(getBearerTokenFilter(context)).isNotNull();
8896
});
8997
}
9098

9199
@Test
92-
public void autoConfigurationShouldConfigureResourceServerWithJwsAlgotihms() {
100+
public void autoConfigurationShouldConfigureResourceServerWithJwsAlgorithm() {
93101
this.contextRunner.withPropertyValues(
94102
"spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://jwk-set-uri.com",
95103
"spring.security.oauth2.resourceserver.jwt.jws-algorithm=HS512")
96104
.run((context) -> {
97105
JwtDecoder jwtDecoder = context.getBean(JwtDecoder.class);
98-
assertThat(jwtDecoder).isInstanceOf(NimbusJwtDecoderJwkSupport.class);
99-
NimbusJwtDecoderJwkSupport decoder = (NimbusJwtDecoderJwkSupport) jwtDecoder;
100-
assertThat(decoder).hasFieldOrPropertyWithValue("jwsAlgorithm",
106+
assertThat(jwtDecoder).hasFieldOrPropertyWithValue("jwsAlgorithm",
101107
JWSAlgorithm.HS512);
102108
assertThat(getBearerTokenFilter(context)).isNotNull();
103109
});

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ content into your application. Rather, pick only the properties that you need.
547547
548548
# SECURITY OAUTH2 RESOURCE SERVER ({sc-spring-boot-autoconfigure}/security/oauth2/resource/OAuth2ResourceServerProperties.{sc-ext}[OAuth2ResourceServerProperties])
549549
spring.security.oauth2.resourceserver.jwt.jwk-set-uri= # JSON Web Key URI to use to verify the JWT token.
550-
spring.security.oauth2.resourceserver.jwt.jws-algorithm= # JSON Web Algorithm used for verifying the digital signatures.
550+
spring.security.oauth2.resourceserver.jwt.jws-algorithm=RS256 # JSON Web Algorithm used for verifying the digital signatures.
551551
spring.security.oauth2.resourceserver.jwt.issuer-uri= # URI that an OpenID Connect Provider asserts as its Issuer Identifier.
552552
553553
# ----------------------------------------

0 commit comments

Comments
 (0)