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

org.owasp.security.logging.mdc.UsernamePlugin 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.slf4j.MDC;

/**
 * This is an example MDC plugin that gets a username from the HTTP session and 
 * places it in the MDC context for access by the logging system. 
 * 
 * @author August Detlefsen [[email protected]]
 */
public class UsernamePlugin implements IPlugin {

    public void init(FilterConfig config) {
    }
    
    public void execute(HttpServletRequest request) {
        HttpSession session = request.getSession();
        String username = (String)session.getAttribute("username");
        System.out.println("username: " + username);
            if (username != null) {
                MDC.put(MDCFilter.LOGIN_ID, username);
            }
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy