<layout class="ch.qos.logback.classic.PatternLayout">
<!-- General logging pattern -->
- <Pattern>%date{HH:mm:ss.SSS} %level [%logger:%line] - %msg%n</Pattern>
+ <Pattern>%date{HH:mm:ss.SSS} - %level [%logger:%line] - %msg%n</Pattern>
+
+ <!--
+ Two MDC variables are available for authenticated users: 'idpSessionID' and 'principalName'.
+ You may include these the data in the logging pattern by means of %mdc{NAME}
+ You may include the thread ID by means of %t
+ -->
+ <!-- Example logging pattern using thread ID and principal name -->
+ <!--
+ <Pattern>%date{HH:mm:ss.SSS} - %level [%logger:%line] - [%t:%mdc{principalName}] - %msg%n</Pattern>
+ -->
+
</layout>
</appender>
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import org.apache.log4j.MDC;
import org.joda.time.DateTime;
import org.opensaml.xml.util.DatatypeHelper;
import org.slf4j.Logger;
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException,
ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
- HttpServletResponse httpResponse = (HttpServletResponse) response;
Session idpSession = null;
Cookie idpSessionCookie = getIdPSessionCookie(httpRequest);
if (idpSession != null) {
log.trace("Updating IdP session activity time and adding session object to the request");
idpSession.setLastActivityInstant(new DateTime());
+ MDC.put("idpSessionId", idpSession.getSessionID());
+ MDC.put("principalName", idpSession.getPrincipalName());
httpRequest.setAttribute(Session.HTTP_SESSION_BINDING_ATTRIBUTE, idpSession);
}
}
import java.security.SecureRandom;
import org.apache.commons.ssl.util.Hex;
+import org.apache.log4j.MDC;
import org.joda.time.DateTime;
import org.opensaml.util.storage.ExpiringObject;
import org.opensaml.util.storage.StorageService;
prng.nextBytes(sid);
String sessionID = Hex.encode(sid);
+ MDC.put("idpSessionId", sessionID);
+ MDC.put("principalName", principal);
+
Session session = new SessionImpl(sessionID, principal, sessionLifetime);
SessionManagerEntry sessionEntry = new SessionManagerEntry(this, session, sessionLifetime);
sessionStore.put(partition, sessionID, sessionEntry);