All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.owasp.security.logging.mdc.IPAddressPlugin Maven / Gradle / Ivy

package org.owasp.security.logging.mdc;

import javax.servlet.FilterConfig;
import javax.servlet.http.HttpServletRequest;
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