shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r1022243 - in /shiro/trunk/core/src: main/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManager.java test/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManagerTest.java
Date Wed, 13 Oct 2010 19:10:49 GMT
Author: lhazlewood
Date: Wed Oct 13 19:10:48 2010
New Revision: 1022243

URL: http://svn.apache.org/viewvc?rev=1022243&view=rev
Log:
SHIRO-199: Committed fix w/ accompanying test case

Added:
    shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManagerTest.java
Modified:
    shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManager.java

Modified: shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManager.java
URL: http://svn.apache.org/viewvc/shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManager.java?rev=1022243&r1=1022242&r2=1022243&view=diff
==============================================================================
--- shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManager.java
(original)
+++ shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManager.java
Wed Oct 13 19:10:48 2010
@@ -272,7 +272,10 @@ public abstract class AbstractValidating
         if (activeSessions != null && !activeSessions.isEmpty()) {
             for (Session s : activeSessions) {
                 try {
-                    doValidate(s);
+                    //simulate a lookup key to satisfy the method signature.
+                    //this could probably stand to be cleaned up in future versions:
+                    SessionKey key = new DefaultSessionKey(s.getId());
+                    validate(s, key);
                 } catch (InvalidSessionException e) {
                     if (log.isDebugEnabled()) {
                         boolean expired = (e instanceof ExpiredSessionException);

Added: shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManagerTest.java
URL: http://svn.apache.org/viewvc/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManagerTest.java?rev=1022243&view=auto
==============================================================================
--- shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManagerTest.java
(added)
+++ shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManagerTest.java
Wed Oct 13 19:10:48 2010
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.session.mgt;
+
+import org.apache.shiro.authz.AuthorizationException;
+import org.apache.shiro.session.Session;
+import org.apache.shiro.session.SessionListener;
+import org.apache.shiro.session.SessionListenerAdapter;
+import org.apache.shiro.session.UnknownSessionException;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Unit tests for the {@link org.apache.shiro.session.mgt.AbstractValidatingSessionManager}
class.
+ */
+public class AbstractValidatingSessionManagerTest {
+
+    /**
+     * Tests that both SessionListeners are called and that invalid sessions are deleted
by default.
+     * Verifies <a href="https://issues.apache.org/jira/browse/SHIRO-199">SHIRO-199</a>.
+     */
+    @Test
+    public void testValidateSessions() {
+
+        final SimpleSession validSession = new SimpleSession();
+        validSession.setId(1);
+        final SimpleSession invalidSession = new SimpleSession();
+        //set to a time in the past:
+        Calendar cal = Calendar.getInstance();
+        Long expiredTimeout = AbstractSessionManager.DEFAULT_GLOBAL_SESSION_TIMEOUT + 1;
+        cal.add(Calendar.MILLISECOND, -(expiredTimeout.intValue()) );
+        Date past = cal.getTime();
+        invalidSession.setStartTimestamp(past);
+        invalidSession.setLastAccessTime(past);
+        invalidSession.setId(2);
+
+        final AtomicInteger expirationCount = new AtomicInteger();
+
+        SessionListener sessionListener = new SessionListenerAdapter() {
+            @Override
+            public void onExpiration(Session session) {
+                expirationCount.incrementAndGet();
+            }
+        };
+
+        AbstractValidatingSessionManager sessionManager = new AbstractValidatingSessionManager()
{
+            @Override
+            protected Session retrieveSession(SessionKey key) throws UnknownSessionException
{
+                throw new UnsupportedOperationException("Should not be called in this test.");
+            }
+
+            @Override
+            protected Session doCreateSession(SessionContext initData) throws AuthorizationException
{
+                throw new UnsupportedOperationException("Should not be called in this test.");
+            }
+
+            @Override
+            protected Collection<Session> getActiveSessions() {
+                Collection<Session> sessions = new ArrayList<Session>(2);
+                sessions.add(validSession);
+                sessions.add(invalidSession);
+                return sessions;
+            }
+        };
+
+        sessionManager.setSessionListeners(Arrays.asList(sessionListener));
+        sessionManager.validateSessions();
+        
+        assertEquals(1, expirationCount.intValue());
+    }
+}



Mime
View raw message