parent
ff73a4d0bb
commit
eb4498d788
|
@ -65,7 +65,6 @@ include "spring-boot-project:spring-boot-actuator-integration-tests"
|
|||
include "spring-boot-project:spring-boot-amqp"
|
||||
include "spring-boot-project:spring-boot-artemis"
|
||||
include "spring-boot-project:spring-boot-autoconfigure"
|
||||
include "spring-boot-project:spring-boot-autoconfigure-all"
|
||||
include "spring-boot-project:spring-boot-batch"
|
||||
include "spring-boot-project:spring-boot-cache"
|
||||
include "spring-boot-project:spring-boot-cassandra"
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
plugins {
|
||||
id "java-library"
|
||||
id "org.springframework.boot.deployed"
|
||||
id "org.springframework.boot.optional-dependencies"
|
||||
}
|
||||
|
||||
description = "Spring Boot AutoConfigure All"
|
||||
|
||||
dependencies {
|
||||
api(project(":spring-boot-project:spring-boot"))
|
||||
api(project(":spring-boot-project:spring-boot-autoconfigure"))
|
||||
|
||||
optional(project(":spring-boot-project:spring-boot-web-server"))
|
||||
optional("jakarta.servlet:jakarta.servlet-api")
|
||||
optional("org.springframework:spring-webmvc")
|
||||
|
||||
testImplementation(project(":spring-boot-project:spring-boot-data-redis"))
|
||||
testImplementation(project(":spring-boot-project:spring-boot-http-converter"))
|
||||
testImplementation(project(":spring-boot-project:spring-boot-jetty"))
|
||||
testImplementation(project(":spring-boot-project:spring-boot-security"))
|
||||
testImplementation(project(":spring-boot-project:spring-boot-servlet"))
|
||||
testImplementation(project(":spring-boot-project:spring-boot-session-data-redis"))
|
||||
testImplementation(project(":spring-boot-project:spring-boot-test"))
|
||||
testImplementation(project(":spring-boot-project:spring-boot-tomcat"))
|
||||
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
|
||||
testImplementation(project(":spring-boot-project:spring-boot-undertow"))
|
||||
testImplementation(project(":spring-boot-project:spring-boot-webmvc"))
|
||||
testImplementation(testFixtures(project(":spring-boot-project:spring-boot-web-server")))
|
||||
|
||||
testRuntimeOnly("org.apache.httpcomponents.client5:httpclient5")
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* 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.autoconfigure.web.servlet;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import jakarta.servlet.Filter;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.http.converter.autoconfigure.HttpMessageConvertersAutoConfiguration;
|
||||
import org.springframework.boot.security.autoconfigure.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.servlet.autoconfigure.HttpEncodingAutoConfiguration;
|
||||
import org.springframework.boot.servlet.filter.OrderedCharacterEncodingFilter;
|
||||
import org.springframework.boot.servlet.filter.OrderedRequestContextFilter;
|
||||
import org.springframework.boot.session.autoconfigure.SessionAutoConfiguration;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor;
|
||||
import org.springframework.boot.web.server.servlet.MockServletWebServer.RegisteredFilter;
|
||||
import org.springframework.boot.web.server.servlet.MockServletWebServerFactory;
|
||||
import org.springframework.boot.web.server.servlet.context.AnnotationConfigServletWebServerApplicationContext;
|
||||
import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.security.web.FilterChainProxy;
|
||||
import org.springframework.session.MapSessionRepository;
|
||||
import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession;
|
||||
import org.springframework.web.filter.DelegatingFilterProxy;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Integration tests that verify the ordering of various filters that are auto-configured.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
class FilterOrderingIntegrationTests {
|
||||
|
||||
private AnnotationConfigServletWebServerApplicationContext context;
|
||||
|
||||
@AfterEach
|
||||
void cleanup() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFilterOrdering() {
|
||||
load();
|
||||
List<RegisteredFilter> registeredFilters = this.context.getBean(MockServletWebServerFactory.class)
|
||||
.getWebServer()
|
||||
.getRegisteredFilters();
|
||||
assertThat(registeredFilters.get(0).getFilter()).isInstanceOf(OrderedCharacterEncodingFilter.class);
|
||||
assertThat(registeredFilters.get(1).getFilter()).isInstanceOf(DelegatingFilterProxy.class)
|
||||
.extracting("targetBeanName")
|
||||
.isEqualTo("springSessionRepositoryFilter");
|
||||
assertThat(registeredFilters.get(2).getFilter()).isInstanceOf(Filter.class)
|
||||
.extracting("beanName")
|
||||
.isEqualTo("hiddenHttpMethodFilter");
|
||||
assertThat(registeredFilters.get(3).getFilter()).isInstanceOf(Filter.class)
|
||||
.extracting("beanName")
|
||||
.isEqualTo("formContentFilter");
|
||||
assertThat(registeredFilters.get(4).getFilter()).isInstanceOf(OrderedRequestContextFilter.class);
|
||||
assertThat(registeredFilters.get(5).getFilter()).isInstanceOf(FilterChainProxy.class);
|
||||
}
|
||||
|
||||
private void load() {
|
||||
this.context = new AnnotationConfigServletWebServerApplicationContext();
|
||||
this.context.register(MockWebServerConfiguration.class, TestSessionConfiguration.class,
|
||||
TestRedisConfiguration.class, WebMvcAutoConfiguration.class, SecurityAutoConfiguration.class,
|
||||
SessionAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, HttpEncodingAutoConfiguration.class);
|
||||
TestPropertyValues.of("spring.mvc.hiddenmethod.filter.enabled:true").applyTo(this.context);
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class MockWebServerConfiguration {
|
||||
|
||||
@Bean
|
||||
MockServletWebServerFactory webServerFactory() {
|
||||
return new MockServletWebServerFactory();
|
||||
}
|
||||
|
||||
@Bean
|
||||
static WebServerFactoryCustomizerBeanPostProcessor servletWebServerCustomizerBeanPostProcessor() {
|
||||
return new WebServerFactoryCustomizerBeanPostProcessor();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableSpringHttpSession
|
||||
static class TestSessionConfiguration {
|
||||
|
||||
@Bean
|
||||
MapSessionRepository mapSessionRepository() {
|
||||
return new MapSessionRepository(new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class TestRedisConfiguration {
|
||||
|
||||
@Bean
|
||||
RedisConnectionFactory redisConnectionFactory() {
|
||||
RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class);
|
||||
RedisConnection connection = mock(RedisConnection.class);
|
||||
given(connectionFactory.getConnection()).willReturn(connection);
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<include resource="org/springframework/boot/logging/logback/base.xml"/>
|
||||
</configuration>
|
|
@ -40,11 +40,11 @@ artifacts {
|
|||
|
||||
dependencies {
|
||||
api(project(":spring-boot-project:spring-boot"))
|
||||
api(project(":spring-boot-project:spring-boot-autoconfigure-all"))
|
||||
api(project(":spring-boot-project:spring-boot-autoconfigure"))
|
||||
|
||||
intTestDependencies(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
|
||||
|
||||
intTestImplementation(project(":spring-boot-project:spring-boot-autoconfigure-all"))
|
||||
intTestImplementation(project(":spring-boot-project:spring-boot-autoconfigure"))
|
||||
intTestImplementation(project(":spring-boot-project:spring-boot-restclient"))
|
||||
intTestImplementation(project(":spring-boot-project:spring-boot-test"))
|
||||
intTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
|
||||
|
|
|
@ -57,7 +57,6 @@ dependencies {
|
|||
optional(project(":spring-boot-project:spring-boot-activemq"))
|
||||
optional(project(":spring-boot-project:spring-boot-amqp"))
|
||||
optional(project(":spring-boot-project:spring-boot-artemis"))
|
||||
optional(project(":spring-boot-project:spring-boot-autoconfigure-all"))
|
||||
optional(project(":spring-boot-project:spring-boot-actuator-autoconfigure-all"))
|
||||
optional(project(":spring-boot-project:spring-boot-cassandra"))
|
||||
optional(project(":spring-boot-project:spring-boot-data-redis"))
|
||||
|
|
|
@ -249,7 +249,6 @@ dependencies {
|
|||
implementation(project(path: ":spring-boot-project:spring-boot-actuator-autoconfigure"))
|
||||
implementation(project(path: ":spring-boot-project:spring-boot-actuator-autoconfigure-all"))
|
||||
implementation(project(path: ":spring-boot-project:spring-boot-amqp"))
|
||||
implementation(project(path: ":spring-boot-project:spring-boot-autoconfigure-all"))
|
||||
implementation(project(path: ":spring-boot-project:spring-boot-cache"))
|
||||
implementation(project(path: ":spring-boot-project:spring-boot-data-cassandra"))
|
||||
implementation(project(path: ":spring-boot-project:spring-boot-data-elasticsearch"))
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.boot.security.autoconfigure.servlet;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
|
@ -26,13 +27,17 @@ import org.springframework.boot.security.autoconfigure.servlet.SecurityFilterAut
|
|||
import org.springframework.boot.security.autoconfigure.servlet.SecurityFilterAutoConfigurationEarlyInitializationTests.DeserializerBean;
|
||||
import org.springframework.boot.security.autoconfigure.servlet.SecurityFilterAutoConfigurationEarlyInitializationTests.ExampleController;
|
||||
import org.springframework.boot.security.autoconfigure.servlet.SecurityFilterAutoConfigurationEarlyInitializationTests.JacksonModuleBean;
|
||||
import org.springframework.boot.servlet.filter.OrderedRequestContextFilter;
|
||||
import org.springframework.boot.web.context.servlet.AnnotationConfigServletWebApplicationContext;
|
||||
import org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean;
|
||||
import org.springframework.boot.webmvc.autoconfigure.DispatcherServletAutoConfiguration;
|
||||
import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SecurityFilterAutoConfiguration}.
|
||||
*
|
||||
|
@ -49,6 +54,20 @@ class SecurityFilterAutoConfigurationTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void filterIsOrderedShortlyAfterRequestContextFilter() {
|
||||
try (AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext()) {
|
||||
context.setServletContext(new MockServletContext());
|
||||
context.register(SecurityAutoConfiguration.class);
|
||||
context.register(Config.class);
|
||||
context.refresh();
|
||||
int securityFilterOrder = context.getBean(DelegatingFilterProxyRegistrationBean.class).getOrder();
|
||||
int requestContextFilterOrder = new OrderedRequestContextFilter().getOrder();
|
||||
assertThat(securityFilterOrder).isGreaterThan(requestContextFilterOrder)
|
||||
.isCloseTo(requestContextFilterOrder, Assertions.within(5));
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import({ DeserializerBean.class, JacksonModuleBean.class, ExampleController.class, ConverterBean.class })
|
||||
@ImportAutoConfiguration({ WebMvcAutoConfiguration.class, JacksonAutoConfiguration.class,
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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.servlet.filter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for the ordering of various {@link OrderedFilter} implementations.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class OrderedFilterOrderingTests {
|
||||
|
||||
@Test
|
||||
void ordering() {
|
||||
OrderedCharacterEncodingFilter characterEncoding = new OrderedCharacterEncodingFilter();
|
||||
OrderedFormContentFilter formContent = new OrderedFormContentFilter();
|
||||
OrderedHiddenHttpMethodFilter hiddenHttpMethod = new OrderedHiddenHttpMethodFilter();
|
||||
OrderedRequestContextFilter requestContext = new OrderedRequestContextFilter();
|
||||
List<OrderedFilter> filters = new ArrayList<>(
|
||||
List.of(characterEncoding, formContent, hiddenHttpMethod, requestContext));
|
||||
AnnotationAwareOrderComparator.sort(filters);
|
||||
assertThat(filters).containsExactly(characterEncoding, hiddenHttpMethod, formContent, requestContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestContextOrderingIsCloseToRequestWrapperFilterMaxOrder() {
|
||||
assertThat(new OrderedRequestContextFilter().getOrder())
|
||||
.isCloseTo(OrderedFilter.REQUEST_WRAPPER_FILTER_MAX_ORDER, Assertions.within(105));
|
||||
}
|
||||
|
||||
}
|
|
@ -19,8 +19,11 @@ package org.springframework.boot.session.autoconfigure;
|
|||
import java.time.Duration;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -32,22 +35,28 @@ import static org.mockito.Mockito.mock;
|
|||
*/
|
||||
class SessionPropertiesTests {
|
||||
|
||||
private final SessionProperties properties = new SessionProperties();
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void determineTimeoutWithTimeoutIgnoreFallback() {
|
||||
SessionProperties properties = new SessionProperties();
|
||||
properties.setTimeout(Duration.ofMinutes(1));
|
||||
this.properties.setTimeout(Duration.ofMinutes(1));
|
||||
Supplier<Duration> fallback = mock(Supplier.class);
|
||||
assertThat(properties.determineTimeout(fallback)).isEqualTo(Duration.ofMinutes(1));
|
||||
assertThat(this.properties.determineTimeout(fallback)).isEqualTo(Duration.ofMinutes(1));
|
||||
then(fallback).shouldHaveNoInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
void determineTimeoutWithNoTimeoutUseFallback() {
|
||||
SessionProperties properties = new SessionProperties();
|
||||
properties.setTimeout(null);
|
||||
this.properties.setTimeout(null);
|
||||
Duration fallback = Duration.ofMinutes(2);
|
||||
assertThat(properties.determineTimeout(() -> fallback)).isSameAs(fallback);
|
||||
assertThat(this.properties.determineTimeout(() -> fallback)).isSameAs(fallback);
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultFilterOrderIsCloseToHighestPrecedence() {
|
||||
assertThat(this.properties.getServlet().getFilterOrder()).isCloseTo(Ordered.HIGHEST_PRECEDENCE,
|
||||
Assertions.within(50));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ description = "Core starter, including auto-configuration support, logging and Y
|
|||
|
||||
dependencies {
|
||||
api(project(":spring-boot-project:spring-boot"))
|
||||
api(project(":spring-boot-project:spring-boot-autoconfigure-all"))
|
||||
api(project(":spring-boot-project:spring-boot-autoconfigure"))
|
||||
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-logging"))
|
||||
api("jakarta.annotation:jakarta.annotation-api")
|
||||
api("org.springframework:spring-core")
|
||||
|
|
|
@ -33,8 +33,8 @@ configurations.all {
|
|||
|
||||
dependencies {
|
||||
api(project(":spring-boot-project:spring-boot"))
|
||||
api(project(":spring-boot-project:spring-boot-autoconfigure"))
|
||||
api(project(":spring-boot-project:spring-boot-test"))
|
||||
api(project(":spring-boot-project:spring-boot-autoconfigure-all"))
|
||||
|
||||
dockerTestImplementation(project(":spring-boot-project:spring-boot-data-mongodb"))
|
||||
dockerTestImplementation(project(":spring-boot-project:spring-boot-docker-compose"))
|
||||
|
|
Loading…
Reference in New Issue