Search in sources :

Example 1 with Valve

use of org.apache.catalina.Valve in project spring-boot by spring-projects.

the class DefaultServletWebServerFactoryCustomizerTests method testRemoteIpValveConfigured.

private void testRemoteIpValveConfigured() {
    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-Forwarded-Proto");
    assertThat(remoteIpValve.getProtocolHeaderHttpsValue()).isEqualTo("https");
    assertThat(remoteIpValve.getRemoteIpHeader()).isEqualTo("X-Forwarded-For");
    String expectedInternalProxies = // 10/8
    "10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|" + // 192.168/16
    "192\\.168\\.\\d{1,3}\\.\\d{1,3}|" + // 169.254/16
    "169\\.254\\.\\d{1,3}\\.\\d{1,3}|" + // 127/8
    "127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|" + // 172.16/12
    "172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|" + "172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|" + "172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3}";
    assertThat(remoteIpValve.getInternalProxies()).isEqualTo(expectedInternalProxies);
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) Valve(org.apache.catalina.Valve) AccessLogValve(org.apache.catalina.valves.AccessLogValve) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve)

Example 2 with Valve

use of org.apache.catalina.Valve in project ofbiz-framework by apache.

the class CatalinaContainer method prepareTomcatEngineValves.

private List<Valve> prepareTomcatEngineValves(Property engineConfig) throws ContainerException {
    List<Valve> engineValves = new ArrayList<>();
    // configure the CrossSubdomainSessionValve
    if (ContainerConfig.getPropertyValue(engineConfig, "enable-cross-subdomain-sessions", false)) {
        engineValves.add(new CrossSubdomainSessionValve());
    }
    // configure the SslAcceleratorValve
    String sslAcceleratorPortStr = ContainerConfig.getPropertyValue(engineConfig, "ssl-accelerator-port", null);
    if (UtilValidate.isNotEmpty(sslAcceleratorPortStr)) {
        Integer sslAcceleratorPort = Integer.valueOf(sslAcceleratorPortStr);
        SslAcceleratorValve sslAcceleratorValve = new SslAcceleratorValve();
        sslAcceleratorValve.setSslAcceleratorPort(sslAcceleratorPort);
        engineValves.add(sslAcceleratorValve);
    }
    // configure the AccessLogValve
    String logDir = ContainerConfig.getPropertyValue(engineConfig, "access-log-dir", null);
    if (logDir != null) {
        AccessLogValve accessLogValve = new AccessLogValve();
        logDir = logDir.startsWith("/") ? System.getProperty("ofbiz.home") + "/" + logDir : logDir;
        File logFile = new File(logDir);
        if (!logFile.isDirectory()) {
            throw new ContainerException("Log directory [" + logDir + "] is not available; make sure the directory is created");
        }
        accessLogValve.setDirectory(logFile.getAbsolutePath());
        String accessLogPattern = ContainerConfig.getPropertyValue(engineConfig, "access-log-pattern", null);
        if (UtilValidate.isNotEmpty(accessLogPattern)) {
            accessLogValve.setPattern(accessLogPattern);
        }
        String accessLogPrefix = ContainerConfig.getPropertyValue(engineConfig, "access-log-prefix", null);
        if (UtilValidate.isNotEmpty(accessLogPrefix)) {
            accessLogValve.setPrefix(accessLogPrefix);
        }
        accessLogValve.setRotatable(ContainerConfig.getPropertyValue(engineConfig, "access-log-rotate", false));
        engineValves.add(accessLogValve);
    }
    return engineValves;
}
Also used : ContainerException(org.apache.ofbiz.base.container.ContainerException) ArrayList(java.util.ArrayList) ReplicationValve(org.apache.catalina.ha.tcp.ReplicationValve) Valve(org.apache.catalina.Valve) AccessLogValve(org.apache.catalina.valves.AccessLogValve) File(java.io.File) AccessLogValve(org.apache.catalina.valves.AccessLogValve)

Example 3 with Valve

use of org.apache.catalina.Valve in project tomcat70 by apache.

the class MBeanFactory method removeValve.

/**
 * Remove an existing Valve.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeValve(String name) throws Exception {
    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    ContainerBase container = getParentContainerFromChild(oname);
    Valve[] valves = container.getPipeline().getValves();
    for (int i = 0; i < valves.length; i++) {
        ObjectName voname = ((ValveBase) valves[i]).getObjectName();
        if (voname.equals(oname)) {
            container.getPipeline().removeValve(valves[i]);
        }
    }
}
Also used : ContainerBase(org.apache.catalina.core.ContainerBase) Valve(org.apache.catalina.Valve) AccessLogValve(org.apache.catalina.valves.AccessLogValve) RemoteHostValve(org.apache.catalina.valves.RemoteHostValve) RemoteAddrValve(org.apache.catalina.valves.RemoteAddrValve) ValveBase(org.apache.catalina.valves.ValveBase) ObjectName(javax.management.ObjectName)

Example 4 with Valve

use of org.apache.catalina.Valve in project tomcat70 by apache.

the class SimpleTcpCluster method registerClusterValve.

/**
 * register all cluster valve to host or engine
 */
protected void registerClusterValve() {
    if (container != null) {
        for (Iterator<Valve> iter = valves.iterator(); iter.hasNext(); ) {
            ClusterValve valve = (ClusterValve) iter.next();
            if (log.isDebugEnabled())
                log.debug("Invoking addValve on " + getContainer() + " with class=" + valve.getClass().getName());
            if (valve != null) {
                container.getPipeline().addValve(valve);
                valve.setCluster(this);
            }
        }
    }
}
Also used : Valve(org.apache.catalina.Valve) JvmRouteBinderValve(org.apache.catalina.ha.session.JvmRouteBinderValve) ClusterValve(org.apache.catalina.ha.ClusterValve) ClusterValve(org.apache.catalina.ha.ClusterValve)

Example 5 with Valve

use of org.apache.catalina.Valve in project tomcat70 by apache.

the class StandardPipeline method addValve.

/**
 * <p>Add a new Valve to the end of the pipeline associated with this
 * Container.  Prior to adding the Valve, the Valve's
 * <code>setContainer()</code> method will be called, if it implements
 * <code>Contained</code>, with the owning Container as an argument.
 * The method may throw an
 * <code>IllegalArgumentException</code> if this Valve chooses not to
 * be associated with this Container, or <code>IllegalStateException</code>
 * if it is already associated with a different Container.</p>
 *
 * @param valve Valve to be added
 *
 * @exception IllegalArgumentException if this Container refused to
 *  accept the specified Valve
 * @exception IllegalArgumentException if the specified Valve refuses to be
 *  associated with this Container
 * @exception IllegalStateException if the specified Valve is already
 *  associated with a different Container
 */
@Override
public void addValve(Valve valve) {
    // Validate that we can add this Valve
    if (valve instanceof Contained)
        ((Contained) valve).setContainer(this.container);
    // Start the new component if necessary
    if (getState().isAvailable()) {
        if (valve instanceof Lifecycle) {
            try {
                ((Lifecycle) valve).start();
            } catch (LifecycleException e) {
                log.error("StandardPipeline.addValve: start: ", e);
            }
        }
    }
    // Add this Valve to the set associated with this Pipeline
    if (first == null) {
        first = valve;
        valve.setNext(basic);
    } else {
        Valve current = first;
        while (current != null) {
            if (current.getNext() == basic) {
                current.setNext(valve);
                valve.setNext(basic);
                break;
            }
            current = current.getNext();
        }
    }
    container.fireContainerEvent(Container.ADD_VALVE_EVENT, valve);
}
Also used : Contained(org.apache.catalina.Contained) LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Valve(org.apache.catalina.Valve)

Aggregations

Valve (org.apache.catalina.Valve)72 ArrayList (java.util.ArrayList)15 Lifecycle (org.apache.catalina.Lifecycle)14 Container (org.apache.catalina.Container)13 LifecycleException (org.apache.catalina.LifecycleException)13 Pipeline (org.apache.catalina.Pipeline)11 ObjectName (javax.management.ObjectName)9 Realm (org.apache.catalina.Realm)8 AccessLogValve (org.apache.catalina.valves.AccessLogValve)8 Contained (org.apache.catalina.Contained)7 LifecycleListener (org.apache.catalina.LifecycleListener)7 Request (org.apache.catalina.connector.Request)7 ClusterValve (org.apache.catalina.ha.ClusterValve)7 RemoteIpValve (org.apache.catalina.valves.RemoteIpValve)7 Test (org.junit.Test)7 Context (org.apache.catalina.Context)6 JmxEnabled (org.apache.catalina.JmxEnabled)6 Response (org.apache.catalina.connector.Response)6 IOException (java.io.IOException)5 ContainerBase (org.apache.catalina.core.ContainerBase)5