Search in sources :

Example 6 with RemoteIpValve

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");
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) HashMap(java.util.HashMap) Valve(org.apache.catalina.Valve) AccessLogValve(org.apache.catalina.valves.AccessLogValve) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) Test(org.junit.Test)

Example 7 with RemoteIpValve

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");
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) ErrorReportValve(org.apache.catalina.valves.ErrorReportValve) Valve(org.apache.catalina.Valve) AccessLogValve(org.apache.catalina.valves.AccessLogValve) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) Test(org.junit.jupiter.api.Test)

Example 8 with RemoteIpValve

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);
}
Also used : RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) Test(org.junit.jupiter.api.Test)

Aggregations

RemoteIpValve (org.apache.catalina.valves.RemoteIpValve)8 Valve (org.apache.catalina.Valve)4 AccessLogValve (org.apache.catalina.valves.AccessLogValve)4 TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)4 Test (org.junit.jupiter.api.Test)3 ErrorReportValve (org.apache.catalina.valves.ErrorReportValve)2 HashMap (java.util.HashMap)1 Context (org.apache.catalina.Context)1 TesterMapRealm (org.apache.catalina.startup.TesterMapRealm)1 TesterServlet (org.apache.catalina.startup.TesterServlet)1 Tomcat (org.apache.catalina.startup.Tomcat)1 LoginConfig (org.apache.tomcat.util.descriptor.web.LoginConfig)1 SecurityCollection (org.apache.tomcat.util.descriptor.web.SecurityCollection)1 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)1 Test (org.junit.Test)1 Remoteip (org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Remoteip)1