portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r331641 - in /portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed: engine/JetspeedServlet.java pipeline/valve/SecurityValve.java security/impl/SecurityValveImpl.java
Date Mon, 07 Nov 2005 23:35:56 GMT
Author: taylor
Date: Mon Nov  7 15:35:53 2005
New Revision: 331641

URL: http://svn.apache.org/viewcvs?rev=331641&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-362

User statistics implemented

Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/pipeline/valve/SecurityValve.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/security/impl/SecurityValveImpl.java

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java?rev=331641&r1=331640&r2=331641&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/engine/JetspeedServlet.java
Mon Nov  7 15:35:53 2005
@@ -17,13 +17,17 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.security.Principal;
 
+import javax.security.auth.Subject;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.PropertiesConfiguration;
@@ -31,13 +35,18 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.Jetspeed;
+import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.components.ComponentManager;
 import org.apache.jetspeed.components.SpringComponentManager;
 import org.apache.jetspeed.components.factorybeans.ServletConfigFactoryBean;
 import org.apache.jetspeed.engine.servlet.ServletHelper;
 import org.apache.jetspeed.exception.JetspeedException;
+import org.apache.jetspeed.pipeline.valve.SecurityValve;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.request.RequestContextComponent;
+import org.apache.jetspeed.security.SecurityHelper;
+import org.apache.jetspeed.security.UserPrincipal;
+import org.apache.jetspeed.statistics.PortalStatistics;
 
 /**
  * Jetspeed Servlet entry point.
@@ -45,7 +54,9 @@
  * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor </a>
  * @version $Id$
  */
-public class JetspeedServlet extends HttpServlet implements JetspeedEngineConstants
+public class JetspeedServlet 
+extends HttpServlet 
+implements JetspeedEngineConstants, HttpSessionListener
 {
     private final static Log log = LogFactory.getLog(JetspeedServlet.class);
     private final static Log console = LogFactory.getLog(CONSOLE_LOGGER);
@@ -310,5 +321,19 @@
         SpringComponentManager cm = new SpringComponentManager(bootConfigs, appConfigs, servletContext,
appRoot);      
         
         return cm;        
+    }
+    
+    public void sessionCreated(HttpSessionEvent se)
+    {
+    }
+    
+    public void sessionDestroyed(HttpSessionEvent se)
+    {
+        Subject subject = (Subject)se.getSession().getAttribute(PortalReservedParameters.SESSION_KEY_SUBJECT);
+        Principal subjectUserPrincipal = SecurityHelper.getPrincipal(subject, UserPrincipal.class);
+        PortalStatistics statistics = (PortalStatistics)engine.getComponentManager().getComponent("PortalStatistics");
+        long sessionLength = System.currentTimeMillis() - se.getSession().getCreationTime();
+        String ipAddress = (String)se.getSession().getAttribute(SecurityValve.IP_ADDRESS);
+        statistics.logUserLogout(ipAddress, subjectUserPrincipal.getName(), sessionLength);
       
     }
 }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/pipeline/valve/SecurityValve.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/pipeline/valve/SecurityValve.java?rev=331641&r1=331640&r2=331641&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/pipeline/valve/SecurityValve.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/pipeline/valve/SecurityValve.java
Mon Nov  7 15:35:53 2005
@@ -15,6 +15,8 @@
  */
 package org.apache.jetspeed.pipeline.valve;
 
+import org.apache.jetspeed.security.impl.SecurityValveImpl;
+
 /**
  * Authenticates the User or redirects to Login if necessary, add
  * authenticated Subject to RequestContext
@@ -39,4 +41,5 @@
  */
 public interface SecurityValve extends Valve
 {
+    final String IP_ADDRESS = SecurityValveImpl.class.getName() + ".ipaddress";    
 }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/security/impl/SecurityValveImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/security/impl/SecurityValveImpl.java?rev=331641&r1=331640&r2=331641&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/security/impl/SecurityValveImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/security/impl/SecurityValveImpl.java
Mon Nov  7 15:35:53 2005
@@ -32,6 +32,7 @@
 import org.apache.jetspeed.security.User;
 import org.apache.jetspeed.security.UserManager;
 import org.apache.jetspeed.security.UserPrincipal;
+import org.apache.jetspeed.statistics.PortalStatistics;
 
 /**
  * SecurityValve
@@ -46,11 +47,13 @@
     private static final Log log = LogFactory.getLog(SecurityValveImpl.class);
     private Profiler profiler;
     private UserManager userMgr;
+    private PortalStatistics statistics;
 
-    public SecurityValveImpl( Profiler profiler, UserManager userMgr )
+    public SecurityValveImpl( Profiler profiler, UserManager userMgr, PortalStatistics statistics
)
     {
         this.profiler = profiler;
         this.userMgr = userMgr;
+        this.statistics = statistics;
     }
 
     public String toString()
@@ -110,12 +113,17 @@
                 Set principals = new HashSet();
                 principals.add(userPrincipal);
                 subject = new Subject(true, principals, new HashSet(), new HashSet());
-            }           
+            } 
+            
+            // create a new statistics *user* session
+            statistics.logUserLogin(request, 0);
+            // put IP address in session for logout
+            request.setSessionAttribute(IP_ADDRESS, request.getRequest().getRemoteAddr());
         }
         
         return subject;
     }
-    
+        
     /**
      * 
      * <p>



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


Mime
View raw message