From 472afafd4bc351f139716edf8b899a5a79df6808 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 25 Apr 2023 11:22:33 +0100 Subject: [PATCH] Stop WebFilterChainPostProcessor from causing eager init Fixes gh-35163 --- ...tiveCloudFoundryActuatorAutoConfiguration.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfiguration.java index 1548bbbb10..dd109244b6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfiguration.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.function.Supplier; import java.util.stream.Collectors; import org.springframework.beans.BeansException; @@ -64,6 +65,7 @@ import org.springframework.security.web.server.MatcherSecurityWebFilterChain; import org.springframework.security.web.server.WebFilterChainProxy; import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher; import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers; +import org.springframework.util.function.SingletonSupplier; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.server.WebFilter; @@ -155,8 +157,8 @@ public class ReactiveCloudFoundryActuatorAutoConfiguration { static class IgnoredPathsSecurityConfiguration { @Bean - WebFilterChainPostProcessor webFilterChainPostProcessor( - CloudFoundryWebFluxEndpointHandlerMapping handlerMapping) { + static WebFilterChainPostProcessor webFilterChainPostProcessor( + ObjectProvider handlerMapping) { return new WebFilterChainPostProcessor(handlerMapping); } @@ -164,16 +166,17 @@ public class ReactiveCloudFoundryActuatorAutoConfiguration { static class WebFilterChainPostProcessor implements BeanPostProcessor { - private final PathMappedEndpoints pathMappedEndpoints; + private Supplier pathMappedEndpoints; - WebFilterChainPostProcessor(CloudFoundryWebFluxEndpointHandlerMapping handlerMapping) { - this.pathMappedEndpoints = new PathMappedEndpoints(BASE_PATH, handlerMapping::getAllEndpoints); + WebFilterChainPostProcessor(ObjectProvider handlerMapping) { + this.pathMappedEndpoints = SingletonSupplier + .of(() -> new PathMappedEndpoints(BASE_PATH, () -> handlerMapping.getObject().getAllEndpoints())); } @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof WebFilterChainProxy) { - return postProcess((WebFilterChainProxy) bean, this.pathMappedEndpoints); + return postProcess((WebFilterChainProxy) bean, this.pathMappedEndpoints.get()); } return bean; }