Commit 2f9db7ee authored by Sebastien Deleuze's avatar Sebastien Deleuze Committed by Andy Wilkinson

Update CORS handling according to Framework changes

This commit updates CORS handling according to Framework changes
introduced via [1]. It also fixes tests according to the new behavior.

See gh-16410

[1] https://github.com/spring-projects/spring-framework/commit/d27b5d0ab6e8b91a77e272ad57ae83c7d81d810b.
parent 8ebe5f99
...@@ -63,8 +63,7 @@ public class WebFluxEndpointCorsIntegrationTests { ...@@ -63,8 +63,7 @@ public class WebFluxEndpointCorsIntegrationTests {
createWebTestClient().options().uri("/actuator/beans") createWebTestClient().options().uri("/actuator/beans")
.header("Origin", "spring.example.org") .header("Origin", "spring.example.org")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET").exchange() .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET").exchange()
.expectStatus().isForbidden().expectHeader() .expectHeader().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN);
.doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN);
} }
@Test @Test
......
...@@ -138,7 +138,7 @@ public class WebMvcEndpointCorsIntegrationTests { ...@@ -138,7 +138,7 @@ public class WebMvcEndpointCorsIntegrationTests {
.of("management.endpoints.web.cors.allowed-origins:foo.example.com") .of("management.endpoints.web.cors.allowed-origins:foo.example.com")
.applyTo(this.context); .applyTo(this.context);
createMockMvc() createMockMvc()
.perform(options("/actuator/health") .perform(options("/actuator/beans")
.header(HttpHeaders.ORIGIN, "foo.example.com") .header(HttpHeaders.ORIGIN, "foo.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "PATCH")) .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "PATCH"))
.andExpect(status().isForbidden()); .andExpect(status().isForbidden());
......
...@@ -190,6 +190,11 @@ public abstract class AbstractWebFluxEndpointHandlerMapping ...@@ -190,6 +190,11 @@ public abstract class AbstractWebFluxEndpointHandlerMapping
.findMethod(linksHandler.getClass(), "links", ServerWebExchange.class)); .findMethod(linksHandler.getClass(), "links", ServerWebExchange.class));
} }
@Override
protected boolean hasCorsConfigurationSource(Object handler) {
return this.corsConfiguration != null;
}
@Override @Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
RequestMappingInfo mapping) { RequestMappingInfo mapping) {
......
...@@ -117,6 +117,11 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi ...@@ -117,6 +117,11 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi
mapping.getCustomCondition()); mapping.getCustomCondition());
} }
@Override
protected boolean hasCorsConfigurationSource(Object handler) {
return this.corsConfiguration != null;
}
@Override @Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
RequestMappingInfo mapping) { RequestMappingInfo mapping) {
......
...@@ -217,6 +217,11 @@ public abstract class AbstractWebMvcEndpointHandlerMapping ...@@ -217,6 +217,11 @@ public abstract class AbstractWebMvcEndpointHandlerMapping
builderConfig.useTrailingSlashMatch()); builderConfig.useTrailingSlashMatch());
} }
@Override
protected boolean hasCorsConfigurationSource(Object handler) {
return this.corsConfiguration != null;
}
@Override @Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
RequestMappingInfo mapping) { RequestMappingInfo mapping) {
......
...@@ -118,6 +118,11 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi ...@@ -118,6 +118,11 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi
mapping.getCustomCondition()); mapping.getCustomCondition());
} }
@Override
protected boolean hasCorsConfigurationSource(Object handler) {
return this.corsConfiguration != null;
}
@Override @Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
RequestMappingInfo mapping) { RequestMappingInfo mapping) {
......
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