You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by ka...@apache.org on 2010/05/15 07:44:20 UTC
svn commit: r944573 - in /incubator/shiro/trunk/core/src:
main/java/org/apache/shiro/authc/SimpleAuthenticationInfo.java
test/java/org/apache/shiro/authc/SimpleAuthenticationInfoTest.java
Author: kaosko
Date: Sat May 15 05:44:20 2010
New Revision: 944573
URL: http://svn.apache.org/viewvc?rev=944573&view=rev
Log:
FIXED - issue SHIRO-156: SimpleAuthenticationInfo.merge does not merge principals if its internal principal collection is not mutable
https://issues.apache.org/jira/browse/SHIRO-156
- modified as suggested
- Added a unit test to assert the case
Modified:
incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authc/SimpleAuthenticationInfo.java
incubator/shiro/trunk/core/src/test/java/org/apache/shiro/authc/SimpleAuthenticationInfoTest.java
Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authc/SimpleAuthenticationInfo.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authc/SimpleAuthenticationInfo.java?rev=944573&r1=944572&r2=944573&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authc/SimpleAuthenticationInfo.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authc/SimpleAuthenticationInfo.java Sat May 15 05:44:20 2010
@@ -122,12 +122,11 @@ public class SimpleAuthenticationInfo im
if (this.principals == null) {
this.principals = info.getPrincipals();
} else {
- if (this.principals instanceof MutablePrincipalCollection) {
- ((MutablePrincipalCollection) this.principals).addAll(info.getPrincipals());
- } else {
+ if (!(this.principals instanceof MutablePrincipalCollection)) {
this.principals = new SimplePrincipalCollection(this.principals);
}
- }
+ ((MutablePrincipalCollection) this.principals).addAll(info.getPrincipals());
+ }
Object thisCredentials = getCredentials();
Object otherCredentials = info.getCredentials();
Modified: incubator/shiro/trunk/core/src/test/java/org/apache/shiro/authc/SimpleAuthenticationInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/test/java/org/apache/shiro/authc/SimpleAuthenticationInfoTest.java?rev=944573&r1=944572&r2=944573&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/test/java/org/apache/shiro/authc/SimpleAuthenticationInfoTest.java (original)
+++ incubator/shiro/trunk/core/src/test/java/org/apache/shiro/authc/SimpleAuthenticationInfoTest.java Sat May 15 05:44:20 2010
@@ -18,11 +18,22 @@
*/
package org.apache.shiro.authc;
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.shiro.subject.PrincipalCollection;
import org.junit.Test;
/**
* @author Les Hazlewood
+ * @author Kalle Korhonen
* @since 0.9
*/
public class SimpleAuthenticationInfoTest {
@@ -43,4 +54,40 @@ public class SimpleAuthenticationInfoTes
SimpleAuthenticationInfo local = new SimpleAuthenticationInfo("username", "password", "testRealm");
aggregate.merge(local);
}
+
+ @SuppressWarnings("serial")
+ @Test
+ public void testMergeWithImmutablePrincipalCollection() {
+ SimpleAuthenticationInfo aggregate = new SimpleAuthenticationInfo();
+ // Make a quick test fixture that does *not* implement MutablePrincipalCollection
+ PrincipalCollection principalCollection = new PrincipalCollection() {
+ @SuppressWarnings("unchecked")
+ public List asList() { return null;}
+ @SuppressWarnings("unchecked")
+ public Set asSet() {return null;}
+ public <T> Collection<T> byType(Class<T> type) {return null;}
+ @SuppressWarnings("unchecked")
+ public Collection fromRealm(String realmName) {
+ Collection<Object> principals = new HashSet<Object>();
+ principals.add("testprincipal");
+ return principals;
+ }
+ public Object getPrimaryPrincipal() {return null;}
+ public Set<String> getRealmNames() {
+ Set<String> realms = new HashSet<String>();
+ realms.add("testrealm");
+ return realms;
+ }
+ public boolean isEmpty() {return false;}
+ public <T> T oneByType(Class<T> type) {return null;}
+ @SuppressWarnings("unchecked")
+ public Iterator iterator() {return null;}
+
+ };
+ aggregate.setPrincipals(principalCollection);
+ SimpleAuthenticationInfo local = new SimpleAuthenticationInfo("username", "password", "testRealm");
+ aggregate.merge(local);
+ assertEquals(2, aggregate.getPrincipals().asList().size());
+ }
+
}