shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r795260 - in /incubator/shiro/trunk/core/src: main/java/org/apache/shiro/session/mgt/AbstractSessionManager.java test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
Date Fri, 17 Jul 2009 22:47:12 GMT
Author: lhazlewood
Date: Fri Jul 17 22:47:11 2009
New Revision: 795260

URL: http://svn.apache.org/viewvc?rev=795260&view=rev
Log:
Fixed session timeout bug - globalSessionTimeout configuration was not being applied

Added:
    incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
Modified:
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/AbstractSessionManager.java

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/AbstractSessionManager.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/AbstractSessionManager.java?rev=795260&r1=795259&r2=795260&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/AbstractSessionManager.java
(original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/AbstractSessionManager.java
Fri Jul 17 22:47:11 2009
@@ -113,11 +113,15 @@
 
     public Serializable start(Map initData) throws AuthorizationException {
         Session session = createSession(initData);
+        applyGlobalSessionTimeout(session);
         onStart(session);
         notifyStart(session);
         return session.getId();
     }
 
+    protected void applyGlobalSessionTimeout(Session session) {
+        session.setTimeout(getGlobalSessionTimeout());
+    }
 
     /**
      * Returns the session instance to use to pass to registered {@code SessionListener}s
for notification

Added: incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java?rev=795260&view=auto
==============================================================================
--- incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
(added)
+++ incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
Fri Jul 17 22:47:11 2009
@@ -0,0 +1,48 @@
+package org.apache.shiro.session.mgt;
+
+import org.apache.shiro.util.ThreadContext;
+import org.junit.After;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.Serializable;
+import java.net.InetAddress;
+
+/**
+ * Unit test for the {@link DefaultSessionManager DefaultSessionManager} implementation.
+ */
+public class DefaultSessionManagerTest {
+
+    DefaultSessionManager sm = null;
+
+    @Before
+    public void setup() {
+        ThreadContext.clear();
+        sm = new DefaultSessionManager();
+    }
+
+    @After
+    public void tearDown() {
+        sm.destroy();
+        ThreadContext.clear();
+    }
+
+    public void sleep(long millis) {
+        try {
+            Thread.sleep(millis);
+        } catch (InterruptedException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    @Test
+    public void testGlobalTimeout() {
+        sm.setGlobalSessionTimeout(100);
+        Serializable sessionId = sm.start((InetAddress) null);
+        assertTrue(sm.isValid(sessionId));
+        sleep(100);
+        assertFalse(sm.isValid(sessionId));
+    }
+}



Mime
View raw message