Commit bff39e95 authored by Phillip Webb's avatar Phillip Webb

Add `server.tomcat.port-header` support

Update Tomcat ServerProperties to support the RemoteIpValve portHeader
property.

Fixes gh-1616
parent 0dc46a2f
...@@ -209,6 +209,8 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer { ...@@ -209,6 +209,8 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
private String protocolHeader; private String protocolHeader;
private String portHeader;
private String remoteIpHeader; private String remoteIpHeader;
private File basedir; private File basedir;
...@@ -285,6 +287,14 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer { ...@@ -285,6 +287,14 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
this.protocolHeader = protocolHeader; this.protocolHeader = protocolHeader;
} }
public String getPortHeader() {
return this.portHeader;
}
public void setPortHeader(String portHeader) {
this.portHeader = portHeader;
}
public String getRemoteIpHeader() { public String getRemoteIpHeader() {
return this.remoteIpHeader; return this.remoteIpHeader;
} }
...@@ -321,6 +331,7 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer { ...@@ -321,6 +331,7 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
valve.setRemoteIpHeader(remoteIpHeader); valve.setRemoteIpHeader(remoteIpHeader);
valve.setProtocolHeader(protocolHeader); valve.setProtocolHeader(protocolHeader);
valve.setInternalProxies(getInternalProxies()); valve.setInternalProxies(getInternalProxies());
valve.setPortHeader(getPortHeader());
factory.addContextValves(valve); factory.addContextValves(valve);
} }
......
...@@ -177,6 +177,7 @@ public class ServerPropertiesTests { ...@@ -177,6 +177,7 @@ public class ServerPropertiesTests {
map.put("server.tomcat.remote_ip_header", "x-my-remote-ip-header"); map.put("server.tomcat.remote_ip_header", "x-my-remote-ip-header");
map.put("server.tomcat.protocol_header", "x-my-protocol-header"); map.put("server.tomcat.protocol_header", "x-my-protocol-header");
map.put("server.tomcat.internal_proxies", "192.168.0.1"); map.put("server.tomcat.internal_proxies", "192.168.0.1");
map.put("server.tomcat.port-header", "x-my-forward-port");
bindProperties(map); bindProperties(map);
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(); TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
...@@ -188,6 +189,7 @@ public class ServerPropertiesTests { ...@@ -188,6 +189,7 @@ public class ServerPropertiesTests {
RemoteIpValve remoteIpValve = (RemoteIpValve) valve; RemoteIpValve remoteIpValve = (RemoteIpValve) valve;
assertEquals("x-my-protocol-header", remoteIpValve.getProtocolHeader()); assertEquals("x-my-protocol-header", remoteIpValve.getProtocolHeader());
assertEquals("x-my-remote-ip-header", remoteIpValve.getRemoteIpHeader()); assertEquals("x-my-remote-ip-header", remoteIpValve.getRemoteIpHeader());
assertEquals("x-my-forward-port", remoteIpValve.getPortHeader());
assertEquals("192.168.0.1", remoteIpValve.getInternalProxies()); assertEquals("192.168.0.1", remoteIpValve.getInternalProxies());
} }
......
...@@ -74,7 +74,8 @@ content into your application; rather pick only the properties that you need. ...@@ -74,7 +74,8 @@ content into your application; rather pick only the properties that you need.
192\.168\.\d{1,3}\.\d{1,3}|\ 192\.168\.\d{1,3}\.\d{1,3}|\
169\.254\.\d{1,3}\.\d{1,3}|\ 169\.254\.\d{1,3}\.\d{1,3}|\
127\.\d{1,3}\.\d{1,3}\.\d{1,3} # regular expression matching trusted IP addresses 127\.\d{1,3}\.\d{1,3}\.\d{1,3} # regular expression matching trusted IP addresses
server.tomcat.protocol-header=x-forwarded-proto # ssl forward headers server.tomcat.protocol-header=x-forwarded-proto # front end proxy forward header
server.tomcat.port-header= # front end proxy port header
server.tomcat.remote-ip-header=x-forwarded-for server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp) server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp)
server.tomcat.background-processor-delay=30; # in seconds server.tomcat.background-processor-delay=30; # in seconds
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment