Author: markt
Date: Sun Feb  6 18:11:52 2011
New Revision: 1067718

URL: http://svn.apache.org/viewvc?rev=1067718&view=rev
Log:
Initial attempt to fix RemoteIp issues observed with ASF Jira
Docs, filter and changelog commits to follow once it works

Modified:
    tomcat/trunk/java/org/apache/catalina/valves/RemoteIpValve.java

Modified: tomcat/trunk/java/org/apache/catalina/valves/RemoteIpValve.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/RemoteIpValve.java?rev=1067718&r1=1067717&r2=1067718&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/RemoteIpValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/RemoteIpValve.java Sun Feb  6 
18:11:52 2011
@@ -430,7 +430,12 @@ public class RemoteIpValve extends Valve
      * @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 Valve
     }
 
     /**
+     * @see #setRequestAttributesEnabled(boolean)
+     * @return <code>true</code> if the attributes will be logged, otherwise
+     *         <code>false</code>
+     */
+    public boolean getRequestAttributesEnabled() {
+        return requestAttributesEnabled;
+    }
+
+    /**
      * @see #setTrustedProxies(String)
      * @return Regular expression that defines the trusted proxies
      */
@@ -607,6 +621,16 @@ public class RemoteIpValve extends Valve
                         + 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 Valve
     }
     
     /**
+     * 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 <code>true</code>.
+     * 
+     * The attributes set are:
+     * <ul>
+     * <li>org.apache.catalina.RemoteAddr</li>
+     * <li>org.apache.catalina.RemoteHost</li>
+     * <li>org.apache.catalina.Protocol</li>
+     * <li>org.apache.catalina.ServerPost</li>
+     * </ul>
+     * 
+     * @param requestAttributesEnabled  <code>true</code> causes the attributes
+     *                                  to be set, <code>false</code> disables
+     *                                  the setting of the attributes. 
+     */
+    public void setRequestAttributesEnabled(boolean requestAttributesEnabled) {
+        this.requestAttributesEnabled = requestAttributesEnabled;
+    }
+
+    /**
      * <p>
      * Regular expression defining proxies that are trusted when they appear in
      * the {@link #remoteIpHeader} header.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to