diff --git a/module/spring-boot-security-test/src/main/java/org/springframework/boot/security/test/autoconfigure/webmvc/SecurityMockMvcAutoConfiguration.java b/module/spring-boot-security-test/src/main/java/org/springframework/boot/security/test/autoconfigure/webmvc/SecurityMockMvcAutoConfiguration.java index 709bb6fa2c3..32c9b6b1387 100644 --- a/module/spring-boot-security-test/src/main/java/org/springframework/boot/security/test/autoconfigure/webmvc/SecurityMockMvcAutoConfiguration.java +++ b/module/spring-boot-security-test/src/main/java/org/springframework/boot/security/test/autoconfigure/webmvc/SecurityMockMvcAutoConfiguration.java @@ -23,6 +23,7 @@ import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.security.autoconfigure.web.servlet.ServletWebSecurityAutoConfiguration; import org.springframework.boot.webmvc.test.autoconfigure.MockMvcBuilderCustomizer; import org.springframework.boot.webmvc.test.autoconfigure.MockMvcHtmlUnitDriverCustomizer; import org.springframework.context.annotation.Bean; @@ -43,7 +44,7 @@ import org.springframework.web.context.WebApplicationContext; * @author Andy Wilkinson * @since 4.0.0 */ -@AutoConfiguration +@AutoConfiguration(after = ServletWebSecurityAutoConfiguration.class) @ConditionalOnClass(MockMvc.class) public final class SecurityMockMvcAutoConfiguration { diff --git a/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/MockMvcSecurityIntegrationTests.java b/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/MockMvcSecurityIntegrationTests.java index 5fec9408c76..9a7fc007a5b 100644 --- a/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/MockMvcSecurityIntegrationTests.java +++ b/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/MockMvcSecurityIntegrationTests.java @@ -18,6 +18,7 @@ package org.springframework.boot.security.test.autoconfigure.webmvc; import java.util.Base64; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -26,6 +27,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher; import org.springframework.test.context.TestPropertySource; import org.springframework.test.web.servlet.assertj.MockMvcTester; @@ -43,6 +45,9 @@ class MockMvcSecurityIntegrationTests { @Autowired private MockMvcTester mvc; + @Autowired + private PathPatternRequestMatcher.@Nullable Builder pathPatternRequestMatcherBuilder; + @Test @WithMockUser(username = "test", password = "test", roles = "USER") void okResponseWithMockUser() { @@ -62,4 +67,9 @@ class MockMvcSecurityIntegrationTests { .hasStatusOk(); } + @Test + void pathPatternRequestMatcherBuilderIsAvailable() { + assertThat(this.pathPatternRequestMatcherBuilder).isNotNull(); + } + } diff --git a/module/spring-boot-security/build.gradle b/module/spring-boot-security/build.gradle index f3eef8ea20c..76fe8512afc 100644 --- a/module/spring-boot-security/build.gradle +++ b/module/spring-boot-security/build.gradle @@ -39,6 +39,7 @@ dependencies { optional(project(":module:spring-boot-rsocket")) optional(project(":module:spring-boot-webflux")) optional(project(":module:spring-boot-webmvc")) + optional(project(":module:spring-boot-webmvc-test")) optional(project(":module:spring-boot-web-server")) optional("jakarta.servlet:jakarta.servlet-api") optional("org.springframework:spring-messaging") diff --git a/module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/web/servlet/ServletWebSecurityAutoConfiguration.java b/module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/web/servlet/ServletWebSecurityAutoConfiguration.java index a8ab62ce00a..b04fd53e0f5 100644 --- a/module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/web/servlet/ServletWebSecurityAutoConfiguration.java +++ b/module/spring-boot-security/src/main/java/org/springframework/boot/security/autoconfigure/web/servlet/ServletWebSecurityAutoConfiguration.java @@ -45,7 +45,8 @@ import static org.springframework.security.config.Customizer.withDefaults; * @since 4.0.0 */ @AutoConfiguration(after = UserDetailsServiceAutoConfiguration.class, - afterName = "org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration") + afterName = { "org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration", + "org.springframework.boot.webmvc.test.autoconfigure.MockMvcAutoConfiguration" }) @ConditionalOnClass(EnableWebSecurity.class) @ConditionalOnWebApplication(type = Type.SERVLET) public final class ServletWebSecurityAutoConfiguration {