Adapt to latest changes in Spring Security snapshots

See https://github.com/spring-projects/spring-security/issues/17746
This commit is contained in:
Stéphane Nicoll
2025-08-18 16:28:07 +02:00
parent 49a588f80a
commit 4e425a9b4d
2 changed files with 7 additions and 21 deletions
@@ -16,9 +16,6 @@
package org.springframework.boot.security.autoconfigure.servlet;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -53,23 +50,12 @@ class SpringBootWebSecurityConfiguration {
static class PathPatternRequestMatcherBuilderConfiguration {
@Bean
static BeanPostProcessor pathPatternRequestMatcherBuilderBasePathCustomizer(
ObjectProvider<DispatcherServletPath> dispatcherServletPath) {
return new BeanPostProcessor() {
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if ("pathPatternRequestMatcherBuilder".equals(beanName)
&& bean instanceof PathPatternRequestMatcher.Builder builder) {
String path = dispatcherServletPath.getObject().getPath();
if (!path.equals("/")) {
return builder.basePath(path);
}
}
return bean;
}
};
@ConditionalOnMissingBean
PathPatternRequestMatcher.Builder pathPatternRequestMatcherBuilder(
DispatcherServletPath dispatcherServletPath) {
PathPatternRequestMatcher.Builder builder = PathPatternRequestMatcher.withDefaults();
String path = dispatcherServletPath.getPath();
return (!path.equals("/")) ? builder.basePath(path) : builder;
}
}
@@ -228,7 +228,7 @@ class SecurityAutoConfigurationTests {
}
@Test
void givenACustomPathPatternRequestMatcherBuilderwhenDispatcherServletPathIsSetBuilderBasePathIsNotCustomized() {
void givenACustomPathPatternRequestMatcherBuilderWhenDispatcherServletPathIsSetBuilderBasePathIsNotCustomized() {
this.contextRunner.withBean(PathPatternRequestMatcherBuilderFactoryBean.class)
.withBean(DispatcherServletPath.class, () -> () -> "/dispatcher-servlet")
.run((context) -> {