Tweak defaults. Document.
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 6 Feb 2011 19:08:13 +0000 (19:08 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 6 Feb 2011 19:08:13 +0000 (19:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1067732 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/filters/RemoteIpFilter.java
java/org/apache/catalina/valves/AccessLogValve.java
java/org/apache/catalina/valves/RemoteIpValve.java
webapps/docs/changelog.xml
webapps/docs/config/valve.xml

index ca83323..da2a1be 100644 (file)
@@ -41,6 +41,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequestWrapper;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.catalina.AccessLog;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 
@@ -698,6 +699,11 @@ public class RemoteIpFilter implements Filter {
     private String remoteIpHeader = "X-Forwarded-For";
     
     /**
+     * @see #setRequestAttributesEnabled(boolean)
+     */
+    private boolean requestAttributesEnabled = true;
+
+    /**
      * @see #setTrustedProxies(String)
      */
     private Pattern trustedProxies = null;
@@ -792,6 +798,16 @@ public class RemoteIpFilter implements Filter {
                         + xRequest.getScheme() + "', newSecure='" + xRequest.isSecure() + "', new[" + remoteIpHeader + "]='"
                         + xRequest.getHeader(remoteIpHeader) + "', new[" + proxiesHeader + "]='" + xRequest.getHeader(proxiesHeader) + "'");
             }
+            if (requestAttributesEnabled) {
+                request.setAttribute(AccessLog.REMOTE_ADDR_ATTRIBUTE,
+                        request.getRemoteAddr());
+                request.setAttribute(AccessLog.REMOTE_HOST_ATTRIBUTE,
+                        request.getRemoteHost());
+                request.setAttribute(AccessLog.PROTOCOL_ATTRIBUTE,
+                        request.getProtocol());
+                request.setAttribute(AccessLog.SERVER_PORT_ATTRIBUTE,
+                        Integer.valueOf(request.getServerPort()));
+            }
             chain.doFilter(xRequest, response);
         } else {
             if (log.isDebugEnabled()) {
@@ -839,6 +855,15 @@ public class RemoteIpFilter implements Filter {
         return remoteIpHeader;
     }
     
+    /**
+     * @see #setRequestAttributesEnabled(boolean)
+     * @return <code>true</code> if the attributes will be logged, otherwise
+     *         <code>false</code>
+     */
+    public boolean getRequestAttributesEnabled() {
+        return requestAttributesEnabled;
+    }
+
     public Pattern getTrustedProxies() {
         return trustedProxies;
     }
@@ -988,6 +1013,28 @@ public class RemoteIpFilter implements Filter {
     }
     
     /**
+     * Should this filter set request attributes for IP address, Hostname,
+     * protocol and port used for the request? This are typically used in
+     * conjunction with an {@link AccessLog} 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.
index e72fdd1..78f92c5 100644 (file)
@@ -296,7 +296,7 @@ public class AccessLogValve extends ValveBase implements AccessLog {
     /**
      * @see #setRequestAttributesEnabled(boolean)
      */
-    protected boolean requestAttributesEnabled = true;
+    protected boolean requestAttributesEnabled = false;
 
     // ------------------------------------------------------------- Properties
 
index 1ea4615..bb4b4e7 100644 (file)
@@ -752,7 +752,7 @@ 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
+     * conjunction with the {@link AccessLog} which will otherwise log the
      * original values. Default is <code>true</code>.
      * 
      * The attributes set are:
index 7db82d4..813143d 100644 (file)
         When running under a security manager, user requests may fail with a
         security exception. (markt)
       </fix>
+      <add>
+        Enhance the RemoteIpFilter and RemoteIpValve so that the modified remote
+        address, remote host, protocol and server port may be used in an access
+        log if desired. (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Coyote">
index 52319a7..ad90b97 100644 (file)
         use a zero-length string.</p>
       </attribute>
 
+      <attribute name="requestAttributesEnabled" required="false">
+        <p>Set to <code>true</code> to check for the existance of request
+        attributes (typically set by the RemoteIpValve and similar) that should
+        be used to override the values returned by the request for remote
+        address, remote host, server port and protocol. If the attributes are
+        not set, or this attribute is set to <code>false</code> then the values 
+        from the request will be used. If not set, the default value of
+        <code>false</code> will be used.</p>
+      </attribute>
+
       <attribute name="resolveHosts" required="false">
         <p>Set to <code>true</code> to convert the IP address of the remote
         host into the corresponding host name via a DNS lookup.  Set to
         <code>x-forwarded-by</code> is used.</p>
       </attribute>
 
+      <attribute name="requestAttributesEnabled" required="false">
+        <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. If
+        the attributes are not set, or this attribute is set to
+        <code>false</code> then the values from the request will be used. If not
+        set, the default value of <code>true</code> will be used.</p>
+      </attribute>
+
       <attribute name="trustedProxies" required="false">
         <p>Regular expression (using <code>java.util.regex</code>) that a
         proxy&apos;s IP address must match to be considered an trusted proxy.