From 2e3658fd91832fe14603a406e5d818676a0fb5b4 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 28 Sep 2015 13:58:29 +0100 Subject: [PATCH] Enable RemoteIpValve by default Fixes gh-3782 --- .../autoconfigure/web/ServerProperties.java | 8 ++--- .../web/ServerPropertiesTests.java | 29 ++++++++----------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index fe0e61f276d..0974871eaaf 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -484,9 +484,9 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord /** * Header that holds the incoming protocol, usually named "X-Forwarded-Proto". - * Configured as a RemoteIpValve only if remoteIpHeader is also set. + * Configures a RemoteIpValve only if remoteIpHeader is also set. */ - private String protocolHeader; + private String protocolHeader = "x-forwarded-proto"; /** * Value of the protocol header that indicates that the incoming request uses SSL. @@ -499,8 +499,8 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord private String portHeader = "x-forwarded-port"; /** - * Name of the http header from which the remote ip is extracted. Configured as a - * RemoteIpValve only if remoteIpHeader is also set. + * Name of the http header from which the remote ip is extracted. Configures a + * RemoteIpValve only if protocolHeader is also set. */ private String remoteIpHeader = "x-forwarded-for"; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index 646aff9ac98..6fd6054ba3b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -16,6 +16,17 @@ package org.springframework.boot.autoconfigure.web; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + import java.net.InetAddress; import java.nio.charset.Charset; import java.util.Collections; @@ -41,17 +52,6 @@ import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletCont import org.springframework.boot.context.embedded.ServletContextInitializer; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.instanceOf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; - /** * Tests for {@link ServerProperties}. * @@ -261,12 +261,7 @@ public class ServerPropertiesTests { @Test public void defaultTomcatRemoteIpValve() throws Exception { - Map map = new HashMap(); - // Since 1.1.7 you need to specify at least the protocol and ip properties - map.put("server.tomcat.protocol_header", "x-forwarded-proto"); - map.put("server.tomcat.remote_ip_header", "x-forwarded-for"); - bindProperties(map); - + // Since 1.3.0 no need to explicitly set header names TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(); this.properties.customize(container);