shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r737637 - in /incubator/jsecurity/trunk/core/src/org/jsecurity/session: ReplacedSessionException.java mgt/DefaultSessionManager.java
Date Mon, 26 Jan 2009 05:32:59 GMT
Author: lhazlewood
Date: Mon Jan 26 05:32:58 2009
New Revision: 737637

URL: http://svn.apache.org/viewvc?rev=737637&view=rev
Log:
JSEC-46 Minor adjustment to catch a possible exception

Modified:
    incubator/jsecurity/trunk/core/src/org/jsecurity/session/ReplacedSessionException.java
    incubator/jsecurity/trunk/core/src/org/jsecurity/session/mgt/DefaultSessionManager.java

Modified: incubator/jsecurity/trunk/core/src/org/jsecurity/session/ReplacedSessionException.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/src/org/jsecurity/session/ReplacedSessionException.java?rev=737637&r1=737636&r2=737637&view=diff
==============================================================================
--- incubator/jsecurity/trunk/core/src/org/jsecurity/session/ReplacedSessionException.java
(original)
+++ incubator/jsecurity/trunk/core/src/org/jsecurity/session/ReplacedSessionException.java
Mon Jan 26 05:32:58 2009
@@ -36,8 +36,8 @@
         super();
     }
 
-    public ReplacedSessionException(String msg, Serializable originalSessionId, Serializable
newSessionId) {
-        super(msg, originalSessionId);
+    public ReplacedSessionException(String msg, Throwable cause, Serializable originalSessionId,
Serializable newSessionId) {
+        super(msg, cause, originalSessionId);
         this.newSessionId = newSessionId;
     }
 

Modified: incubator/jsecurity/trunk/core/src/org/jsecurity/session/mgt/DefaultSessionManager.java
URL: http://svn.apache.org/viewvc/incubator/jsecurity/trunk/core/src/org/jsecurity/session/mgt/DefaultSessionManager.java?rev=737637&r1=737636&r2=737637&view=diff
==============================================================================
--- incubator/jsecurity/trunk/core/src/org/jsecurity/session/mgt/DefaultSessionManager.java
(original)
+++ incubator/jsecurity/trunk/core/src/org/jsecurity/session/mgt/DefaultSessionManager.java
Mon Jan 26 05:32:58 2009
@@ -28,6 +28,7 @@
 import org.jsecurity.session.mgt.eis.MemorySessionDAO;
 import org.jsecurity.session.mgt.eis.SessionDAO;
 import org.jsecurity.util.CollectionUtils;
+import org.jsecurity.util.ThreadContext;
 
 import java.io.Serializable;
 import java.net.InetAddress;
@@ -107,26 +108,32 @@
 
     protected Session retrieveSession(Serializable sessionId) throws InvalidSessionException
{
         if (log.isTraceEnabled()) {
-            log.trace("Retrieving session with id [" + sessionId + "]");
+            log.trace("Attempting to retrieve session with id [" + sessionId + "]");
         }
-        Session s = sessionDAO.readSession(sessionId);
-        if ( isAutoCreateAfterInvalidation() ) {
+        InetAddress hostAddress = null;
+        try {
+            Session s = sessionDAO.readSession(sessionId);
             //save the host address in case the session will be invalidated.  We want to
retain it for the
             //replacement session:
-            InetAddress hostAddress = s.getHostAddress();
-            try {
-                validate(s);
-            } catch (InvalidSessionException e) {
+            hostAddress = s.getHostAddress();
+            validate(s);
+            return s;
+        } catch (InvalidSessionException ise) {
+            if (isAutoCreateAfterInvalidation()) {
+                if (hostAddress == null) {
+                    //try the threadContext as a last resort:
+                    hostAddress = ThreadContext.getInetAddress();
+                }
                 Serializable newId = start(hostAddress);
                 String msg = "Session with id [" + sessionId + "] is invalid.  The SessionManager
" +
                         "has been configured to automatically re-create sessions upon invalidation.
 Returnining " +
                         "new session id [" + newId + "] with exception so the caller may
react accordingly.";
-                throw new ReplacedSessionException(msg, sessionId, newId);
+                throw new ReplacedSessionException(msg, ise, sessionId, newId);
+            } else {
+                //propagate original exception:
+                throw ise;
             }
-        } else {
-            validate(s);
         }
-        return s;
     }
 
     protected Collection<Session> getActiveSessions() {



Mime
View raw message