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

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

package org.owasp.security.logging.mdc;

import javax.servlet.FilterConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.owasp.security.logging.Utils;
import org.slf4j.MDC;

/**
 * This plugin adds a hash of the session ID to the MDC. The value can 
 * be accessed in a PatternLayout by using the specifier: %X{session}
 *
 * @author August Detlefsen [[email protected]]
 */
public class SessionPlugin implements IPlugin {

    public void init(FilterConfig config) {
    }
    
    public void execute(HttpServletRequest request) {
        HttpSession session = request.getSession();
        if (session != null) {
            //capture (a hash of) the session ID
            String hashedSession = Utils.toSHA(session.getId());
            MDC.put("session", hashedSession);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy