Skip to content

Commit 4e425a9

Browse files
committed
Adapt to latest changes in Spring Security snapshots
See spring-projects/spring-security#17746
1 parent 49a588f commit 4e425a9

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/servlet/SpringBootWebSecurityConfiguration.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
package org.springframework.boot.security.autoconfigure.servlet;
1818

19-
import org.springframework.beans.BeansException;
20-
import org.springframework.beans.factory.ObjectProvider;
21-
import org.springframework.beans.factory.config.BeanPostProcessor;
2219
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2320
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2421
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -53,23 +50,12 @@ class SpringBootWebSecurityConfiguration {
5350
static class PathPatternRequestMatcherBuilderConfiguration {
5451

5552
@Bean
56-
static BeanPostProcessor pathPatternRequestMatcherBuilderBasePathCustomizer(
57-
ObjectProvider<DispatcherServletPath> dispatcherServletPath) {
58-
return new BeanPostProcessor() {
59-
60-
@Override
61-
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
62-
if ("pathPatternRequestMatcherBuilder".equals(beanName)
63-
&& bean instanceof PathPatternRequestMatcher.Builder builder) {
64-
String path = dispatcherServletPath.getObject().getPath();
65-
if (!path.equals("/")) {
66-
return builder.basePath(path);
67-
}
68-
}
69-
return bean;
70-
}
71-
72-
};
53+
@ConditionalOnMissingBean
54+
PathPatternRequestMatcher.Builder pathPatternRequestMatcherBuilder(
55+
DispatcherServletPath dispatcherServletPath) {
56+
PathPatternRequestMatcher.Builder builder = PathPatternRequestMatcher.withDefaults();
57+
String path = dispatcherServletPath.getPath();
58+
return (!path.equals("/")) ? builder.basePath(path) : builder;
7359
}
7460

7561
}

module/spring-boot-security/src/test/java/org/springframework/boot/security/autoconfigure/servlet/SecurityAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void whenDispatcherServletPathIsSetPathPatternRequestMatcherBuilderHasCustomBase
228228
}
229229

230230
@Test
231-
void givenACustomPathPatternRequestMatcherBuilderwhenDispatcherServletPathIsSetBuilderBasePathIsNotCustomized() {
231+
void givenACustomPathPatternRequestMatcherBuilderWhenDispatcherServletPathIsSetBuilderBasePathIsNotCustomized() {
232232
this.contextRunner.withBean(PathPatternRequestMatcherBuilderFactoryBean.class)
233233
.withBean(DispatcherServletPath.class, () -> () -> "/dispatcher-servlet")
234234
.run((context) -> {

0 commit comments

Comments
 (0)