shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kao...@apache.org
Subject svn commit: r961162 - in /incubator/shiro/trunk/core/src: main/java/org/apache/shiro/session/mgt/SimpleSession.java test/java/org/apache/shiro/session/mgt/SimpleSessionTest.java
Date Wed, 07 Jul 2010 04:12:27 GMT
Author: kaosko
Date: Wed Jul  7 04:12:26 2010
New Revision: 961162

URL: http://svn.apache.org/viewvc?rev=961162&view=rev
Log:
FIXED - issue SHIRO-182: SimpleSession cannot be deserialized 
https://issues.apache.org/jira/browse/SHIRO-182
- fixed the incorrect comparison of expired flag in getAlteredFieldsBitMask
- added two unit tests

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

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/SimpleSession.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/SimpleSession.java?rev=961162&r1=961161&r2=961162&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/SimpleSession.java
(original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/SimpleSession.java
Wed Jul  7 04:12:26 2010
@@ -500,7 +500,7 @@ public class SimpleSession implements Va
         bitMask = stopTimestamp != null ? bitMask | STOP_TIMESTAMP_BIT_MASK : bitMask;
         bitMask = lastAccessTime != null ? bitMask | LAST_ACCESS_TIME_BIT_MASK : bitMask;
         bitMask = timeout != 0l ? bitMask | TIMEOUT_BIT_MASK : bitMask;
-        bitMask = !expired ? bitMask | EXPIRED_BIT_MASK : bitMask;
+        bitMask = expired ? bitMask | EXPIRED_BIT_MASK : bitMask;
         bitMask = host != null ? bitMask | HOST_BIT_MASK : bitMask;
         bitMask = !CollectionUtils.isEmpty(attributes) ? bitMask | ATTRIBUTES_BIT_MASK :
bitMask;
         return (short) bitMask;

Added: incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/SimpleSessionTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/SimpleSessionTest.java?rev=961162&view=auto
==============================================================================
--- incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/SimpleSessionTest.java
(added)
+++ incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/SimpleSessionTest.java
Wed Jul  7 04:12:26 2010
@@ -0,0 +1,35 @@
+package org.apache.shiro.session.mgt;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.junit.Test;
+
+public class SimpleSessionTest {
+    @Test
+    public void serializeHost() throws IOException, ClassNotFoundException {
+	SimpleSession session = new SimpleSession("localhost");
+	assertEquals("localhost", serializeAndDeserialize(session).getHost());
+    }
+    
+    @Test
+    public void serializeExpired() throws IOException, ClassNotFoundException {
+	SimpleSession session = new SimpleSession();
+	session.setExpired(true);
+	assertTrue(serializeAndDeserialize(session).isExpired());
+    }
+    
+    private SimpleSession serializeAndDeserialize(SimpleSession session) throws IOException,
ClassNotFoundException {
+	ByteArrayOutputStream serialized = new ByteArrayOutputStream();
+	ObjectOutputStream serializer = new ObjectOutputStream(serialized);
+	serializer.writeObject(session);
+	serializer.close();
+	return (SimpleSession) new ObjectInputStream(new ByteArrayInputStream(serialized.toByteArray())).readObject();
	
+    }
+}



Mime
View raw message