use of org.apache.catalina.valves.RemoteIpValve in project spring-boot by spring-projects.
the class DefaultServletWebServerFactoryCustomizerTests method customTomcatRemoteIpValve.
@Test
public void customTomcatRemoteIpValve() throws Exception {
Map<String, String> map = new HashMap<>();
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.internal_proxies", "192.168.0.1");
map.put("server.tomcat.port-header", "x-my-forward-port");
map.put("server.tomcat.protocol-header-https-value", "On");
bindProperties(map);
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
this.customizer.customize(factory);
assertThat(factory.getEngineValves()).hasSize(1);
Valve valve = factory.getEngineValves().iterator().next();
assertThat(valve).isInstanceOf(RemoteIpValve.class);
RemoteIpValve remoteIpValve = (RemoteIpValve) valve;
assertThat(remoteIpValve.getProtocolHeader()).isEqualTo("x-my-protocol-header");
assertThat(remoteIpValve.getProtocolHeaderHttpsValue()).isEqualTo("On");
assertThat(remoteIpValve.getRemoteIpHeader()).isEqualTo("x-my-remote-ip-header");
assertThat(remoteIpValve.getPortHeader()).isEqualTo("x-my-forward-port");
assertThat(remoteIpValve.getInternalProxies()).isEqualTo("192.168.0.1");
}
use of org.apache.catalina.valves.RemoteIpValve in project spring-boot by spring-projects.
the class TomcatWebServerFactoryCustomizerTests method customRemoteIpValve.
@Test
void customRemoteIpValve() {
bind("server.tomcat.remoteip.remote-ip-header=x-my-remote-ip-header", "server.tomcat.remoteip.protocol-header=x-my-protocol-header", "server.tomcat.remoteip.internal-proxies=192.168.0.1", "server.tomcat.remoteip.host-header=x-my-forward-host", "server.tomcat.remoteip.port-header=x-my-forward-port", "server.tomcat.remoteip.protocol-header-https-value=On");
TomcatServletWebServerFactory factory = customizeAndGetFactory();
assertThat(factory.getEngineValves()).hasSize(1);
Valve valve = factory.getEngineValves().iterator().next();
assertThat(valve).isInstanceOf(RemoteIpValve.class);
RemoteIpValve remoteIpValve = (RemoteIpValve) valve;
assertThat(remoteIpValve.getProtocolHeader()).isEqualTo("x-my-protocol-header");
assertThat(remoteIpValve.getProtocolHeaderHttpsValue()).isEqualTo("On");
assertThat(remoteIpValve.getRemoteIpHeader()).isEqualTo("x-my-remote-ip-header");
assertThat(remoteIpValve.getHostHeader()).isEqualTo("x-my-forward-host");
assertThat(remoteIpValve.getPortHeader()).isEqualTo("x-my-forward-port");
assertThat(remoteIpValve.getInternalProxies()).isEqualTo("192.168.0.1");
}
use of org.apache.catalina.valves.RemoteIpValve in project spring-boot by spring-projects.
the class TomcatServletWebServerFactoryTests method useForwardHeaders.
@Test
void useForwardHeaders() throws Exception {
TomcatServletWebServerFactory factory = getFactory();
factory.addContextValves(new RemoteIpValve());
assertForwardHeaderIsUsed(factory);
}
Aggregations