shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r911459 - in /incubator/shiro/trunk/core/src: main/java/org/apache/shiro/mgt/AbstractRememberMeManager.java test/java/org/apache/shiro/mgt/AbstractRememberMeManagerTest.java
Date Thu, 18 Feb 2010 16:00:27 GMT
Author: lhazlewood
Date: Thu Feb 18 16:00:27 2010
New Revision: 911459

URL: http://svn.apache.org/viewvc?rev=911459&view=rev
Log:
SHIRO-138 - fixed bug and added accompanying test case

Added:
    incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/AbstractRememberMeManagerTest.java
Modified:
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/mgt/AbstractRememberMeManager.java

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/mgt/AbstractRememberMeManager.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/mgt/AbstractRememberMeManager.java?rev=911459&r1=911458&r2=911459&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/mgt/AbstractRememberMeManager.java
(original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/mgt/AbstractRememberMeManager.java
Thu Feb 18 16:00:27 2010
@@ -477,12 +477,18 @@
      * @return the remembered principals or {@code null} if none could be acquired.
      */
     public PrincipalCollection getRememberedPrincipals(Map subjectContext) {
+        PrincipalCollection principals = null;
         try {
             byte[] bytes = getRememberedSerializedIdentity(subjectContext);
-            return convertBytesToPrincipals(bytes, subjectContext);
+            //SHIRO-138 - only call convertBytesToPrincipals if bytes exist:
+            if ( bytes != null && bytes.length > 0 ) {
+                principals = convertBytesToPrincipals(bytes, subjectContext);
+            }
         } catch (RuntimeException re) {
-            return onRememberedPrincipalFailure(re, subjectContext);
+            principals = onRememberedPrincipalFailure(re, subjectContext);
         }
+
+        return principals;
     }
 
     /**

Added: incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/AbstractRememberMeManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/AbstractRememberMeManagerTest.java?rev=911459&view=auto
==============================================================================
--- incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/AbstractRememberMeManagerTest.java
(added)
+++ incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/AbstractRememberMeManagerTest.java
Thu Feb 18 16:00:27 2010
@@ -0,0 +1,79 @@
+/*
+ * 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.mgt;
+
+import org.apache.shiro.subject.PrincipalCollection;
+import org.apache.shiro.subject.Subject;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertNull;
+
+/**
+ * Test cases for the {@link AbstractRememberMeManager} implementation.
+ */
+public class AbstractRememberMeManagerTest {
+
+    /**
+     * Tests the {@link AbstractRememberMeManager#getRememberedPrincipals(java.util.Map)}
method
+     * implementation when the internal
+     * {@link AbstractRememberMeManager#getRememberedSerializedIdentity(java.util.Map)} method
+     * returns null or empty bytes.
+     */
+    @Test
+    public void testGetRememberedPrincipalsWithEmptySerializedBytes() {
+        AbstractRememberMeManager rmm = new DummyRememberMeManager();
+        //Since the dummy's getRememberedSerializedIdentity implementation returns an empty
byte
+        //array, we should be ok:
+        PrincipalCollection principals = rmm.getRememberedPrincipals(new HashMap());
+        assertNull(principals);
+
+        //try with a null return value too:
+        rmm = new DummyRememberMeManager() {
+            @Override
+            protected byte[] getRememberedSerializedIdentity(Map subjectContext) {
+                return null;
+            }
+        };
+        principals = rmm.getRememberedPrincipals(new HashMap());
+        assertNull(principals);
+    }
+
+    private static class DummyRememberMeManager extends AbstractRememberMeManager {
+        @Override
+        protected void forgetIdentity(Map subjectContext) {
+            //do nothing
+        }
+
+        @Override
+        protected void forgetIdentity(Subject subject) {
+        }
+
+        @Override
+        protected void rememberSerializedIdentity(Subject subject, byte[] serialized) {
+        }
+
+        @Override
+        protected byte[] getRememberedSerializedIdentity(Map subjectContext) {
+            return new byte[0];
+        }
+    }
+}



Mime
View raw message