[jboss-cvs] JBossAS SVN: r108973 - trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/sso.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 28 13:26:05 EDT 2010


Author: smarlow at redhat.com
Date: 2010-10-28 13:26:05 -0400 (Thu, 28 Oct 2010)
New Revision: 108973

Modified:
   trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/sso/ClusteredSingleSignOn.java
Log:
JBAS-8556 SSO logging changes, code fix will be in ha-server-cache-ispn for CR2

Modified: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/sso/ClusteredSingleSignOn.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/sso/ClusteredSingleSignOn.java	2010-10-28 17:18:01 UTC (rev 108972)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/sso/ClusteredSingleSignOn.java	2010-10-28 17:26:05 UTC (rev 108973)
@@ -83,9 +83,8 @@
    public static final int DEFAULT_MAX_EMPTY_LIFE = 1800;
    /** The default JBoss Cache to use for storing SSO entries */
    public static final String DEFAULT_CACHE_NAME = "clustered-sso";
-   public static final String LEGACY_CACHE_NAME = "jboss.cache:service=TomcatClusteringCache";
    /** for use when there is no container logger to use **/
-   private static final Logger ALTERNATE_LOG = Logger.getLogger(ClusteredSingleSignOn.class);
+   private static final Logger LOG = Logger.getLogger(ClusteredSingleSignOn.class);
 
    // Override the superclass value
    static
@@ -227,13 +226,13 @@
          }
          catch (LifecycleException e)
          {
-            getContainer().getLogger().error("Exception creating SSOClusterManager " +
+            LOG.error("Exception creating SSOClusterManager " +
                managerClass, e);
          }
       }
       else
       {
-          getContainer().getLogger().error("Cannot set clusterManagerClass to " + managerClass +
+          LOG.error("Cannot set clusterManagerClass to " + managerClass +
             "; already started using " + clusterManagerClass);
       }
    }
@@ -417,9 +416,11 @@
             (sm.getString("authenticator.alreadyStarted"));
       }
 
-      if (ALTERNATE_LOG.isDebugEnabled())
+      if (LOG.isDebugEnabled())
       {
-         ALTERNATE_LOG.debug("ClusteredSSO:  starting, clusterManagerClass=" + this.clusterManagerClass);
+         LOG.debug("ClusteredSSO:  starting, clusterManagerClass=" + this.clusterManagerClass +
+         ", maxEmptyLife = " + maxEmptyLife + "ms, processExpiresInterval = " + processExpiresInterval +"ms");
+
       }
 
       // Attempt to create an SSOClusterManager
@@ -511,16 +512,20 @@
 
       // Look up the single session id associated with this session (if any)
       Session session = event.getSession();
-      if (getContainer().getLogger().isTraceEnabled())
-          getContainer().getLogger().trace("Process session destroyed on " + session);
+      if (LOG.isTraceEnabled())
+          LOG.trace("Process session destroyed on " + session);
 
       String ssoId = null;
       synchronized (reverse)
       {
-         ssoId = (String) reverse.get(session);
+         ssoId = reverse.get(session);
       }
       if (ssoId == null)
+      {
+         if (LOG.isTraceEnabled())
+             LOG.trace("ignoring as SSO is already closed for session " + session);
          return;
+      }
 
       try
       {
@@ -529,8 +534,17 @@
          // If so, we'll just remove the expired session from the
          // SSO.  If the session was logged out, we'll log out
          // of all sessions associated with the SSO.
-         if (isSessionTimedOut(session) || isManagerStopped(session))
+         boolean timedOut;
+         boolean stopped = false;
+         if ( (timedOut = isSessionTimedOut(session)) || (stopped=isManagerStopped(session)))
          {
+            if (LOG.isTraceEnabled())
+                LOG.trace(
+                   "remove session " + session + " from SSO " + ssoId +
+                      ", isSessionTimedOut=" + timedOut +
+                      ", isManagerStopped=" + stopped
+                );
+
             removeSession(ssoId, session);
 
             // Quite poor.  We hijack the caller thread (the Tomcat background thread)
@@ -539,6 +553,8 @@
          }
          else
          {
+            if (LOG.isTraceEnabled())
+                LOG.trace("user logged out of SSO " + ssoId);
             // The session was logged out.
             logout(ssoId);
          }
@@ -547,7 +563,7 @@
       {
          // Don't propagate back to the webapp; we don't want to disrupt
          // the session expiration process
-         getContainer().getLogger().error("Caught exception updating SSO " + ssoId +
+         LOG.error("Caught exception updating SSO " + ssoId +
                                           " following destruction of session " +
                                           session.getIdInternal(), e);
       }
@@ -614,7 +630,7 @@
          {
             source.removeLifecycleListener(this);
             
-            getContainer().getLogger().debug("ClusteredSSO: removed stopped " +
+            LOG.debug("ClusteredSSO: removed stopped " +
                                              "manager " + source.toString());            
          }
          
@@ -649,12 +665,12 @@
       request.removeNote(Constants.REQ_SSOID_NOTE);
 
       // Has a valid user already been authenticated?
-      if (getContainer().getLogger().isTraceEnabled())
-         getContainer().getLogger().trace("Process request for '" + request.getRequestURI() + "'");
+      if (LOG.isTraceEnabled())
+         LOG.trace("Process request for '" + request.getRequestURI() + "'");
       if (request.getUserPrincipal() != null)
       {
-         if (getContainer().getLogger().isTraceEnabled())
-            getContainer().getLogger().trace(" Principal '" + request.getUserPrincipal().getName() +
+         if (LOG.isTraceEnabled())
+            LOG.trace(" Principal '" + request.getUserPrincipal().getName() +
                "' has already been authenticated");
          getNext().invoke(request, response);
          return;
@@ -675,16 +691,16 @@
       }
       if (cookie == null)
       {
-         if (getContainer().getLogger().isTraceEnabled())
-            getContainer().getLogger().trace(" SSO cookie is not present");
+         if (LOG.isTraceEnabled())
+            LOG.trace(" SSO cookie is not present");
          getNext().invoke(request, response);
          return;
       }
 
       // Look up the cached Principal associated with this cookie value
       String ssoId = cookie.getValue();
-      if (getContainer().getLogger().isTraceEnabled())
-          getContainer().getLogger().trace(" Checking for cached principal for " + ssoId);
+      if (LOG.isTraceEnabled())
+          LOG.trace(" Checking for cached principal for " + ssoId);
       JBossSingleSignOnEntry entry = getSingleSignOnEntry(cookie.getValue());
       if (entry != null && isValid(ssoId, entry))
       {
@@ -692,9 +708,9 @@
          // have to deal with the fact that the entry may not have an
          // associated Principal. SSO entries retrieved via a lookup from a 
          // cluster will not have a Principal, as Principal is not Serializable
-         if (getContainer().getLogger().isTraceEnabled())
+         if (LOG.isTraceEnabled())
          {
-             getContainer().getLogger().trace(" Found cached principal '" +
+             LOG.trace(" Found cached principal '" +
                (ssoPrinc == null ? "NULL" : ssoPrinc.getName()) +
                "' with auth type '" + entry.getAuthType() + "'");
          }
@@ -709,8 +725,8 @@
       }
       else
       {
-         if (getContainer().getLogger().isTraceEnabled())
-            getContainer().getLogger().trace(" No cached principal found, erasing SSO cookie");
+         if (LOG.isTraceEnabled())
+            LOG.trace(" No cached principal found, erasing SSO cookie");
          cookie.setMaxAge(0);
          response.addCookie(cookie);
       }
@@ -735,8 +751,8 @@
     */
    public void associate(String ssoId, Session session)
    {
-      if (getContainer().getLogger().isTraceEnabled())
-          getContainer().getLogger().trace("Associate sso id " + ssoId + " with session " + session);
+      if (LOG.isTraceEnabled())
+          LOG.trace("Associate sso id " + ssoId + " with session " + session);
 
       JBossSingleSignOnEntry sso = getSingleSignOnEntry(ssoId);
       boolean added = false;
@@ -769,7 +785,7 @@
             mgrKey = manager;
          }
          else {
-            getContainer().getLogger().warn("Manager for session " + 
+            LOG.warn("Manager for session " +
                       session.getIdInternal() +
                       " does not implement Lifecycle; web app shutdown may " +
                       " lead to incorrect SSO invalidations");
@@ -816,15 +832,28 @@
 
       boolean removed = sso.removeSession2(session);
       // If we changed anything, notify any cluster
-      if (removed && ssoClusterManager != null)
+      if (ssoClusterManager != null)
       {
-         ssoClusterManager.removeSession(ssoId, getFullyQualifiedSessionId(session));
+         if (removed)
+         {
+            ssoClusterManager.removeSession(ssoId, getFullyQualifiedSessionId(session));
+            if (LOG.isTraceEnabled())
+                LOG.trace("deregister will notify cluster of removed session " + session +" sso id " + ssoId);
+         }
+         else
+         {
+            if (LOG.isTraceEnabled())
+                LOG.trace("deregister didn't find session " + session +" sso id " + ssoId + " cluster notification not sent");
+         }
       }
 
       // see if this was the last session on this node, 
       // if remove sso entry from our local cache
       if (sso.getSessionCount() == 0)
       {
+         if (LOG.isTraceEnabled())
+             LOG.trace("deregister detected zero sessions for sso id " + ssoId);
+
          synchronized (cache)
          {
             sso = (JBossSingleSignOnEntry) cache.remove(ssoId);
@@ -841,8 +870,8 @@
     */
    public void deregister(String ssoId)
    {
-      if (getContainer().getLogger().isTraceEnabled())
-          getContainer().getLogger().trace("Deregistering sso id '" + ssoId + "'");
+      if (LOG.isTraceEnabled())
+          LOG.trace("Deregistering sso id '" + ssoId + "'");
 
       
       // It's possible we don't have the SSO locally but it's in
@@ -863,8 +892,8 @@
       Session sessions[] = sso.findSessions();
       for (int i = 0; i < sessions.length; i++)
       {
-         if (getContainer().getLogger().isTraceEnabled())
-             getContainer().getLogger().trace(" Invalidating session " + sessions[i]);
+         if (LOG.isTraceEnabled())
+             LOG.trace(" Invalidating session " + sessions[i]);
          // Remove from reverse cache first to avoid recursion
          synchronized (reverse)
          {
@@ -1016,20 +1045,26 @@
     */
    protected void removeSession(String ssoId, Session session)
    {
-      if (getContainer().getLogger().isTraceEnabled())
-          getContainer().getLogger().trace("Removing session " + session.toString() +
-            " from sso id " + ssoId);
-
       // Get a reference to the SingleSignOn
       JBossSingleSignOnEntry entry = getSingleSignOnEntry(ssoId);
+      if (LOG.isTraceEnabled())
+          LOG.trace("Removing session " + session.toString() +
+            " from sso id " + ssoId + ", " + (entry != null?"found SSO entry":"SSO entry not found"));
       if (entry == null)
          return;
 
       // Remove the inactive session from SingleSignOnEntry
       boolean removed = entry.removeSession2(session);
+      if (LOG.isTraceEnabled())
+          LOG.trace("Removing Session " + session.toString() +
+             ", session found =" + removed +
+             ", ssoClusterManager is " + (ssoClusterManager!= null?"set":"not set"
+          ));
+
       // If we changed anything, notify any cluster
       if (removed && ssoClusterManager != null)
       {
+
          ssoClusterManager.removeSession(ssoId, getFullyQualifiedSessionId(session));
       }
 
@@ -1116,9 +1151,9 @@
    void registerLocal(String ssoId, Principal principal, String authType,
       String username, String password)
    {
-      if (getContainer().getLogger().isTraceEnabled())
+      if (LOG.isTraceEnabled())
       {
-          getContainer().getLogger().trace("Registering sso id '" + ssoId + "' for user '" +
+          LOG.trace("Registering sso id '" + ssoId + "' for user '" +
             principal.getName() + "' with auth type '" + authType + "'");
       }
 
@@ -1154,8 +1189,8 @@
       {
          if (sso.getCanReauthenticate() == false)
          {
-            if (getContainer().getLogger().isTraceEnabled())
-                getContainer().getLogger().trace("Update sso id " + ssoId + " to auth type " + authType);
+            if (LOG.isTraceEnabled())
+                LOG.trace("Update sso id " + ssoId + " to auth type " + authType);
 
             synchronized (sso)
             {
@@ -1165,8 +1200,8 @@
          }
          else if (sso.getPrincipal() == null && principal != null)
          {
-            if (getContainer().getLogger().isTraceEnabled())
-                getContainer().getLogger().trace("Update sso id " + ssoId + " with principal " +
+            if (LOG.isTraceEnabled())
+                LOG.trace("Update sso id " + ssoId + " with principal " +
                   principal.getName());
 
             synchronized (sso)
@@ -1188,8 +1223,8 @@
       // Only update if the entry is missing information
       if (sso != null && sso.getCanReauthenticate() == false)
       {
-         if (getContainer().getLogger().isTraceEnabled())
-             getContainer().getLogger().trace("Update sso id " + ssoId + 
+         if (LOG.isTraceEnabled())
+             LOG.trace("Update sso id " + ssoId +
                    " to auth type " + credentials.getAuthType());
 
          synchronized (sso)
@@ -1212,9 +1247,9 @@
    {
       Object obj = emptySSOs.put(ssoId, new Long(System.currentTimeMillis()));
       
-      if (obj == null && getContainer().getLogger().isTraceEnabled())
+      if (obj == null && LOG.isTraceEnabled())
       {
-         getContainer().getLogger().trace("Notified that SSO " + ssoId + " is empty");
+         LOG.trace("Notified that SSO " + ssoId + " is empty");
       }
    }
    
@@ -1226,9 +1261,9 @@
    {
       Object obj = emptySSOs.remove(ssoId);
       
-      if (obj != null && getContainer().getLogger().isTraceEnabled())
+      if (obj != null && LOG.isTraceEnabled())
       {
-         getContainer().getLogger().trace("Notified that SSO " + ssoId + 
+         LOG.trace("Notified that SSO " + ssoId +
                                           " is no longer empty");
       }
    }
@@ -1352,9 +1387,9 @@
          if ( (now - ((Long) entry.getValue()).longValue()) > maxEmptyLife)
          {
             String ssoId = (String) entry.getKey();
-            if (getContainer().getLogger().isTraceEnabled())
+            if (LOG.isTraceEnabled())
             {
-               getContainer().getLogger().trace("Invalidating expired SSO " + ssoId);
+               LOG.trace("Invalidating expired SSO " + ssoId);
             }
             logout(ssoId);
          }
@@ -1372,9 +1407,9 @@
          {
             valid = false;
             
-            if (getContainer().getLogger().isTraceEnabled())
+            if (LOG.isTraceEnabled())
             {
-               getContainer().getLogger().trace("Invalidating expired SSO " + ssoId);
+               LOG.trace("Invalidating expired SSO " + ssoId);
             }
             
             logout(ssoId);



More information about the jboss-cvs-commits mailing list