Commit fc4340c5 authored by Madhura Bhave's avatar Madhura Bhave

Rename OAuth2 resource server properties

Closes gh-14165
parent 26353a8f
...@@ -23,7 +23,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -23,7 +23,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @author Madhura Bhave * @author Madhura Bhave
* @since 2.1.0 * @since 2.1.0
*/ */
@ConfigurationProperties(prefix = "spring.security.oauth2.resource") @ConfigurationProperties(prefix = "spring.security.oauth2.resourceserver")
public class OAuth2ResourceServerProperties { public class OAuth2ResourceServerProperties {
private final Jwt jwt = new Jwt(); private final Jwt jwt = new Jwt();
...@@ -34,27 +34,17 @@ public class OAuth2ResourceServerProperties { ...@@ -34,27 +34,17 @@ public class OAuth2ResourceServerProperties {
public static class Jwt { public static class Jwt {
private final Jwk jwk = new Jwk();
public Jwk getJwk() {
return this.jwk;
}
}
public static class Jwk {
/** /**
* JSON Web Key URI to use to verify the JWT token. * JSON Web Key URI to use to verify the JWT token.
*/ */
private String setUri; private String jwkSetUri;
public String getSetUri() { public String getJwkSetUri() {
return this.setUri; return this.jwkSetUri;
} }
public void setSetUri(String setUri) { public void setJwkSetUri(String jwkSetUri) {
this.setUri = setUri; this.jwkSetUri = jwkSetUri;
} }
} }
......
...@@ -39,11 +39,10 @@ class ReactiveOAuth2ResourceServerJwkConfiguration { ...@@ -39,11 +39,10 @@ class ReactiveOAuth2ResourceServerJwkConfiguration {
} }
@Bean @Bean
@ConditionalOnProperty(name = "spring.security.oauth2.resource.jwt.jwk.set-uri") @ConditionalOnProperty(name = "spring.security.oauth2.resourceserver.jwt.jwk-set-uri")
@ConditionalOnMissingBean @ConditionalOnMissingBean
public ReactiveJwtDecoder jwtDecoder() { public ReactiveJwtDecoder jwtDecoder() {
return new NimbusReactiveJwtDecoder( return new NimbusReactiveJwtDecoder(this.properties.getJwt().getJwkSetUri());
this.properties.getJwt().getJwk().getSetUri());
} }
} }
...@@ -38,11 +38,10 @@ class OAuth2ResourceServerJwkConfiguration { ...@@ -38,11 +38,10 @@ class OAuth2ResourceServerJwkConfiguration {
} }
@Bean @Bean
@ConditionalOnProperty(name = "spring.security.oauth2.resource.jwt.jwk.set-uri") @ConditionalOnProperty(name = "spring.security.oauth2.resourceserver.jwt.jwk-set-uri")
@ConditionalOnMissingBean @ConditionalOnMissingBean
public JwtDecoder jwtDecoder() { public JwtDecoder jwtDecoder() {
return new NimbusJwtDecoderJwkSupport( return new NimbusJwtDecoderJwkSupport(this.properties.getJwt().getJwkSetUri());
this.properties.getJwt().getJwk().getSetUri());
} }
} }
...@@ -58,7 +58,7 @@ public class ReactiveOAuth2ResourceServerAutoConfigurationTests { ...@@ -58,7 +58,7 @@ public class ReactiveOAuth2ResourceServerAutoConfigurationTests {
@Test @Test
public void autoConfigurationShouldConfigureResourceServer() { public void autoConfigurationShouldConfigureResourceServer() {
this.contextRunner.withPropertyValues( this.contextRunner.withPropertyValues(
"spring.security.oauth2.resource.jwt.jwk.set-uri=http://jwk-set-uri.com") "spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://jwk-set-uri.com")
.run((context) -> { .run((context) -> {
assertThat(context.getBean(ReactiveJwtDecoder.class)) assertThat(context.getBean(ReactiveJwtDecoder.class))
.isInstanceOf(NimbusReactiveJwtDecoder.class); .isInstanceOf(NimbusReactiveJwtDecoder.class);
...@@ -75,7 +75,7 @@ public class ReactiveOAuth2ResourceServerAutoConfigurationTests { ...@@ -75,7 +75,7 @@ public class ReactiveOAuth2ResourceServerAutoConfigurationTests {
@Test @Test
public void jwtDecoderBeanIsConditionalOnMissingBean() { public void jwtDecoderBeanIsConditionalOnMissingBean() {
this.contextRunner.withPropertyValues( this.contextRunner.withPropertyValues(
"spring.security.oauth2.resource.jwt.jwk.set-uri=http://jwk-set-uri.com") "spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://jwk-set-uri.com")
.withUserConfiguration(JwtDecoderConfig.class) .withUserConfiguration(JwtDecoderConfig.class)
.run((this::assertFilterConfiguredWithJwtAuthenticationManager)); .run((this::assertFilterConfiguredWithJwtAuthenticationManager));
} }
...@@ -83,7 +83,7 @@ public class ReactiveOAuth2ResourceServerAutoConfigurationTests { ...@@ -83,7 +83,7 @@ public class ReactiveOAuth2ResourceServerAutoConfigurationTests {
@Test @Test
public void autoConfigurationShouldBeConditionalOnBearerTokenAuthenticationTokenClass() { public void autoConfigurationShouldBeConditionalOnBearerTokenAuthenticationTokenClass() {
this.contextRunner.withPropertyValues( this.contextRunner.withPropertyValues(
"spring.security.oauth2.resource.jwt.jwk.set-uri=http://jwk-set-uri.com") "spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://jwk-set-uri.com")
.withUserConfiguration(JwtDecoderConfig.class) .withUserConfiguration(JwtDecoderConfig.class)
.withClassLoader( .withClassLoader(
new FilteredClassLoader(BearerTokenAuthenticationToken.class)) new FilteredClassLoader(BearerTokenAuthenticationToken.class))
...@@ -94,7 +94,7 @@ public class ReactiveOAuth2ResourceServerAutoConfigurationTests { ...@@ -94,7 +94,7 @@ public class ReactiveOAuth2ResourceServerAutoConfigurationTests {
@Test @Test
public void autoConfigurationWhenSecurityWebFilterChainConfigPresentShouldNotAddOne() { public void autoConfigurationWhenSecurityWebFilterChainConfigPresentShouldNotAddOne() {
this.contextRunner.withPropertyValues( this.contextRunner.withPropertyValues(
"spring.security.oauth2.resource.jwt.jwk.set-uri=http://jwk-set-uri.com") "spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://jwk-set-uri.com")
.withUserConfiguration(SecurityWebFilterChainConfig.class) .withUserConfiguration(SecurityWebFilterChainConfig.class)
.run((context) -> { .run((context) -> {
assertThat(context).hasSingleBean(SecurityWebFilterChain.class); assertThat(context).hasSingleBean(SecurityWebFilterChain.class);
......
...@@ -55,7 +55,7 @@ public class OAuth2ResourceServerAutoConfigurationTests { ...@@ -55,7 +55,7 @@ public class OAuth2ResourceServerAutoConfigurationTests {
@Test @Test
public void autoConfigurationShouldConfigureResourceServer() { public void autoConfigurationShouldConfigureResourceServer() {
this.contextRunner.withPropertyValues( this.contextRunner.withPropertyValues(
"spring.security.oauth2.resource.jwt.jwk.set-uri=http://jwk-set-uri.com") "spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://jwk-set-uri.com")
.run((context) -> { .run((context) -> {
assertThat(context.getBean(JwtDecoder.class)) assertThat(context.getBean(JwtDecoder.class))
.isInstanceOf(NimbusJwtDecoderJwkSupport.class); .isInstanceOf(NimbusJwtDecoderJwkSupport.class);
...@@ -72,7 +72,7 @@ public class OAuth2ResourceServerAutoConfigurationTests { ...@@ -72,7 +72,7 @@ public class OAuth2ResourceServerAutoConfigurationTests {
@Test @Test
public void jwtDecoderBeanIsConditionalOnMissingBean() { public void jwtDecoderBeanIsConditionalOnMissingBean() {
this.contextRunner.withPropertyValues( this.contextRunner.withPropertyValues(
"spring.security.oauth2.resource.jwt.jwk.set-uri=http://jwk-set-uri.com") "spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://jwk-set-uri.com")
.withUserConfiguration(JwtDecoderConfig.class) .withUserConfiguration(JwtDecoderConfig.class)
.run((context) -> assertThat(getBearerTokenFilter(context)).isNotNull()); .run((context) -> assertThat(getBearerTokenFilter(context)).isNotNull());
} }
...@@ -80,7 +80,7 @@ public class OAuth2ResourceServerAutoConfigurationTests { ...@@ -80,7 +80,7 @@ public class OAuth2ResourceServerAutoConfigurationTests {
@Test @Test
public void autoConfigurationShouldBeConditionalOnJwtAuthenticationTokenClass() { public void autoConfigurationShouldBeConditionalOnJwtAuthenticationTokenClass() {
this.contextRunner.withPropertyValues( this.contextRunner.withPropertyValues(
"spring.security.oauth2.resource.jwt.jwk.set-uri=http://jwk-set-uri.com") "spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://jwk-set-uri.com")
.withUserConfiguration(JwtDecoderConfig.class) .withUserConfiguration(JwtDecoderConfig.class)
.withClassLoader(new FilteredClassLoader(JwtAuthenticationToken.class)) .withClassLoader(new FilteredClassLoader(JwtAuthenticationToken.class))
.run((context) -> assertThat(getBearerTokenFilter(context)).isNull()); .run((context) -> assertThat(getBearerTokenFilter(context)).isNull());
......
...@@ -538,7 +538,7 @@ content into your application. Rather, pick only the properties that you need. ...@@ -538,7 +538,7 @@ content into your application. Rather, pick only the properties that you need.
spring.security.oauth2.client.registration.*= # OAuth client registrations. spring.security.oauth2.client.registration.*= # OAuth client registrations.
# SECURITY OAUTH2 RESOURCE SERVER ({sc-spring-boot-autoconfigure}/security/oauth2/resource/OAuth2ResourceServerProperties.{sc-ext}[OAuth2ResourceServerProperties]) # SECURITY OAUTH2 RESOURCE SERVER ({sc-spring-boot-autoconfigure}/security/oauth2/resource/OAuth2ResourceServerProperties.{sc-ext}[OAuth2ResourceServerProperties])
spring.security.oauth2.resource.jwt.jwk.set-uri= # JSON Web Key URI to use to verify the JWT token. spring.security.oauth2.resourceserver.jwt.jwk-set-uri= # JSON Web Key URI to use to verify the JWT token.
# ---------------------------------------- # ----------------------------------------
# DATA PROPERTIES # DATA PROPERTIES
......
...@@ -3324,7 +3324,7 @@ following example: ...@@ -3324,7 +3324,7 @@ following example:
[source,properties,indent=0] [source,properties,indent=0]
---- ----
spring.security.oauth2.resource.jwt.jwk.set-uri=https://example.com/oauth2/default/v1/keys spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://example.com/oauth2/default/v1/keys
---- ----
The same properties are applicable for both servlet and reactive applications. The same properties are applicable for both servlet and reactive applications.
......
...@@ -3,6 +3,5 @@ spring: ...@@ -3,6 +3,5 @@ spring:
oauth2: oauth2:
resource: resource:
jwt: jwt:
jwk: # To run the application, replace this with a valid JWK Set URI
# To run the application, replace this with a valid JWK Set URI jwk-set-uri: https://example.com/oauth2/default/v1/keys
set-uri: https://example.com/oauth2/default/v1/keys \ No newline at end of file
\ No newline at end of file
...@@ -57,13 +57,13 @@ public class SampleOauth2ResourceServerApplicationTests { ...@@ -57,13 +57,13 @@ public class SampleOauth2ResourceServerApplicationTests {
server.start(); server.start();
String url = server.url("/.well-known/jwks.json").toString(); String url = server.url("/.well-known/jwks.json").toString();
server.enqueue(mockResponse()); server.enqueue(mockResponse());
System.setProperty("spring.security.oauth2.resource.jwt.jwk.set-uri", url); System.setProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri", url);
} }
@AfterClass @AfterClass
public static void shutdown() throws IOException { public static void shutdown() throws IOException {
server.shutdown(); server.shutdown();
System.clearProperty("spring.security.oauth2.resource.jwt.jwk.set-uri"); System.clearProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri");
} }
@Test @Test
......
spring: spring:
security: security:
oauth2: oauth2:
resource: resourceserver:
jwt: jwt:
jwk:
# To run the application, replace this with a valid JWK Set URI # To run the application, replace this with a valid JWK Set URI
set-uri: https://example.com/oauth2/default/v1/keys jwk-set-uri: https://example.com/oauth2/default/v1/keys
\ No newline at end of file \ No newline at end of file
...@@ -50,13 +50,13 @@ public class SampleReactiveOAuth2ResourceServerApplicationTests { ...@@ -50,13 +50,13 @@ public class SampleReactiveOAuth2ResourceServerApplicationTests {
server.start(); server.start();
String url = server.url("/.well-known/jwks.json").toString(); String url = server.url("/.well-known/jwks.json").toString();
server.enqueue(mockResponse()); server.enqueue(mockResponse());
System.setProperty("spring.security.oauth2.resource.jwt.jwk.set-uri", url); System.setProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri", url);
} }
@AfterClass @AfterClass
public static void shutdown() throws Exception { public static void shutdown() throws Exception {
server.shutdown(); server.shutdown();
System.clearProperty("spring.security.oauth2.resource.jwt.jwk.set-uri"); System.clearProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri");
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment