Skip to content

Commit 3c21ade

Browse files
committed
Merge pull request #16410 from Sebastien Deleuze
* gh-16410: Polish "Update CORS handling according to Framework changes" Update CORS handling according to Framework changes Closes gh-16410
2 parents 8ebe5f9 + e1a6726 commit 3c21ade

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebFluxEndpointCorsIntegrationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -63,8 +63,7 @@ public void corsIsDisabledByDefault() {
6363
createWebTestClient().options().uri("/actuator/beans")
6464
.header("Origin", "spring.example.org")
6565
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET").exchange()
66-
.expectStatus().isForbidden().expectHeader()
67-
.doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN);
66+
.expectHeader().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN);
6867
}
6968

7069
@Test

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointCorsIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -138,7 +138,7 @@ public void requestsWithDisallowedMethodsAreRejected() throws Exception {
138138
.of("management.endpoints.web.cors.allowed-origins:foo.example.com")
139139
.applyTo(this.context);
140140
createMockMvc()
141-
.perform(options("/actuator/health")
141+
.perform(options("/actuator/beans")
142142
.header(HttpHeaders.ORIGIN, "foo.example.com")
143143
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "PATCH"))
144144
.andExpect(status().isForbidden());

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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,11 @@ private void registerLinksMapping() {
190190
.findMethod(linksHandler.getClass(), "links", ServerWebExchange.class));
191191
}
192192

193+
@Override
194+
protected boolean hasCorsConfigurationSource(Object handler) {
195+
return this.corsConfiguration != null;
196+
}
197+
193198
@Override
194199
protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
195200
RequestMappingInfo mapping) {

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMapping.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -117,6 +117,11 @@ private RequestMappingInfo withNewPatterns(RequestMappingInfo mapping,
117117
mapping.getCustomCondition());
118118
}
119119

120+
@Override
121+
protected boolean hasCorsConfigurationSource(Object handler) {
122+
return this.corsConfiguration != null;
123+
}
124+
120125
@Override
121126
protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
122127
RequestMappingInfo mapping) {

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -217,6 +217,11 @@ private PatternsRequestCondition patternsRequestConditionForPattern(String path)
217217
builderConfig.useTrailingSlashMatch());
218218
}
219219

220+
@Override
221+
protected boolean hasCorsConfigurationSource(Object handler) {
222+
return this.corsConfiguration != null;
223+
}
224+
220225
@Override
221226
protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
222227
RequestMappingInfo mapping) {

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/ControllerEndpointHandlerMapping.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -118,6 +118,11 @@ patterns, null, null, useSuffixPatternMatch(), useTrailingSlashMatch(),
118118
mapping.getCustomCondition());
119119
}
120120

121+
@Override
122+
protected boolean hasCorsConfigurationSource(Object handler) {
123+
return this.corsConfiguration != null;
124+
}
125+
121126
@Override
122127
protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
123128
RequestMappingInfo mapping) {

0 commit comments

Comments
 (0)