Make IdP session ID and principal name available to logging framerwork for inclusion...
authorlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 24 Apr 2008 07:31:15 +0000 (07:31 +0000)
committerlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 24 Apr 2008 07:31:15 +0000 (07:31 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/branches/REL_2@2729 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/installer/resources/conf-tmpl/logging.xml
src/main/java/edu/internet2/middleware/shibboleth/idp/session/IdPSessionFilter.java
src/main/java/edu/internet2/middleware/shibboleth/idp/session/impl/SessionManagerImpl.java

index 88252e0..d885d91 100644 (file)
 
         <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>
   
index e1a6a88..8b832f8 100644 (file)
@@ -26,8 +26,8 @@ import javax.servlet.ServletRequest;
 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;
@@ -56,7 +56,6 @@ public class IdPSessionFilter implements Filter {
     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);
@@ -65,6 +64,8 @@ public class IdPSessionFilter implements Filter {
             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);
             }
         }
index 8b94aec..335dafd 100644 (file)
@@ -19,6 +19,7 @@ package edu.internet2.middleware.shibboleth.idp.session.impl;
 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;
@@ -96,6 +97,9 @@ public class SessionManagerImpl implements SessionManager<Session>, ApplicationC
         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);