diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/AutoConfigureMockMvc.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/AutoConfigureMockMvc.java index fd61d76008..53128b012f 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/AutoConfigureMockMvc.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/AutoConfigureMockMvc.java @@ -85,13 +85,4 @@ public @interface AutoConfigureMockMvc { @PropertyMapping("webdriver.enabled") boolean webDriverEnabled() default true; - /** - * If Spring Security's {@link MockMvc} support should be auto-configured when it is - * on the classpath. Defaults to {@code true}. - * @return if Spring Security's MockMvc support is auto-configured - * @deprecated since 2.1.0 in favor of Spring Security's testing support - */ - @Deprecated - boolean secure() default true; - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcSecurityAutoConfiguration.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcSecurityAutoConfiguration.java deleted file mode 100644 index 87b007be4d..0000000000 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcSecurityAutoConfiguration.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2012-2018 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 - * - * http://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.test.autoconfigure.web.servlet; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; -import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Auto-configuration for Spring Security's testing support. - * - * @author Andy Wilkinson - * @since 1.4.0 - */ -@Configuration -@ConditionalOnProperty(prefix = "spring.test.mockmvc", name = "secure", havingValue = "true", matchIfMissing = true) -@Import({ SecurityAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class, - MockMvcSecurityConfiguration.class }) -public class MockMvcSecurityAutoConfiguration { - -} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java index f1fe4ba56d..7eb9a9382e 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java @@ -139,18 +139,6 @@ public @interface WebMvcTest { */ Filter[] excludeFilters() default {}; - /** - * If Spring Security's {@link MockMvc} support should be auto-configured when it is - * on the classpath. Also determines if - * {@link org.springframework.security.config.annotation.web.WebSecurityConfigurer} - * classes should be included in the application context. Defaults to {@code true}. - * @return if Spring Security's MockMvc support is auto-configured - * @deprecated since 2.1.0 in favor of Spring Security's testing support - */ - @Deprecated - @AliasFor(annotation = AutoConfigureMockMvc.class) - boolean secure() default true; - /** * Auto-configuration exclusions that should be applied for this test. * @return auto-configuration exclusions to apply diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilter.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilter.java index cb59cdf061..683e927290 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilter.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilter.java @@ -47,7 +47,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; */ class WebMvcTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter { - private static final String SECURITY_CONFIGURER = "org.springframework.security.config.annotation.web.WebSecurityConfigurer"; + private static final String[] OPTIONAL_INCLUDES = { + "org.springframework.security.config.annotation.web.WebSecurityConfigurer" }; private static final Set> DEFAULT_INCLUDES; @@ -64,21 +65,17 @@ class WebMvcTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter { includes.add(ErrorAttributes.class); includes.add(Converter.class); includes.add(GenericConverter.class); + for (String optionalInclude : OPTIONAL_INCLUDES) { + try { + includes.add(ClassUtils.forName(optionalInclude, null)); + } + catch (Exception ex) { + // Ignore + } + } DEFAULT_INCLUDES = Collections.unmodifiableSet(includes); } - private static final Set> DEFAULT_INCLUDES_AND_SECURITY_CONFIGURER; - - static { - Set> includes = new LinkedHashSet<>(DEFAULT_INCLUDES); - try { - includes.add(ClassUtils.forName(SECURITY_CONFIGURER, null)); - } - catch (Exception ex) { - } - DEFAULT_INCLUDES_AND_SECURITY_CONFIGURER = Collections.unmodifiableSet(includes); - } - private static final Set> DEFAULT_INCLUDES_AND_CONTROLLER; static { @@ -87,16 +84,6 @@ class WebMvcTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter { DEFAULT_INCLUDES_AND_CONTROLLER = Collections.unmodifiableSet(includes); } - private static final Set> DEFAULT_INCLUDES_SECURITY_CONFIGURER_AND_CONTROLLER; - - static { - Set> includes = new LinkedHashSet<>( - DEFAULT_INCLUDES_AND_SECURITY_CONFIGURER); - includes.add(Controller.class); - DEFAULT_INCLUDES_SECURITY_CONFIGURER_AND_CONTROLLER = Collections - .unmodifiableSet(includes); - } - private final WebMvcTest annotation; WebMvcTypeExcludeFilter(Class testClass) { @@ -128,12 +115,6 @@ class WebMvcTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter { @Override @SuppressWarnings("deprecation") protected Set> getDefaultIncludes() { - if (this.annotation.secure()) { - if (ObjectUtils.isEmpty(this.annotation.controllers())) { - return DEFAULT_INCLUDES_SECURITY_CONFIGURER_AND_CONTROLLER; - } - return DEFAULT_INCLUDES_AND_SECURITY_CONFIGURER; - } if (ObjectUtils.isEmpty(this.annotation.controllers())) { return DEFAULT_INCLUDES_AND_CONTROLLER; } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories index 4ef428df7f..3ccbafe309 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories @@ -102,9 +102,11 @@ org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration # AutoConfigureMockMvc auto-configuration imports org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc=\ org.springframework.boot.test.autoconfigure.web.servlet.MockMvcAutoConfiguration,\ -org.springframework.boot.test.autoconfigure.web.servlet.MockMvcSecurityAutoConfiguration,\ org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebClientAutoConfiguration,\ -org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebDriverAutoConfiguration +org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebDriverAutoConfiguration,\ +org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,\ +org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,\ +org.springframework.boot.test.autoconfigure.web.servlet.MockMvcSecurityConfiguration # AutoConfigureMockRestServiceServer org.springframework.boot.test.autoconfigure.web.client.AutoConfigureMockRestServiceServer=\ diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/MockMvcSecurityAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/MockMvcSecurityIntegrationTests.java similarity index 90% rename from spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/MockMvcSecurityAutoConfigurationIntegrationTests.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/MockMvcSecurityIntegrationTests.java index 95b4700567..77becde14a 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/MockMvcSecurityAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/MockMvcSecurityIntegrationTests.java @@ -20,7 +20,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.MockMvcSecurityAutoConfiguration; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -34,14 +33,14 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /** - * Integration tests for {@link MockMvcSecurityAutoConfiguration}. + * Integration tests for MockMvc security. * * @author Andy Wilkinson */ @WebMvcTest @RunWith(SpringRunner.class) @TestPropertySource(properties = { "debug=true" }) -public class MockMvcSecurityAutoConfigurationIntegrationTests { +public class MockMvcSecurityIntegrationTests { @Autowired private MockMvc mockMvc; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/SecurityTestApplication.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/SecurityTestApplication.java index f49d31e726..b654d46636 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/SecurityTestApplication.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/security/SecurityTestApplication.java @@ -17,13 +17,12 @@ package org.springframework.boot.test.autoconfigure.security; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.autoconfigure.web.servlet.MockMvcSecurityAutoConfiguration; import org.springframework.security.access.annotation.Secured; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** - * Tests application for {@link MockMvcSecurityAutoConfiguration}. + * Tests application for MockMvc Security. * * @author Andy Wilkinson */ diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java index a082bd6a69..105b0dcf11 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java @@ -113,20 +113,6 @@ public class WebMvcTypeExcludeFilterTests { assertThat(excludes(filter, ExampleWebSecurityConfigurer.class)).isFalse(); } - @Test - public void matchWhenSecureFalse() throws Exception { - WebMvcTypeExcludeFilter filter = new WebMvcTypeExcludeFilter( - WithSecureFalse.class); - assertThat(excludes(filter, Controller1.class)).isFalse(); - assertThat(excludes(filter, Controller2.class)).isFalse(); - assertThat(excludes(filter, ExampleControllerAdvice.class)).isFalse(); - assertThat(excludes(filter, ExampleWeb.class)).isFalse(); - assertThat(excludes(filter, ExampleMessageConverter.class)).isFalse(); - assertThat(excludes(filter, ExampleService.class)).isTrue(); - assertThat(excludes(filter, ExampleRepository.class)).isTrue(); - assertThat(excludes(filter, ExampleWebSecurityConfigurer.class)).isTrue(); - } - private boolean excludes(WebMvcTypeExcludeFilter filter, Class type) throws IOException { MetadataReader metadataReader = this.metadataReaderFactory @@ -159,11 +145,6 @@ public class WebMvcTypeExcludeFilterTests { } - @WebMvcTest(secure = false) - static class WithSecureFalse { - - } - @Controller static class Controller1 {