Skip to content

Commit 68fcea7

Browse files
committed
Migrate endpoints.cors to management.endpoints.cors
This commit moves CORS properties out of the endpoints namespace as they do not refer to a "cors" endpoint but rather to the CORS configuration of all endpoints. Closes gh-10053
1 parent 3087514 commit 68fcea7

File tree

7 files changed

+37
-38
lines changed

7 files changed

+37
-38
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.actuate.autoconfigure.endpoint;
17+
package org.springframework.boot.actuate.autoconfigure.endpoint.infrastructure;
1818

1919
import java.util.ArrayList;
2020
import java.util.List;
@@ -27,8 +27,8 @@
2727
* @author Andy Wilkinson
2828
* @since 2.0.0
2929
*/
30-
@ConfigurationProperties(prefix = "endpoints.cors")
31-
public class EndpointCorsProperties {
30+
@ConfigurationProperties(prefix = "management.endpoints.cors")
31+
public class CorsEndpointProperties {
3232

3333
/**
3434
* Comma-separated list of origins to allow. '*' allows all origins. When not set,

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/infrastructure/WebEndpointInfrastructureManagementContextConfiguration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import org.springframework.beans.factory.ObjectProvider;
2626
import org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration;
27-
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointCorsProperties;
2827
import org.springframework.boot.actuate.autoconfigure.web.ManagementServerProperties;
2928
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
3029
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -50,7 +49,7 @@
5049
*/
5150
@ConditionalOnWebApplication
5251
@ManagementContextConfiguration
53-
@EnableConfigurationProperties({ EndpointCorsProperties.class,
52+
@EnableConfigurationProperties({ CorsEndpointProperties.class,
5453
ManagementServerProperties.class })
5554
class WebEndpointInfrastructureManagementContextConfiguration {
5655

@@ -91,7 +90,7 @@ static class MvcWebEndpointConfiguration {
9190
@ConditionalOnMissingBean
9291
public WebEndpointServletHandlerMapping webEndpointServletHandlerMapping(
9392
EndpointProvider<WebEndpointOperation> provider,
94-
EndpointCorsProperties corsProperties,
93+
CorsEndpointProperties corsProperties,
9594
ManagementServerProperties managementServerProperties) {
9695
WebEndpointServletHandlerMapping handlerMapping = new WebEndpointServletHandlerMapping(
9796
managementServerProperties.getContextPath(), provider.getEndpoints(),
@@ -103,7 +102,7 @@ public WebEndpointServletHandlerMapping webEndpointServletHandlerMapping(
103102
}
104103

105104
private CorsConfiguration getCorsConfiguration(
106-
EndpointCorsProperties properties) {
105+
CorsEndpointProperties properties) {
107106
if (CollectionUtils.isEmpty(properties.getAllowedOrigins())) {
108107
return null;
109108
}

spring-boot-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
}
201201
],"hints": [
202202
{
203-
"name": "endpoints.cors.allowed-headers",
203+
"name": "management.endpoints.cors.allowed-headers",
204204
"values": [
205205
{
206206
"value": "*"
@@ -213,7 +213,7 @@
213213
]
214214
},
215215
{
216-
"name": "endpoints.cors.allowed-methods",
216+
"name": "management.endpoints.cors.allowed-methods",
217217
"values": [
218218
{
219219
"value": "*"
@@ -226,7 +226,7 @@
226226
]
227227
},
228228
{
229-
"name": "endpoints.cors.allowed-origins",
229+
"name": "management.endpoints.cors.allowed-origins",
230230
"values": [
231231
{
232232
"value": "*"

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointCorsIntegrationTests.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void corsIsDisabledByDefault() throws Exception {
7777

7878
@Test
7979
public void settingAllowedOriginsEnablesCors() throws Exception {
80-
TestPropertyValues.of("endpoints.cors.allowed-origins:foo.example.com")
80+
TestPropertyValues.of("management.endpoints.cors.allowed-origins:foo.example.com")
8181
.applyTo(this.context);
8282
createMockMvc()
8383
.perform(options("/application/beans").header("Origin", "bar.example.com")
@@ -88,23 +88,23 @@ public void settingAllowedOriginsEnablesCors() throws Exception {
8888

8989
@Test
9090
public void maxAgeDefaultsTo30Minutes() throws Exception {
91-
TestPropertyValues.of("endpoints.cors.allowed-origins:foo.example.com")
91+
TestPropertyValues.of("management.endpoints.cors.allowed-origins:foo.example.com")
9292
.applyTo(this.context);
9393
performAcceptedCorsRequest()
9494
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1800"));
9595
}
9696

9797
@Test
9898
public void maxAgeCanBeConfigured() throws Exception {
99-
TestPropertyValues.of("endpoints.cors.allowed-origins:foo.example.com",
100-
"endpoints.cors.max-age: 2400").applyTo(this.context);
99+
TestPropertyValues.of("management.endpoints.cors.allowed-origins:foo.example.com",
100+
"management.endpoints.cors.max-age: 2400").applyTo(this.context);
101101
performAcceptedCorsRequest()
102102
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "2400"));
103103
}
104104

105105
@Test
106106
public void requestsWithDisallowedHeadersAreRejected() throws Exception {
107-
TestPropertyValues.of("endpoints.cors.allowed-origins:foo.example.com")
107+
TestPropertyValues.of("management.endpoints.cors.allowed-origins:foo.example.com")
108108
.applyTo(this.context);
109109
createMockMvc()
110110
.perform(options("/application/beans").header("Origin", "foo.example.com")
@@ -116,8 +116,8 @@ public void requestsWithDisallowedHeadersAreRejected() throws Exception {
116116
@Test
117117
public void allowedHeadersCanBeConfigured() throws Exception {
118118
TestPropertyValues
119-
.of("endpoints.cors.allowed-origins:foo.example.com",
120-
"endpoints.cors.allowed-headers:Alpha,Bravo")
119+
.of("management.endpoints.cors.allowed-origins:foo.example.com",
120+
"management.endpoints.cors.allowed-headers:Alpha,Bravo")
121121
.applyTo(this.context);
122122
createMockMvc()
123123
.perform(options("/application/beans").header("Origin", "foo.example.com")
@@ -129,7 +129,7 @@ public void allowedHeadersCanBeConfigured() throws Exception {
129129

130130
@Test
131131
public void requestsWithDisallowedMethodsAreRejected() throws Exception {
132-
TestPropertyValues.of("endpoints.cors.allowed-origins:foo.example.com")
132+
TestPropertyValues.of("management.endpoints.cors.allowed-origins:foo.example.com")
133133
.applyTo(this.context);
134134
createMockMvc()
135135
.perform(options("/application/health")
@@ -140,8 +140,8 @@ public void requestsWithDisallowedMethodsAreRejected() throws Exception {
140140

141141
@Test
142142
public void allowedMethodsCanBeConfigured() throws Exception {
143-
TestPropertyValues.of("endpoints.cors.allowed-origins:foo.example.com",
144-
"endpoints.cors.allowed-methods:GET,HEAD").applyTo(this.context);
143+
TestPropertyValues.of("management.endpoints.cors.allowed-origins:foo.example.com",
144+
"management.endpoints.cors.allowed-methods:GET,HEAD").applyTo(this.context);
145145
createMockMvc()
146146
.perform(options("/application/beans")
147147
.header(HttpHeaders.ORIGIN, "foo.example.com")
@@ -152,16 +152,16 @@ public void allowedMethodsCanBeConfigured() throws Exception {
152152

153153
@Test
154154
public void credentialsCanBeAllowed() throws Exception {
155-
TestPropertyValues.of("endpoints.cors.allowed-origins:foo.example.com",
156-
"endpoints.cors.allow-credentials:true").applyTo(this.context);
155+
TestPropertyValues.of("management.endpoints.cors.allowed-origins:foo.example.com",
156+
"management.endpoints.cors.allow-credentials:true").applyTo(this.context);
157157
performAcceptedCorsRequest().andExpect(
158158
header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"));
159159
}
160160

161161
@Test
162162
public void credentialsCanBeDisabled() throws Exception {
163-
TestPropertyValues.of("endpoints.cors.allowed-origins:foo.example.com",
164-
"endpoints.cors.allow-credentials:false").applyTo(this.context);
163+
TestPropertyValues.of("management.endpoints.cors.allowed-origins:foo.example.com",
164+
"management.endpoints.cors.allow-credentials:false").applyTo(this.context);
165165
performAcceptedCorsRequest().andExpect(
166166
header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
167167
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,14 +1114,6 @@ content into your application; rather pick only the properties that you need.
11141114
endpoints.configprops.keys-to-sanitize=password,secret,key,token,.*credentials.*,vcap_services # Keys that should be sanitized. Keys can be simple strings that the property ends with or regex expressions.
11151115
endpoints.configprops.web.enabled=true # Expose the configprops endpoint as a Web endpoint.
11161116
1117-
# ENDPOINTS CORS CONFIGURATION ({sc-spring-boot-actuator}/autoconfigure/EndpointCorsProperties.{sc-ext}[EndpointCorsProperties])
1118-
endpoints.cors.allow-credentials= # Set whether credentials are supported. When not set, credentials are not supported.
1119-
endpoints.cors.allowed-headers= # Comma-separated list of headers to allow in a request. '*' allows all headers.
1120-
endpoints.cors.allowed-methods= # Comma-separated list of methods to allow. '*' allows all methods. When not set, defaults to GET.
1121-
endpoints.cors.allowed-origins= # Comma-separated list of origins to allow. '*' allows all origins. When not set, CORS support is disabled.
1122-
endpoints.cors.exposed-headers= # Comma-separated list of headers to include in a response.
1123-
endpoints.cors.max-age=1800 # How long, in seconds, the response from a pre-flight request can be cached by clients.
1124-
11251117
# ENVIRONMENT ENDPOINT ({sc-spring-boot-actuator}/endpoint/EnvironmentEndpoint.{sc-ext}[EnvironmentEndpoint])
11261118
endpoints.env.cache.time-to-live=0 # Maximum time in milliseconds that a response can be cached.
11271119
endpoints.env.enabled=true # Enable the env endpoint.
@@ -1238,6 +1230,14 @@ content into your application; rather pick only the properties that you need.
12381230
management.cloudfoundry.enabled=true # Enable extended Cloud Foundry actuator endpoints.
12391231
management.cloudfoundry.skip-ssl-validation=false # Skip SSL verification for Cloud Foundry actuator endpoint security calls.
12401232
1233+
# ENDPOINTS CORS CONFIGURATION ({sc-spring-boot-actuator}/autoconfigure/EndpointCorsProperties.{sc-ext}[EndpointCorsProperties])
1234+
management.endpoints.cors.allow-credentials= # Set whether credentials are supported. When not set, credentials are not supported.
1235+
management.cors.allowed-headers= # Comma-separated list of headers to allow in a request. '*' allows all headers.
1236+
management.endpoints.cors.allowed-methods= # Comma-separated list of methods to allow. '*' allows all methods. When not set, defaults to GET.
1237+
management.endpoints.cors.allowed-origins= # Comma-separated list of origins to allow. '*' allows all origins. When not set, CORS support is disabled.
1238+
management.endpoints.cors.exposed-headers= # Comma-separated list of headers to include in a response.
1239+
management.endpoints.cors.max-age=1800 # How long, in seconds, the response from a pre-flight request can be cached by clients.
1240+
12411241
# HEALTH INDICATORS
12421242
management.health.db.enabled=true # Enable database health check.
12431243
management.health.cassandra.enabled=true # Enable cassandra health check.

spring-boot-docs/src/main/asciidoc/production-ready-features.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ MVC or Spring WebFlux, Actuator's web endpoints can be configured to support suc
243243
scenarios.
244244

245245
CORS support is disabled by default and is only enabled once the
246-
`endpoints.cors.allowed-origins` property has been set. The configuration below permits
247-
`GET` and `POST` calls from the `example.com` domain:
246+
`management.endpoints.cors.allowed-origins` property has been set. The configuration below
247+
permits `GET` and `POST` calls from the `example.com` domain:
248248

249249
[source,properties,indent=0]
250250
----
251-
endpoints.cors.allowed-origins=http://example.com
252-
endpoints.cors.allowed-methods=GET,POST
251+
management.endpoints.cors.allowed-origins=http://example.com
252+
management.endpoints.cors.allowed-methods=GET,POST
253253
----
254254

255255
TIP: Check {sc-spring-boot-actuator}/autoconfigure/EndpointCorsProperties.{sc-ext}[EndpointCorsProperties]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
endpoints.cors.allowed-origins=http://localhost:8080
2-
endpoints.cors.allowed-methods=GET
1+
management.endpoints.cors.allowed-origins=http://localhost:8080
2+
management.endpoints.cors.allowed-methods=GET

0 commit comments

Comments
 (0)