Search in sources :

Example 16 with Valve

use of org.apache.catalina.Valve in project tomcat 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 17 with Valve

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

the class ContextConfig method configureStart.

/**
     * Process a "contextConfig" event for this Context.
     */
protected synchronized void configureStart() {
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("contextConfig.start"));
    }
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("contextConfig.xmlSettings", context.getName(), Boolean.valueOf(context.getXmlValidation()), Boolean.valueOf(context.getXmlNamespaceAware())));
    }
    webConfig();
    if (!context.getIgnoreAnnotations()) {
        applicationAnnotationsConfig();
    }
    if (ok) {
        validateSecurityRoles();
    }
    // Configure an authenticator if we need one
    if (ok) {
        authenticatorConfig();
    }
    // Dump the contents of this pipeline if requested
    if (log.isDebugEnabled()) {
        log.debug("Pipeline Configuration:");
        Pipeline pipeline = context.getPipeline();
        Valve[] valves = null;
        if (pipeline != null) {
            valves = pipeline.getValves();
        }
        if (valves != null) {
            for (int i = 0; i < valves.length; i++) {
                log.debug("  " + valves[i].getClass().getName());
            }
        }
        log.debug("======================");
    }
    // Make our application available if no problems were encountered
    if (ok) {
        context.setConfigured(true);
    } else {
        log.error(sm.getString("contextConfig.unavailable"));
        context.setConfigured(false);
    }
}
Also used : Valve(org.apache.catalina.Valve) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) Pipeline(org.apache.catalina.Pipeline)

Example 18 with Valve

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

the class ValveBase method getObjectNameKeyProperties.

// -------------------- JMX and Registration  --------------------
@Override
public String getObjectNameKeyProperties() {
    StringBuilder name = new StringBuilder("type=Valve");
    Container container = getContainer();
    name.append(container.getMBeanKeyProperties());
    int seq = 0;
    // Pipeline may not be present in unit testing
    Pipeline p = container.getPipeline();
    if (p != null) {
        for (Valve valve : p.getValves()) {
            // Skip null valves
            if (valve == null) {
                continue;
            }
            // Only compare valves in pipeline until we find this valve
            if (valve == this) {
                break;
            }
            if (valve.getClass() == this.getClass()) {
                // Duplicate valve earlier in pipeline
                // increment sequence number
                seq++;
            }
        }
    }
    if (seq > 0) {
        name.append(",seq=");
        name.append(seq);
    }
    String className = this.getClass().getName();
    int period = className.lastIndexOf('.');
    if (period >= 0) {
        className = className.substring(period + 1);
    }
    name.append(",name=");
    name.append(className);
    return name.toString();
}
Also used : Container(org.apache.catalina.Container) Valve(org.apache.catalina.Valve) Pipeline(org.apache.catalina.Pipeline)

Example 19 with Valve

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

the class TomcatServletWebServerFactory method configureContext.

/**
	 * Configure the Tomcat {@link Context}.
	 * @param context the Tomcat context
	 * @param initializers initializers to apply
	 */
protected void configureContext(Context context, ServletContextInitializer[] initializers) {
    TomcatStarter starter = new TomcatStarter(initializers);
    if (context instanceof TomcatEmbeddedContext) {
        // Should be true
        ((TomcatEmbeddedContext) context).setStarter(starter);
    }
    context.addServletContainerInitializer(starter, NO_CLASSES);
    for (LifecycleListener lifecycleListener : this.contextLifecycleListeners) {
        context.addLifecycleListener(lifecycleListener);
    }
    for (Valve valve : this.contextValves) {
        context.getPipeline().addValve(valve);
    }
    for (ErrorPage errorPage : getErrorPages()) {
        new TomcatErrorPage(errorPage).addToContext(context);
    }
    for (MimeMappings.Mapping mapping : getMimeMappings()) {
        context.addMimeMapping(mapping.getExtension(), mapping.getMimeType());
    }
    configureSession(context);
    for (TomcatContextCustomizer customizer : this.tomcatContextCustomizers) {
        customizer.customize(context);
    }
}
Also used : ErrorPage(org.springframework.boot.web.server.ErrorPage) Valve(org.apache.catalina.Valve) LifecycleListener(org.apache.catalina.LifecycleListener) MimeMappings(org.springframework.boot.web.server.MimeMappings)

Example 20 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)

Aggregations

Valve (org.apache.catalina.Valve)34 Container (org.apache.catalina.Container)10 ArrayList (java.util.ArrayList)8 Lifecycle (org.apache.catalina.Lifecycle)8 JmxEnabled (org.apache.catalina.JmxEnabled)6 LifecycleException (org.apache.catalina.LifecycleException)6 LifecycleListener (org.apache.catalina.LifecycleListener)6 ObjectName (javax.management.ObjectName)5 Realm (org.apache.catalina.Realm)5 ClusterValve (org.apache.catalina.ha.ClusterValve)5 Contained (org.apache.catalina.Contained)4 Pipeline (org.apache.catalina.Pipeline)4 Cluster (org.apache.catalina.Cluster)3 StandardContext (org.apache.catalina.core.StandardContext)3 IOException (java.io.IOException)2 ServletContext (javax.servlet.ServletContext)2 JvmRouteBinderValve (org.apache.catalina.ha.session.JvmRouteBinderValve)2 AccessLogValve (org.apache.catalina.valves.AccessLogValve)2 RemoteIpValve (org.apache.catalina.valves.RemoteIpValve)2 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)2