Skip to content

Commit 3735771

Browse files
committed
Merge branch '2.2.x'
Closes gh-20612
2 parents 535e782 + ef1f9b9 commit 3735771

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,7 +78,8 @@ JwtDecoder jwtDecoderByJwkKeySetUri() {
7878
JwtDecoder jwtDecoderByPublicKeyValue() throws Exception {
7979
RSAPublicKey publicKey = (RSAPublicKey) KeyFactory.getInstance("RSA")
8080
.generatePublic(new X509EncodedKeySpec(getKeySpec(this.properties.readPublicKey())));
81-
return NimbusJwtDecoder.withPublicKey(publicKey).build();
81+
return NimbusJwtDecoder.withPublicKey(publicKey)
82+
.signatureAlgorithm(SignatureAlgorithm.from(this.properties.getJwsAlgorithm())).build();
8283
}
8384

8485
private byte[] getKeySpec(String keyValue) {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -190,6 +190,16 @@ void autoConfigurationShouldFailIfPublicKeyLocationDoesNotExist() {
190190
.hasMessageContaining("Public key location does not exist"));
191191
}
192192

193+
@Test
194+
void autoConfigurationShouldFailIfAlgorithmIsInvalid() {
195+
this.contextRunner
196+
.withPropertyValues(
197+
"spring.security.oauth2.resourceserver.jwt.public-key-location=classpath:public-key-location",
198+
"spring.security.oauth2.resourceserver.jwt.jws-algorithm=NOT_VALID")
199+
.run((context) -> assertThat(context).hasFailed().getFailure()
200+
.hasMessageContaining("signatureAlgorithm cannot be null"));
201+
}
202+
193203
@Test
194204
void autoConfigurationWhenSetUriKeyLocationAndIssuerUriPresentShouldUseSetUri() {
195205
this.contextRunner

0 commit comments

Comments
 (0)