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;
private String remoteIpHeader = "X-Forwarded-For";
/**
+ * @see #setRequestAttributesEnabled(boolean)
+ */
+ private boolean requestAttributesEnabled = true;
+
+ /**
* @see #setTrustedProxies(String)
*/
private Pattern trustedProxies = null;
+ 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()) {
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;
}
}
/**
+ * 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.
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's IP address must match to be considered an trusted proxy.