From: markt Date: Sun, 6 Feb 2011 18:11:52 +0000 (+0000) Subject: Initial attempt to fix RemoteIp issues observed with ASF Jira X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ce603aac399ad9a1dffcfc9ee8b4c2b481976a41;p=tomcat7.0 Initial attempt to fix RemoteIp issues observed with ASF Jira Docs, filter and changelog commits to follow once it works git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1067718 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/valves/RemoteIpValve.java b/java/org/apache/catalina/valves/RemoteIpValve.java index 228f08058..7fc138ba7 100644 --- a/java/org/apache/catalina/valves/RemoteIpValve.java +++ b/java/org/apache/catalina/valves/RemoteIpValve.java @@ -430,7 +430,12 @@ public class RemoteIpValve extends ValveBase { * @see #setRemoteIpHeader(String) */ private String remoteIpHeader = "X-Forwarded-For"; - + + /** + * @see #setRequestAttributesEnabled(boolean) + */ + private boolean requestAttributesEnabled = true; + /** * @see RemoteIpValve#setTrustedProxies(String) */ @@ -496,6 +501,15 @@ public class RemoteIpValve extends ValveBase { } /** + * @see #setRequestAttributesEnabled(boolean) + * @return true if the attributes will be logged, otherwise + * false + */ + public boolean getRequestAttributesEnabled() { + return requestAttributesEnabled; + } + + /** * @see #setTrustedProxies(String) * @return Regular expression that defines the trusted proxies */ @@ -607,6 +621,16 @@ public class RemoteIpValve extends ValveBase { + request.getRemoteAddr() + "'"); } } + if (requestAttributesEnabled) { + request.setAttribute("org.apache.catalina.RemoteAddr", + request.getRemoteAddr()); + request.setAttribute("org.apache.catalina.RemoteHost", + request.getRemoteHost()); + request.setAttribute("org.apache.catalina.Protocol", + request.getProtocol()); + request.setAttribute("org.apache.catalina.ServerPort", + Integer.valueOf(request.getServerPort())); + } try { getNext().invoke(request, response); } finally { @@ -725,6 +749,28 @@ public class RemoteIpValve extends ValveBase { } /** + * Should this valve set request attributes for IP address, Hostname, + * protocol and port used for the request? This are typically used in + * conjunction with the {@link AccessLogValve} which will otherwise log the + * original values. Default is true. + * + * The attributes set are: + * + * + * @param requestAttributesEnabled true causes the attributes + * to be set, false disables + * the setting of the attributes. + */ + public void setRequestAttributesEnabled(boolean requestAttributesEnabled) { + this.requestAttributesEnabled = requestAttributesEnabled; + } + + /** *

* Regular expression defining proxies that are trusted when they appear in * the {@link #remoteIpHeader} header.