
org.owasp.security.logging.mdc.plugins.UsernamePlugin 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 javax.servlet.http.HttpSession;
import org.owasp.security.logging.mdc.IPlugin;
import org.owasp.security.logging.mdc.MDCFilter;
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");
if (username != null) {
MDC.put(MDCFilter.LOGIN_ID, username);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy