Skip to content

Commit 1c2ca29

Browse files
committed
Introduce configuration properties prefix constants for OAuth2ResourceServerProperties
Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
1 parent 9e6645e commit 1c2ca29

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

module/spring-boot-security-oauth2-resource-server/src/main/java/org/springframework/boot/security/oauth2/server/resource/autoconfigure/IssuerUriCondition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ class IssuerUriCondition extends SpringBootCondition {
3636
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
3737
ConditionMessage.Builder message = ConditionMessage.forCondition("OpenID Connect Issuer URI Condition");
3838
Environment environment = context.getEnvironment();
39-
String issuerUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.issuer-uri");
39+
String issuerUri = environment.getProperty(OAuth2ResourceServerProperties.JWT_PROPERTIES__PREFIX + ".issuer-uri");
4040
if (!StringUtils.hasText(issuerUri)) {
4141
return ConditionOutcome.noMatch(message.didNotFind("issuer-uri property").atAll());
4242
}
43-
String jwkSetUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri");
43+
String jwkSetUri = environment.getProperty(OAuth2ResourceServerProperties.JWT_PROPERTIES__PREFIX + ".jwk-set-uri");
4444
if (StringUtils.hasText(jwkSetUri)) {
4545
return ConditionOutcome.noMatch(message.found("jwk-set-uri property").items(jwkSetUri));
4646
}

module/spring-boot-security-oauth2-resource-server/src/main/java/org/springframework/boot/security/oauth2/server/resource/autoconfigure/KeyValueCondition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
3636
ConditionMessage.Builder message = ConditionMessage.forCondition("Public Key Value Condition");
3737
Environment environment = context.getEnvironment();
3838
String publicKeyLocation = environment
39-
.getProperty("spring.security.oauth2.resourceserver.jwt.public-key-location");
39+
.getProperty(OAuth2ResourceServerProperties.JWT_PROPERTIES__PREFIX + ".public-key-location");
4040
if (!StringUtils.hasText(publicKeyLocation)) {
4141
return ConditionOutcome.noMatch(message.didNotFind("public-key-location property").atAll());
4242
}
43-
String jwkSetUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri");
43+
String jwkSetUri = environment.getProperty(OAuth2ResourceServerProperties.JWT_PROPERTIES__PREFIX + ".jwk-set-uri");
4444
if (StringUtils.hasText(jwkSetUri)) {
4545
return ConditionOutcome.noMatch(message.found("jwk-set-uri property").items(jwkSetUri));
4646
}
47-
String issuerUri = environment.getProperty("spring.security.oauth2.resourceserver.jwt.issuer-uri");
47+
String issuerUri = environment.getProperty(OAuth2ResourceServerProperties.JWT_PROPERTIES__PREFIX + ".issuer-uri");
4848
if (StringUtils.hasText(issuerUri)) {
4949
return ConditionOutcome.noMatch(message.found("issuer-uri property").items(issuerUri));
5050
}

module/spring-boot-security-oauth2-resource-server/src/main/java/org/springframework/boot/security/oauth2/server/resource/autoconfigure/OAuth2ResourceServerProperties.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@
3737
* @author Yan Kardziyaka
3838
* @since 4.0.0
3939
*/
40-
@ConfigurationProperties("spring.security.oauth2.resourceserver")
40+
@ConfigurationProperties(OAuth2ResourceServerProperties.PROPERTIES_PREFIX)
4141
public class OAuth2ResourceServerProperties {
4242

43+
public static final String PROPERTIES_PREFIX = "spring.security.oauth2.resourceserver";
44+
45+
public static final String JWT_PROPERTIES__PREFIX = PROPERTIES_PREFIX + ".jwt";
46+
4347
private final Jwt jwt = new Jwt();
4448

4549
public Jwt getJwt() {
@@ -173,7 +177,7 @@ public void setPrincipalClaimName(String principalClaimName) {
173177
}
174178

175179
public String readPublicKey() throws IOException {
176-
String key = "spring.security.oauth2.resourceserver.public-key-location";
180+
String key = JWT_PROPERTIES__PREFIX + ".public-key-location";
177181
if (this.publicKeyLocation == null) {
178182
throw new InvalidConfigurationPropertyValueException(key, this.publicKeyLocation,
179183
"No public key location specified");

module/spring-boot-security-oauth2-resource-server/src/main/java/org/springframework/boot/security/oauth2/server/resource/autoconfigure/reactive/ReactiveOAuth2ResourceServerJwkConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,17 @@ private static class JwtConverterPropertiesCondition extends AnyNestedCondition
227227
super(ConfigurationPhase.REGISTER_BEAN);
228228
}
229229

230-
@ConditionalOnProperty("spring.security.oauth2.resourceserver.jwt.authority-prefix")
230+
@ConditionalOnProperty(OAuth2ResourceServerProperties.JWT_PROPERTIES__PREFIX + ".authority-prefix")
231231
static class OnAuthorityPrefix {
232232

233233
}
234234

235-
@ConditionalOnProperty("spring.security.oauth2.resourceserver.jwt.principal-claim-name")
235+
@ConditionalOnProperty(OAuth2ResourceServerProperties.JWT_PROPERTIES__PREFIX + ".principal-claim-name")
236236
static class OnPrincipalClaimName {
237237

238238
}
239239

240-
@ConditionalOnProperty("spring.security.oauth2.resourceserver.jwt.authorities-claim-name")
240+
@ConditionalOnProperty(OAuth2ResourceServerProperties.JWT_PROPERTIES__PREFIX + ".authorities-claim-name")
241241
static class OnAuthoritiesClaimName {
242242

243243
}

0 commit comments

Comments
 (0)