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);
}
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;
}
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]);
}
}
}
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);
}
}
}
}
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);
}
Aggregations