shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdem...@apache.org
Subject shiro git commit: SHIRO-437 Corrected WildcardPermissions toString when permission contained a comma.
Date Fri, 01 Jul 2016 22:23:46 GMT
Repository: shiro
Updated Branches:
  refs/heads/1.3.x 204e8e71f -> 012787434


SHIRO-437 Corrected WildcardPermissions toString when permission contained a comma.


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

Branch: refs/heads/1.3.x
Commit: 012787434c4b50843bca2a8bda59a7b76a553ce2
Parents: 204e8e7
Author: Brian Demers <bdemers@apache.org>
Authored: Fri Jul 1 18:19:27 2016 -0400
Committer: Brian Demers <bdemers@apache.org>
Committed: Fri Jul 1 18:19:43 2016 -0400

----------------------------------------------------------------------
 .../authz/permission/WildcardPermission.java    | 11 ++++++--
 .../permission/WildcardPermissionTest.java      | 29 ++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/shiro/blob/01278743/core/src/main/java/org/apache/shiro/authz/permission/WildcardPermission.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/shiro/authz/permission/WildcardPermission.java
b/core/src/main/java/org/apache/shiro/authz/permission/WildcardPermission.java
index 4149771..484ed97 100644
--- a/core/src/main/java/org/apache/shiro/authz/permission/WildcardPermission.java
+++ b/core/src/main/java/org/apache/shiro/authz/permission/WildcardPermission.java
@@ -24,6 +24,7 @@ import org.apache.shiro.util.StringUtils;
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -235,9 +236,15 @@ public class WildcardPermission implements Permission, Serializable {
         StringBuilder buffer = new StringBuilder();
         for (Set<String> part : parts) {
             if (buffer.length() > 0) {
-                buffer.append(":");
+                buffer.append(PART_DIVIDER_TOKEN);
+            }
+            Iterator<String> partIt = part.iterator();
+            while(partIt.hasNext()) {
+                buffer.append(partIt.next());
+                if (partIt.hasNext()) {
+                    buffer.append(SUBPART_DIVIDER_TOKEN);
+                }
             }
-            buffer.append(part);
         }
         return buffer.toString();
     }

http://git-wip-us.apache.org/repos/asf/shiro/blob/01278743/core/src/test/java/org/apache/shiro/authz/permission/WildcardPermissionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/shiro/authz/permission/WildcardPermissionTest.java
b/core/src/test/java/org/apache/shiro/authz/permission/WildcardPermissionTest.java
index 56cea74..d1eb5a5 100644
--- a/core/src/test/java/org/apache/shiro/authz/permission/WildcardPermissionTest.java
+++ b/core/src/test/java/org/apache/shiro/authz/permission/WildcardPermissionTest.java
@@ -126,7 +126,17 @@ public class WildcardPermissionTest {
         assertFalse(p2.implies(p1));
         assertFalse(p3.implies(p1));
         assertTrue(p2.implies(p3));
+    }
+
+    /**
+     * Validates WildcardPermissions with that contain the same list parts are equal.
+     */
+    @Test
+    public void testListDifferentOrder() {
 
+        WildcardPermission p6 = new WildcardPermission("one,two:three,four");
+        WildcardPermission p6DiffOrder = new WildcardPermission("two,one:four,three");
+        assertTrue(p6.equals(p6DiffOrder));
     }
 
     @Test
@@ -196,4 +206,23 @@ public class WildcardPermissionTest {
 
     }
 
+    @Test
+    public void testToString() {
+        WildcardPermission p1 = new WildcardPermission("*");
+        WildcardPermission p2 = new WildcardPermission("one");
+        WildcardPermission p3 = new WildcardPermission("one:two");
+        WildcardPermission p4 = new WildcardPermission("one,two:three,four");
+        WildcardPermission p5 = new WildcardPermission("one,two:three,four,five:six:seven,eight");
+
+        assertTrue("*".equals(p1.toString()));
+        assertTrue(p1.equals(new WildcardPermission(p1.toString())));
+        assertTrue("one".equals(p2.toString()));
+        assertTrue(p2.equals(new WildcardPermission(p2.toString())));
+        assertTrue("one:two".equals(p3.toString()));
+        assertTrue(p3.equals(new WildcardPermission(p3.toString())));
+        assertTrue("one,two:three,four".equals(p4.toString()));
+        assertTrue(p4.equals(new WildcardPermission(p4.toString())));
+        assertTrue("one,two:three,four,five:six:seven,eight".equals(p5.toString()));
+        assertTrue(p5.equals(new WildcardPermission(p5.toString())));
+    }
 }
\ No newline at end of file


Mime
View raw message