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

org.owasp.security.logging.mdc.plugins.UsernamePlugin Maven / Gradle / Ivy

Go to download

The OWASP Security Logging project provides developers and ops personnel with APIs for logging security-related events.

There is a newer version: 1.1.7
Show newest version
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