diff --git a/module/spring-boot-security-test/src/main/resources/META-INF/spring/org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest.includes b/module/spring-boot-security-test/src/main/resources/META-INF/spring/org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest.includes index c40ed292025..ddf85561418 100644 --- a/module/spring-boot-security-test/src/main/resources/META-INF/spring/org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest.includes +++ b/module/spring-boot-security-test/src/main/resources/META-INF/spring/org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest.includes @@ -1 +1,3 @@ +org.springframework.security.config.annotation.web.WebSecurityConfigurer +org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer org.springframework.security.web.SecurityFilterChain diff --git a/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/ExampleWebSecurityConfigurer.java b/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/ExampleWebSecurityConfigurer.java new file mode 100644 index 00000000000..aa21122b514 --- /dev/null +++ b/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/ExampleWebSecurityConfigurer.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.security.test.autoconfigure.webmvc; + +import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; +import org.springframework.security.config.annotation.web.WebSecurityConfigurer; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.stereotype.Component; + +/** + * {@link WebSecurityConfigurer} used to test their inclusion in + * {@link WebMvcTest @WebMvcTest}. + * + * @author Andy Wilkinson + */ +@Component +class ExampleWebSecurityConfigurer implements WebSecurityConfigurer { + + @Override + public void init(WebSecurity builder) { + } + + @Override + public void configure(WebSecurity builder) { + } + +} diff --git a/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/ExampleWebSecurityCustomizer.java b/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/ExampleWebSecurityCustomizer.java new file mode 100644 index 00000000000..0681b74566b --- /dev/null +++ b/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/ExampleWebSecurityCustomizer.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.security.test.autoconfigure.webmvc; + +import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; +import org.springframework.stereotype.Component; + +/** + * {@link WebSecurityCustomizer} used to test their inclusion in + * {@link WebMvcTest @WebMvcTest}. + * + * @author Andy Wilkinson + */ +@Component +class ExampleWebSecurityCustomizer implements WebSecurityCustomizer { + + @Override + public void customize(WebSecurity web) { + } + +} diff --git a/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/SecurityWebMvcTestIntegrationTests.java b/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/SecurityWebMvcTestIntegrationTests.java new file mode 100644 index 00000000000..6aa619edaa4 --- /dev/null +++ b/module/spring-boot-security-test/src/test/java/org/springframework/boot/security/test/autoconfigure/webmvc/SecurityWebMvcTestIntegrationTests.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.security.test.autoconfigure.webmvc; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.assertj.AssertableApplicationContext; +import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.security.web.SecurityFilterChain; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for SpringSecurity with {@link WebMvcTest @WebMvcTest}. + * + * @author Andy Wilkinson + */ +@WebMvcTest +class SecurityWebMvcTestIntegrationTests { + + @Autowired + private ConfigurableApplicationContext context; + + @Test + void includesWebSecurityConfigurer() { + assertThat(AssertableApplicationContext.get(() -> this.context)) + .hasSingleBean(ExampleWebSecurityConfigurer.class); + } + + @Test + void includesWebSecurityCustomizer() { + assertThat(AssertableApplicationContext.get(() -> this.context)) + .hasSingleBean(ExampleWebSecurityCustomizer.class); + } + + @Test + void includesSecurityFilterChain() { + assertThat(AssertableApplicationContext.get(() -> this.context)).hasSingleBean(SecurityFilterChain.class); + } + +} diff --git a/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTypeExcludeFilter.java b/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTypeExcludeFilter.java index dd22845896d..b5276a39ded 100644 --- a/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTypeExcludeFilter.java +++ b/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/WebMvcTypeExcludeFilter.java @@ -50,9 +50,7 @@ class WebMvcTypeExcludeFilter extends StandardAnnotationCustomizableTypeExcludeF private static final Class[] NO_CONTROLLERS = {}; private static final String[] OPTIONAL_INCLUDES = { "tools.jackson.databind.JacksonModule", - "org.springframework.boot.jackson.JacksonComponent", - "org.springframework.security.config.annotation.web.WebSecurityConfigurer", - "org.springframework.security.web.SecurityFilterChain", "org.thymeleaf.dialect.IDialect", + "org.springframework.boot.jackson.JacksonComponent", "org.thymeleaf.dialect.IDialect", "com.fasterxml.jackson.databind.Module", "org.springframework.boot.jackson2.JsonComponent" }; private static final Set> KNOWN_INCLUDES;