tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1559697 - in /tomcat/trunk: java/org/apache/catalina/ java/org/apache/catalina/filters/ java/org/apache/catalina/manager/ java/org/apache/catalina/valves/ java/org/apache/coyote/ webapps/docs/config/
Date Mon, 20 Jan 2014 14:02:46 GMT
Author: markt
Date: Mon Jan 20 14:02:45 2014
New Revision: 1559697

URL: http://svn.apache.org/r1559697
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=55956
Make the forwarded remote IP available on the Manager status page

Modified:
    tomcat/trunk/java/org/apache/catalina/Globals.java
    tomcat/trunk/java/org/apache/catalina/filters/RemoteIpFilter.java
    tomcat/trunk/java/org/apache/catalina/manager/StatusTransformer.java
    tomcat/trunk/java/org/apache/catalina/valves/RemoteIpValve.java
    tomcat/trunk/java/org/apache/coyote/Constants.java
    tomcat/trunk/java/org/apache/coyote/RequestInfo.java
    tomcat/trunk/webapps/docs/config/filter.xml
    tomcat/trunk/webapps/docs/config/valve.xml

Modified: tomcat/trunk/java/org/apache/catalina/Globals.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Globals.java?rev=1559697&r1=1559696&r2=1559697&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Globals.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Globals.java Mon Jan 20 14:02:45 2014
@@ -221,6 +221,19 @@ public final class Globals {
 
 
     /**
+     * The request attribute set by the RemoteIpFilter, RemoteIpValve (and may
+     * be set by other similar components) that identifies for the connector the
+     * remote IP address claimed to be associated with this request when a
+     * request is received via one or more proxies. It is typically provided via
+     * the X-Forwarded-For HTTP header.
+     *
+     * Duplicated here for neater code in the catalina packages.
+     */
+    public static final String REMOTE_ADDR_ATTRIBUTE =
+            org.apache.coyote.Constants.REMOTE_ADDR_ATTRIBUTE;
+
+
+    /**
      *
      */
     public static final String ASYNC_SUPPORTED_ATTR =

Modified: tomcat/trunk/java/org/apache/catalina/filters/RemoteIpFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/filters/RemoteIpFilter.java?rev=1559697&r1=1559696&r2=1559697&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/filters/RemoteIpFilter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/filters/RemoteIpFilter.java Mon Jan 20 14:02:45
2014
@@ -42,6 +42,7 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.catalina.AccessLog;
+import org.apache.catalina.Globals;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 
@@ -827,6 +828,8 @@ public class RemoteIpFilter implements F
             if (requestAttributesEnabled) {
                 request.setAttribute(AccessLog.REMOTE_ADDR_ATTRIBUTE,
                         xRequest.getRemoteAddr());
+                request.setAttribute(Globals.REMOTE_ADDR_ATTRIBUTE,
+                        xRequest.getRemoteAddr());
                 request.setAttribute(AccessLog.REMOTE_HOST_ATTRIBUTE,
                         xRequest.getRemoteHost());
                 request.setAttribute(AccessLog.PROTOCOL_ATTRIBUTE,
@@ -1114,6 +1117,7 @@ public class RemoteIpFilter implements F
      * <li>org.apache.catalina.AccessLog.RemoteHost</li>
      * <li>org.apache.catalina.AccessLog.Protocol</li>
      * <li>org.apache.catalina.AccessLog.ServerPort</li>
+     * <li>org.apache.tomcat.remoteAddr</li>
      * </ul>
      *
      * @param requestAttributesEnabled  <code>true</code> causes the attributes

Modified: tomcat/trunk/java/org/apache/catalina/manager/StatusTransformer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/StatusTransformer.java?rev=1559697&r1=1559696&r2=1559697&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/manager/StatusTransformer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/manager/StatusTransformer.java Mon Jan 20 14:02:45
2014
@@ -336,7 +336,7 @@ public class StatusTransformer {
                                     (grpName, "bytesSent"), true));
             writer.print("</p>");
 
-            writer.print("<table border=\"0\"><tr><th>Stage</th><th>Time</th><th>B
Sent</th><th>B Recv</th><th>Client</th><th>VHost</th><th>Request</th></tr>");
+            writer.print("<table border=\"0\"><tr><th>Stage</th><th>Time</th><th>B
Sent</th><th>B Recv</th><th>Client (Forwarded)</th><th>Client
(Actual)</th><th>VHost</th><th>Request</th></tr>");
 
             enumeration = requestProcessors.elements();
             while (enumeration.hasMoreElements()) {
@@ -485,6 +485,10 @@ public class StatusTransformer {
                 writer.write("</td>");
                 writer.write("<td>");
                 writer.print(filter(mBeanServer.getAttribute
+                                    (pName, "remoteAddrForwarded")));
+                writer.write("</td>");
+                writer.write("<td>");
+                writer.print(filter(mBeanServer.getAttribute
                                     (pName, "remoteAddr")));
                 writer.write("</td>");
                 writer.write("<td nowrap>");

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=1559697&r1=1559696&r2=1559697&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/RemoteIpValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/RemoteIpValve.java Mon Jan 20 14:02:45 2014
@@ -26,6 +26,7 @@ import java.util.regex.Pattern;
 import javax.servlet.ServletException;
 
 import org.apache.catalina.AccessLog;
+import org.apache.catalina.Globals;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.juli.logging.Log;
@@ -662,6 +663,8 @@ public class RemoteIpValve extends Valve
         if (requestAttributesEnabled) {
             request.setAttribute(AccessLog.REMOTE_ADDR_ATTRIBUTE,
                     request.getRemoteAddr());
+            request.setAttribute(Globals.REMOTE_ADDR_ATTRIBUTE,
+                    request.getRemoteAddr());
             request.setAttribute(AccessLog.REMOTE_HOST_ATTRIBUTE,
                     request.getRemoteHost());
             request.setAttribute(AccessLog.PROTOCOL_ATTRIBUTE,
@@ -820,6 +823,7 @@ public class RemoteIpValve extends Valve
      * <li>org.apache.catalina.AccessLog.RemoteHost</li>
      * <li>org.apache.catalina.AccessLog.Protocol</li>
      * <li>org.apache.catalina.AccessLog.ServerPort</li>
+     * <li>org.apache.tomcat.remoteAddr</li>
      * </ul>
      *
      * @param requestAttributesEnabled  <code>true</code> causes the attributes

Modified: tomcat/trunk/java/org/apache/coyote/Constants.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/Constants.java?rev=1559697&r1=1559696&r2=1559697&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/Constants.java (original)
+++ tomcat/trunk/java/org/apache/coyote/Constants.java Mon Jan 20 14:02:45 2014
@@ -128,4 +128,15 @@ public final class Constants {
      */
     public static final String SENDFILE_FILE_END_ATTR =
         "org.apache.tomcat.sendfile.end";
+
+
+    /**
+     * The request attribute set by the RemoteIpFilter, RemoteIpValve (and may
+     * be set by other similar components) that identifies for the connector the
+     * remote IP address claimed to be associated with this request when a
+     * request is received via one or more proxies. It is typically provided via
+     * the X-Forwarded-For HTTP header.
+     */
+    public static final String REMOTE_ADDR_ATTRIBUTE =
+            "org.apache.tomcat.remoteAddr";
 }

Modified: tomcat/trunk/java/org/apache/coyote/RequestInfo.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/RequestInfo.java?rev=1559697&r1=1559696&r2=1559697&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/RequestInfo.java (original)
+++ tomcat/trunk/java/org/apache/coyote/RequestInfo.java Mon Jan 20 14:02:45 2014
@@ -98,6 +98,18 @@ public class RequestInfo  {
         return req.remoteAddr().toString();
     }
 
+    /**
+     * Obtain the remote address for this connection as reported by an
+     * intermediate proxy (if any).
+     */
+    public String getRemoteAddrForwarded() {
+        String remoteAddrProxy = (String) req.getAttribute(Constants.REMOTE_ADDR_ATTRIBUTE);
+        if (remoteAddrProxy == null) {
+            return getRemoteAddr();
+        }
+        return remoteAddrProxy;
+    }
+
     public int getContentLength() {
         return req.getContentLength();
     }

Modified: tomcat/trunk/webapps/docs/config/filter.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/filter.xml?rev=1559697&r1=1559696&r2=1559697&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/filter.xml (original)
+++ tomcat/trunk/webapps/docs/config/filter.xml Mon Jan 20 14:02:45 2014
@@ -890,6 +890,7 @@ FINE: Request "/docs/config/manager.html
       <li><code>org.apache.catalina.AccessLog.RemoteHost</code></li>
       <li><code>org.apache.catalina.AccessLog.Protocol</code></li>
       <li><code>org.apache.catalina.AccessLog.ServerPort</code></li>
+      <li><code>org.apache.tomcat.remoteAddr</code></li>
     </ul>
 
   </subsection>
@@ -1217,6 +1218,8 @@ FINE: Request "/docs/config/manager.html
         <p>Set to <code>true</code> to set the request attributes used
by
         AccessLog implementations to override the values returned by the
         request for remote address, remote host, server port and protocol.
+        Request attributes are also used to enable the forwarded remote address
+        to be displayed on the status page of the Manager web application.
         If not set, the default value of <code>true</code> will be used.</p>
       </attribute>
 

Modified: tomcat/trunk/webapps/docs/config/valve.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/valve.xml?rev=1559697&r1=1559696&r2=1559697&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/valve.xml (original)
+++ tomcat/trunk/webapps/docs/config/valve.xml Mon Jan 20 14:02:45 2014
@@ -1268,6 +1268,7 @@
       <li><code>org.apache.catalina.AccessLog.RemoteHost</code></li>
       <li><code>org.apache.catalina.AccessLog.Protocol</code></li>
       <li><code>org.apache.catalina.AccessLog.ServerPort</code></li>
+      <li><code>org.apache.tomcat.remoteAddr</code></li>
     </ul>
 
   </subsection>
@@ -1311,6 +1312,8 @@
         <p>Set to <code>true</code> to set the request attributes used
by
         AccessLog implementations to override the values returned by the
         request for remote address, remote host, server port and protocol.
+        Request attributes are also used to enable the forwarded remote address
+        to be displayed on the status page of the Manager web application.
         If not set, the default value of <code>true</code> will be used.</p>
       </attribute>
 



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


Mime
View raw message