Browse Source

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] d27b5d0ab6.
pull/16419/head
Sebastien Deleuze 7 years ago committed by Andy Wilkinson
parent
commit
2f9db7eec6
  1. 3
      spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebFluxEndpointCorsIntegrationTests.java
  2. 2
      spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointCorsIntegrationTests.java
  3. 5
      spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java
  4. 5
      spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMapping.java
  5. 5
      spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java
  6. 5
      spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/ControllerEndpointHandlerMapping.java

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

@ -63,8 +63,7 @@ public class WebFluxEndpointCorsIntegrationTests { @@ -63,8 +63,7 @@ public class WebFluxEndpointCorsIntegrationTests {
createWebTestClient().options().uri("/actuator/beans")
.header("Origin", "spring.example.org")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET").exchange()
.expectStatus().isForbidden().expectHeader()
.doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN);
.expectHeader().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN);
}
@Test

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

@ -138,7 +138,7 @@ public class WebMvcEndpointCorsIntegrationTests { @@ -138,7 +138,7 @@ public class WebMvcEndpointCorsIntegrationTests {
.of("management.endpoints.web.cors.allowed-origins:foo.example.com")
.applyTo(this.context);
createMockMvc()
.perform(options("/actuator/health")
.perform(options("/actuator/beans")
.header(HttpHeaders.ORIGIN, "foo.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "PATCH"))
.andExpect(status().isForbidden());

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

@ -190,6 +190,11 @@ public abstract class AbstractWebFluxEndpointHandlerMapping @@ -190,6 +190,11 @@ public abstract class AbstractWebFluxEndpointHandlerMapping
.findMethod(linksHandler.getClass(), "links", ServerWebExchange.class));
}
@Override
protected boolean hasCorsConfigurationSource(Object handler) {
return this.corsConfiguration != null;
}
@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
RequestMappingInfo mapping) {

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

@ -117,6 +117,11 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi @@ -117,6 +117,11 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi
mapping.getCustomCondition());
}
@Override
protected boolean hasCorsConfigurationSource(Object handler) {
return this.corsConfiguration != null;
}
@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
RequestMappingInfo mapping) {

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

@ -217,6 +217,11 @@ public abstract class AbstractWebMvcEndpointHandlerMapping @@ -217,6 +217,11 @@ public abstract class AbstractWebMvcEndpointHandlerMapping
builderConfig.useTrailingSlashMatch());
}
@Override
protected boolean hasCorsConfigurationSource(Object handler) {
return this.corsConfiguration != null;
}
@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
RequestMappingInfo mapping) {

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

@ -118,6 +118,11 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi @@ -118,6 +118,11 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi
mapping.getCustomCondition());
}
@Override
protected boolean hasCorsConfigurationSource(Object handler) {
return this.corsConfiguration != null;
}
@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
RequestMappingInfo mapping) {

Loading…
Cancel
Save