|
42 | 42 | import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
43 | 43 | import org.springframework.boot.testsupport.classpath.resources.WithResource;
|
44 | 44 | import org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean;
|
| 45 | +import org.springframework.boot.webmvc.autoconfigure.DispatcherServletPath; |
45 | 46 | import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration;
|
46 | 47 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
47 | 48 | import org.springframework.context.annotation.Bean;
|
|
52 | 53 | import org.springframework.security.authentication.DefaultAuthenticationEventPublisher;
|
53 | 54 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
54 | 55 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
| 56 | +import org.springframework.security.config.web.PathPatternRequestMatcherBuilderFactoryBean; |
55 | 57 | import org.springframework.security.core.Authentication;
|
56 | 58 | import org.springframework.security.core.AuthenticationException;
|
57 | 59 | import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension;
|
58 | 60 | import org.springframework.security.web.FilterChainProxy;
|
59 | 61 | import org.springframework.security.web.SecurityFilterChain;
|
| 62 | +import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher; |
60 | 63 |
|
61 | 64 | import static org.assertj.core.api.Assertions.assertThat;
|
62 | 65 |
|
@@ -216,6 +219,24 @@ void whenTheBeanFactoryHasAConversionServiceAndAConfigurationPropertyBindingConv
|
216 | 219 | .run((context) -> assertThat(context.getBean(JwtProperties.class).getPublicKey()).isNotNull());
|
217 | 220 | }
|
218 | 221 |
|
| 222 | + @Test |
| 223 | + void whenDispatcherServletPathIsSetPathPatternRequestMatcherBuilderHasCustomBasePath() { |
| 224 | + this.contextRunner.withBean(DispatcherServletPath.class, () -> () -> "/dispatcher-servlet").run((context) -> { |
| 225 | + PathPatternRequestMatcher.Builder builder = context.getBean(PathPatternRequestMatcher.Builder.class); |
| 226 | + assertThat(builder).extracting("basePath").isEqualTo("/dispatcher-servlet"); |
| 227 | + }); |
| 228 | + } |
| 229 | + |
| 230 | + @Test |
| 231 | + void givenACustomPathPatternRequestMatcherBuilderwhenDispatcherServletPathIsSetBuilderBasePathIsNotCustomized() { |
| 232 | + this.contextRunner.withBean(PathPatternRequestMatcherBuilderFactoryBean.class) |
| 233 | + .withBean(DispatcherServletPath.class, () -> () -> "/dispatcher-servlet") |
| 234 | + .run((context) -> { |
| 235 | + PathPatternRequestMatcher.Builder builder = context.getBean(PathPatternRequestMatcher.Builder.class); |
| 236 | + assertThat(builder).extracting("basePath").isEqualTo(""); |
| 237 | + }); |
| 238 | + } |
| 239 | + |
219 | 240 | @Configuration(proxyBeanMethods = false)
|
220 | 241 | @TestAutoConfigurationPackage(City.class)
|
221 | 242 | static class EntityConfiguration {
|
|
0 commit comments