tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject svn commit: r497379 - /tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/authenticator/ClusterSingleSignOn.java
Date Thu, 18 Jan 2007 09:52:26 GMT
Author: pero
Date: Thu Jan 18 01:52:25 2007
New Revision: 497379

URL: http://svn.apache.org/viewvc?view=rev&rev=497379
Log:
Refactor and remove some duplicate code.

Modified:
    tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/authenticator/ClusterSingleSignOn.java

Modified: tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/authenticator/ClusterSingleSignOn.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/authenticator/ClusterSingleSignOn.java?view=diff&rev=497379&r1=497378&r2=497379
==============================================================================
--- tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/authenticator/ClusterSingleSignOn.java
(original)
+++ tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/authenticator/ClusterSingleSignOn.java
Thu Jan 18 01:52:25 2007
@@ -51,6 +51,8 @@
  * </ul>
  *
  * @author Fabien Carrion
+ * @author Peter Rossbach
+ * @version $Revision:$ $Date:$
  */
 
 public class ClusterSingleSignOn
@@ -178,20 +180,7 @@
      * @param session Session to be associated
      */
     protected void associate(String ssoId, Session session) {
-        if (cluster != null) {
-            messageNumber++;
-            SingleSignOnMessage msg =
-                new SingleSignOnMessage(cluster.getLocalMember(),
-                        ssoId, session.getId());
-            Manager mgr = session.getManager();
-            if ((mgr != null) && (mgr instanceof ClusterManager))
-                msg.setContextName(((ClusterManager) mgr).getName());
-            msg.setAction(SingleSignOnMessage.ADD_SESSION);
-            cluster.sendClusterDomain(msg);
-            if (containerLog.isDebugEnabled())
-                containerLog.debug("SingleSignOnMessage Send with action "
-                        + msg.getAction());
-        }
+        sendSSOId(ssoId,session,SingleSignOnMessage.ADD_SESSION) ;
         associateLocal(ssoId, session);
 
     }
@@ -210,21 +199,8 @@
      * @param session Session to be deregistered
      */
     protected void deregister(String ssoId, Session session) {
-        if (cluster != null) {
-            messageNumber++;
-            SingleSignOnMessage msg =
-                new SingleSignOnMessage(cluster.getLocalMember(),
-                        ssoId, session.getId());
-            Manager mgr = session.getManager();
-            if ((mgr != null) && (mgr instanceof ClusterManager))
-                msg.setContextName(((ClusterManager) mgr).getName());
-            msg.setAction(SingleSignOnMessage.DEREGISTER_SESSION);
-            cluster.sendClusterDomain(msg);
-            if (containerLog.isDebugEnabled())
-                containerLog.debug("SingleSignOnMessage Send with action "
-				   + msg.getAction());
-        }
-        deregisterLocal(ssoId, session);
+       sendSSOId(ssoId,session,SingleSignOnMessage.DEREGISTER_SESSION) ;
+       deregisterLocal(ssoId, session);
     }
 
     protected void deregisterLocal(String ssoId, Session session) {
@@ -240,17 +216,7 @@
      * @param ssoId Single sign on identifier to deregister
      */
     protected void deregister(String ssoId) {
-        if (cluster != null) {
-            messageNumber++;
-            SingleSignOnMessage msg =
-                new SingleSignOnMessage(cluster.getLocalMember(),
-                        ssoId, null);
-            msg.setAction(SingleSignOnMessage.LOGOUT_SESSION);
-            cluster.sendClusterDomain(msg);
-            if (containerLog.isDebugEnabled())
-                containerLog.debug("SingleSignOnMessage Send with action "
-                        + msg.getAction());
-        }
+        sendSSOId(ssoId,null,SingleSignOnMessage.LOGOUT_SESSION) ;
         deregisterLocal(ssoId);
     }
 
@@ -272,21 +238,10 @@
      */
     protected void register(String ssoId, Principal principal, String authType,
                   String username, String password) {
-    	if (cluster != null) {
-    	    messageNumber++;
-    	    SingleSignOnMessage msg =
-    		new SingleSignOnMessage(cluster.getLocalMember(),
-    					ssoId, null);
-    	    msg.setAction(SingleSignOnMessage.REGISTER_SESSION);
-    	    msg.setAuthType(authType);
-    	    msg.setUsername(username);
-    	    msg.setPassword(password);
-    	    cluster.sendClusterDomain(msg);
-    	    if (containerLog.isDebugEnabled())
-    		containerLog.debug("SingleSignOnMessage Send with action "
-    				   + msg.getAction());
-    	}
-    	registerLocal(ssoId, principal, authType, username, password);
+        sendSSOIdWithAuth(ssoId,
+                authType, username, password,
+                SingleSignOnMessage.REGISTER_SESSION);
+     	registerLocal(ssoId, principal, authType, username, password);
     }
 
     protected void registerLocal(String ssoId, Principal principal, String authType,
@@ -322,20 +277,9 @@
      */
     protected void update(String ssoId, Principal principal, String authType,
                           String username, String password) {
-        if (cluster != null) {
-            messageNumber++;
-            SingleSignOnMessage msg =
-                new SingleSignOnMessage(cluster.getLocalMember(),
-                        ssoId, null);
-            msg.setAction(SingleSignOnMessage.UPDATE_SESSION);
-            msg.setAuthType(authType);
-            msg.setUsername(username);
-            msg.setPassword(password);
-            cluster.sendClusterDomain(msg);
-            if (containerLog.isDebugEnabled())
-                containerLog.debug("SingleSignOnMessage Send with action "
-                        + msg.getAction());
-        }
+        sendSSOIdWithAuth(ssoId,
+                authType, username, password,
+                SingleSignOnMessage.UPDATE_SESSION);
         updateLocal(ssoId, principal, authType, username, password);
     }
 
@@ -352,25 +296,73 @@
      * @param session the session to be removed.
      */
     protected void removeSession(String ssoId, Session session) {
+        sendSSOId(ssoId,session,SingleSignOnMessage.REMOVE_SESSION) ;
+        removeSessionLocal(ssoId, session);
+    }
+
+    protected void removeSessionLocal(String ssoId, Session session) {
+        super.removeSession(ssoId, session);
+    }
+    
+    
+    /**
+     * Create SingleSignOnMessage with session informations and send to other domain members.
+     * @param ssoId     identifier of Single sign to be updated
+     * @param session   the session to be handle or null.
+     * @param action    SSO Action type
+     */
+    protected void sendSSOId(String ssoId, Session session, int action) {
         if (cluster != null) {
             messageNumber++;
+            String sessionId = null ;
+            if(session != null)
+                sessionId = session.getId() ;
             SingleSignOnMessage msg =
                 new SingleSignOnMessage(cluster.getLocalMember(),
-                        ssoId, session.getId());
-            Manager mgr = session.getManager();
-            if ((mgr != null) && (mgr instanceof ClusterManager))
-                msg.setContextName(((ClusterManager) mgr).getName());
-            msg.setAction(SingleSignOnMessage.REMOVE_SESSION);
-            cluster.sendClusterDomain(msg);
-            if (containerLog.isDebugEnabled())
-                containerLog.debug("SingleSignOnMessage Send with action "
-                        + msg.getAction());
+                        ssoId, sessionId);
+            if(session != null) {
+                Manager mgr = session.getManager();
+                if ((mgr != null) && (mgr instanceof ClusterManager))
+                    msg.setContextName(((ClusterManager) mgr).getName());
+            }
+            send(msg,action);
         }
-        removeSessionLocal(ssoId, session);
     }
 
-    protected void removeSessionLocal(String ssoId, Session session) {
-        super.removeSession(ssoId, session);
+    /**
+     * Create SingleSignOnMessage with auth informations and send to other domain members.
+     * @param ssoId     identifier of Single sign to be updated
+     * @param authType  the type of authenticator used (BASIC, CLIENT-CERT,
+     *                  DIGEST or FORM)
+     * @param username  the username (if any) used for the authentication
+     * @param password  the password (if any) used for the authentication
+     * @param action    SSO Action type
+     */
+    protected void sendSSOIdWithAuth(String ssoId,String authType,
+            String username, String password, int action) {
+        if (cluster != null) {
+            messageNumber++;
+            SingleSignOnMessage msg =
+                new SingleSignOnMessage(cluster.getLocalMember(),
+                        ssoId, null);
+            msg.setAuthType(authType);
+            msg.setUsername(username);
+            msg.setPassword(password);
+            send(msg,action);
+        }
+    }
+
+    /**
+     * Send SingleSignOnMessage to other domain members.
+     * @param msg     SingleSignOnMessage
+     * @param action  SSO Action type
+     */
+    protected void send(SingleSignOnMessage msg, int action) {
+        msg.setAction(action);
+        cluster.sendClusterDomain(msg);
+        if (containerLog.isDebugEnabled())
+            containerLog.debug("SingleSignOnMessage Send with action "
+                + action);
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message