Repository: shiro
Updated Branches:
  refs/heads/master 64955340c -> 63f2891d4


SHIRO-577 Fixes bug allow enabling of SessionValidationScheduler when set via 
setSessionValidationScheduler

If a SessionValidationScheduler was set via 
sessionManager.setSessionValidationScheduler, instead of using the
default creation of the object in enableSessionValidation, the 
SessionValidationScheduler would not be enabled.


Project: http://git-wip-us.apache.org/repos/asf/shiro/repo
Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/63f2891d
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/63f2891d
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/63f2891d

Branch: refs/heads/master
Commit: 63f2891d48a37c7261c4f7eba7ab0ae5e17cb23a
Parents: 6495534
Author: Brian Demers <[email protected]>
Authored: Fri Jul 29 12:13:46 2016 -0400
Committer: Brian Demers <[email protected]>
Committed: Tue Aug 9 10:03:03 2016 -0400

----------------------------------------------------------------------
 .../mgt/AbstractValidatingSessionManager.java   |  4 ++++
 .../session/mgt/DefaultSessionManagerTest.java  | 25 ++++++++++++++++++++
 2 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/shiro/blob/63f2891d/core/src/main/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManager.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManager.java
 
b/core/src/main/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManager.java
index 6c59d77..cdfeded 100644
--- 
a/core/src/main/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManager.java
+++ 
b/core/src/main/java/org/apache/shiro/session/mgt/AbstractValidatingSessionManager.java
@@ -225,6 +225,10 @@ public abstract class AbstractValidatingSessionManager 
extends AbstractNativeSes
         if (scheduler == null) {
             scheduler = createSessionValidationScheduler();
             setSessionValidationScheduler(scheduler);
+        }
+        // it is possible that that a scheduler was already created and set 
via 'setSessionValidationScheduler()'
+        // but would not have been enabled/started yet
+        if (!scheduler.isEnabled()) {
             if (log.isInfoEnabled()) {
                 log.info("Enabling session validation scheduler...");
             }

http://git-wip-us.apache.org/repos/asf/shiro/blob/63f2891d/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
 
b/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
index 7dec6aa..41875ea 100644
--- 
a/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
+++ 
b/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
@@ -196,6 +196,31 @@ public class DefaultSessionManagerTest {
         verify(sessionDAO); //verify that the delete call was actually made on 
the DAO
     }
 
+    /**
+     * Tests a bug introduced by SHIRO-443, where a custom 
sessionValidationScheduler would not be started.
+     */
+    @Test
+    public void testEnablingOfCustomSessionValidationScheduler() {
+
+        // using the default impl of sessionValidationScheduler, as the but 
effects any scheduler we set directly via
+        // sessionManager.setSessionValidationScheduler(), commonly used in 
INI configuration.
+        ExecutorServiceSessionValidationScheduler sessionValidationScheduler = 
new ExecutorServiceSessionValidationScheduler();
+        DefaultSessionManager sessionManager = new DefaultSessionManager();
+        
sessionManager.setSessionValidationScheduler(sessionValidationScheduler);
+
+        // starting a session will trigger the starting of the validator
+        try {
+            Session session = sessionManager.start(null);
+
+            // now sessionValidationScheduler should be enabled
+            assertTrue("sessionValidationScheduler was not enabled", 
sessionValidationScheduler.isEnabled());
+        }
+        finally {
+            // cleanup after test
+            sessionManager.destroy();
+        }
+    }
+
     public static <T extends Session> T eqSessionTimeout(long timeout) {
         EasyMock.reportMatcher(new SessionTimeoutMatcher(timeout));
         return null;

Reply via email to