
org.owasp.security.logging.mdc.plugins.IPAddressPlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of security-logging-common Show documentation
Show all versions of security-logging-common Show documentation
The OWASP Security Logging project provides developers and ops personnel with APIs for logging security-related events.
package org.owasp.security.logging.mdc.plugins;
import javax.servlet.FilterConfig;
import javax.servlet.http.HttpServletRequest;
import org.owasp.security.logging.mdc.IPlugin;
import org.owasp.security.logging.mdc.MDCFilter;
import org.slf4j.MDC;
/**
* This plugin adds the request's remote IP address to the MDC in the most basic
* way possible: By calling request.getRemoteAddr(). The value can
* be accessed in a PatternLayout by using the specifier: %X{ipAddress}
*
* For environments that determine the request IP address by using the value of a
* header appended by a load balancer (e.g. X-Forwarded-For), see ForwardedIPAddressPlugin.
*
* @author August Detlefsen [[email protected]]
* @see ForwardedIPAddressPlugin
*/
public class IPAddressPlugin implements IPlugin {
public void init(FilterConfig config) {
}
public void execute(HttpServletRequest request) {
String ipAddress = request.getRemoteAddr();
MDC.put(MDCFilter.IPADDRESS, ipAddress);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy