jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1099172 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/security/authorization/GlobPattern.java test/java/org/apache/jackrabbit/core/security/authorization/GlobPatternTest.java
Date Tue, 03 May 2011 18:22:01 GMT
Author: angela
Date: Tue May  3 18:22:01 2011
New Revision: 1099172

URL: http://svn.apache.org/viewvc?rev=1099172&view=rev
Log:
JCR-2937 : ACL with glob restrictions does not work on '/'

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/GlobPattern.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/GlobPatternTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/GlobPattern.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/GlobPattern.java?rev=1099172&r1=1099171&r2=1099172&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/GlobPattern.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/GlobPattern.java
Tue May  3 18:22:01 2011
@@ -218,8 +218,9 @@ public final class GlobPattern {
                 // shortcut: verify if end of pattern matches end of toMatch
                 return false;
             }
+            char[] tm = (toMatch.endsWith("/")) ? toMatch.substring(0, toMatch.length()-1).toCharArray()
: toMatch.toCharArray();
             // shortcut didn't reveal mismatch -> need to process the internal match method.
-            return matches(patternChars, 0, toMatch.toCharArray(), 0);
+            return matches(patternChars, 0, tm, 0);
         }
 
         /**

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/GlobPatternTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/GlobPatternTest.java?rev=1099172&r1=1099171&r2=1099172&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/GlobPatternTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/GlobPatternTest.java
Tue May  3 18:22:01 2011
@@ -30,6 +30,11 @@ public class GlobPatternTest extends JUn
 
     private static Logger log = LoggerFactory.getLogger(GlobPatternTest.class);
 
+    private static void assertMatch(GlobPattern gp, String testPath, Boolean expectedResult)
{
+        Boolean match = Boolean.valueOf(gp.matches(testPath));
+        assertEquals("Pattern : " + gp + "; TestPath : " + testPath, expectedResult, match);
+    }
+
     public void testMatchesNoMetaChar() {
         GlobPattern gp = GlobPattern.create("/a/b/c");
 
@@ -43,7 +48,6 @@ public class GlobPatternTest extends JUn
         tests.put("/a", false);
         tests.put("/b/c", false);
         for (String toTest : tests.keySet()) {
-            log.info(gp + " - " + toTest + " : " + tests.get(toTest));
             assertTrue(tests.get(toTest) == gp.matches(toTest));
         }
     }
@@ -54,25 +58,26 @@ public class GlobPatternTest extends JUn
 
         // restriction "*" matches /foo, all siblings of foo and foo's and the siblings'
descendants
         GlobPattern gp = GlobPattern.create("/a/b/c", "*");
+        // matching
         tests.put("/a/b/c", true);        // foo itself
         tests.put("/a/b/c/d", true);      // child of foo
         tests.put("/a/b/c/d/e", true);    // child of foo
         tests.put("/a/b/c/d/e/f", true);  // child of foo
         tests.put("/a/b/cde", true);      // sibling
         tests.put("/a/b/cde/e/f", true);  // child of the sibling
-
+        // not-matching
         tests.put("/", false);
         tests.put("/a", false);
         tests.put("/b/c", false);
 
-        for (String toTest : tests.keySet()) {
-            log.info(gp + " - " + toTest + " : " + tests.get(toTest));
-            assertTrue(gp + " : " + toTest, tests.get(toTest) == gp.matches(toTest));
+        for (String testPath : tests.keySet()) {
+            assertMatch(gp, testPath, tests.get(testPath));
         }
 
         // restriction "*cat" matches all siblings and descendants of /foo that have a name
ending with cat
         gp = GlobPattern.create("/a/b/c", "*e");
         tests = new HashMap<String,Boolean>();
+        // matching
         tests.put("/a/b/c/e", true);      // descendant with name segment 'e'
         tests.put("/a/b/c/d/e", true);    // descendant with name segment 'e'
         tests.put("/a/b/c/gge", true);    // descendant with name segment ending with 'e'
@@ -83,7 +88,7 @@ public class GlobPatternTest extends JUn
         tests.put("/a/b/cd/f/e", true);   // descendant of sibling named 'e'
         tests.put("/a/b/cd/e", true);     // descendant of sibling with name ending with
'e'
         tests.put("/a/b/cd/f/e", true);   // descendant of sibling with name ending with
'e'
-
+        // not-matching
         tests.put("/", false);
         tests.put("/a", false);
         tests.put("/b/c", false);
@@ -97,19 +102,19 @@ public class GlobPatternTest extends JUn
         tests.put("/a/b/ce/", false);
         tests.put("/a/b/ceg", false);
         
-        for (String toTest : tests.keySet()) {
-            log.info(gp + " - " + toTest + " : " + tests.get(toTest));
-            assertTrue(gp + " : " + toTest, tests.get(toTest) == gp.matches(toTest));
+        for (String testPath : tests.keySet()) {
+            assertMatch(gp, testPath, tests.get(testPath));
         }
 
         // restriction "*/cat" matches all descendants of /foo and foo's siblings that have
a name segment "cat"
         gp = GlobPattern.create("/a/b/c", "*/e");
         tests = new HashMap<String,Boolean>();
+        // matching
         tests.put("/a/b/c/e", true);      // descendant with name segment 'e'
         tests.put("/a/b/c/d/e", true);    // descendant with name segment 'e'
         tests.put("/a/b/cd/e", true);     // descendant of sibling named 'e'
         tests.put("/a/b/cd/f/e", true);   // descendant of sibling named 'e'
-
+        // not-matching
         tests.put("/", false);
         tests.put("/a", false);
         tests.put("/b/c", false);
@@ -121,57 +126,128 @@ public class GlobPatternTest extends JUn
         tests.put("/a/b/c/d/f/f", false);
         tests.put("/a/b/c/e/f", false);
         tests.put("/a/b/ce/", false);
-        for (String toTest : tests.keySet()) {
-            log.info(gp + " - " + toTest + " : " + tests.get(toTest));
-            assertTrue(gp + " : " + toTest, tests.get(toTest) == gp.matches(toTest));
+
+        for (String testPath : tests.keySet()) {
+            assertMatch(gp, testPath, tests.get(testPath));
         }
 
+        // matches target path '/a/b/c/e', all siblings whose name starts with e
+        // and child nodes of either.
+        gp = GlobPattern.create("/a/b/c/e", "*");
+        tests = new HashMap<String,Boolean>();
+        // matching
+        tests.put("/a/b/c/e/f/g/h", true);
+        tests.put("/a/b/c/e/d/e/f", true);
+        tests.put("/a/b/c/e/d/e/f", true);
+        tests.put("/a/b/c/e", true);
+        tests.put("/a/b/c/e/", true);
+        tests.put("/a/b/c/ef", true);
+        tests.put("/a/b/c/ef/g", true);
+        // not-matching
+        tests.put("/a/b/ce/f/g/h", false);
+        tests.put("/a/b/ce/d/e/f", false);
+        tests.put("/a/b/c", false);
+        tests.put("/a/b/c/d", false);
+        tests.put("/a/b/c/d/e/f", false);
+        tests.put("/a/b/c/d/f/f", false);
+        tests.put("/a/b/c/d/f/e/f", false);
+        tests.put("/a/b/cee/d/e/f", false);
+
+        for (String testPath : tests.keySet()) {
+            assertMatch(gp, testPath, tests.get(testPath));
+        }
+        
         // all descendants of '/a/b/c/e'
+        gp = GlobPattern.create("/a/b/c/e", "/*");
+        tests = new HashMap<String,Boolean>();
+        // matching
+        tests.put("/a/b/c/e/f/g/h", true);
+        tests.put("/a/b/c/e/d/e/f", true);
+        // not-matching
+        tests.put("/a/b/c/e", false);  // not matching node path
+        tests.put("/a/b/c/e/", false); // not matching node path + /
+        tests.put("/a/b/c/ef", false); // not matching siblings of node path
+        tests.put("/a/b/ce/f/g/h", false);
+        tests.put("/a/b/ce/d/e/f", false);
+        tests.put("/a/b/c", false);
+        tests.put("/a/b/c/d", false);
+        tests.put("/a/b/c/d/e", false);
+        tests.put("/a/b/c/d/e/f", false);
+        tests.put("/a/b/c/d/f/f", false);
+        tests.put("/a/b/c/d/f/e/f", false);
+        tests.put("/a/b/cee/d/e/f", false);
+
+        for (String testPath : tests.keySet()) {
+            assertMatch(gp, testPath, tests.get(testPath));
+        }
+
+        // all descendants of '/a/b/ce'
         gp = GlobPattern.create("/a/b/c", "e/*");
         tests = new HashMap<String,Boolean>();
-        tests.put("/a/b/ce/", true);
+        // not-matching
         tests.put("/a/b/ce/f/g/h", true);
         tests.put("/a/b/ce/d/e/f", true);
-
+        // not-matching
         tests.put("/a/b/c", false);
+        tests.put("/a/b/ce", false);
         tests.put("/a/b/c/d", false);
         tests.put("/a/b/c/d/e", false);
         tests.put("/a/b/c/d/e/f", false);
         tests.put("/a/b/c/d/f/f", false);
         tests.put("/a/b/c/d/f/e/f", false);
         tests.put("/a/b/cee/d/e/f", false);
-        for (String toTest : tests.keySet()) {
-            log.info(gp + " - " + toTest + " : " + tests.get(toTest));
-            assertTrue(gp + " : " + toTest, tests.get(toTest) == gp.matches(toTest));
+        tests.put("/a/b/ce/", false);       // missing * after ce/
+
+        for (String testPath : tests.keySet()) {
+            assertMatch(gp, testPath, tests.get(testPath));
+        }
+                
+        // all descendants of '/'
+        gp = GlobPattern.create("/", "*");
+        tests = new HashMap<String,Boolean>();
+        // matching
+        tests.put("/a", true);
+        tests.put("/b/", true);
+        tests.put("/c/d", true);
+        tests.put("/a/b/ce/", true);
+        tests.put("/a/b/ce/f/g/h", true);
+        tests.put("/a/b/ce/d/e/f", true);
+        // not-matching
+        tests.put("/", false);
+
+        for (String testPath : tests.keySet()) {
+            assertMatch(gp, testPath, tests.get(testPath));
         }
 
         // restriction "*e/*" matches all descendants of /foo that have an intermediate segment
ending with 'e'
         gp = GlobPattern.create("/a/b/c", "*e/*");
         tests = new HashMap<String,Boolean>();
-        tests.put("/a/b/ce/", true);
+        // matching
         tests.put("/a/b/ceeeeeee/f/g/h", true);
         tests.put("/a/b/cde/d/e/f", true);
         tests.put("/a/b/c/d/e/f", true);
-        tests.put("/a/b/c/d/e/", true);
-        tests.put("/a/b/ced/d/e/f", true);        
-        
-        tests.put("/a/b/c/d", false);
-        tests.put("/a/b/c/d/e", false);
-        tests.put("/a/b/c/d/f/f", false);
-        tests.put("/a/b/c/ed/f/f", false);
-        for (String toTest : tests.keySet()) {
-            log.info(gp + " - " + toTest + " : " + tests.get(toTest));
-            assertTrue(gp + " : " + toTest, tests.get(toTest) == gp.matches(toTest));
+        tests.put("/a/b/ced/d/e/f", true);
+        // not-matching
+        tests.put("/a/b/ce/", false);      // ignore trailing / in test path
+        tests.put("/a/b/c/d/e/", false);   // ignore trailing / in test path
+        tests.put("/a/b/c/d", false);      // missing *e/*
+        tests.put("/a/b/c/d/e", false);    // missing /*
+        tests.put("/a/b/c/d/f/f", false);  // missing *e
+        tests.put("/a/b/c/ed/f/f", false); // missing e/
+
+        for (String testPath : tests.keySet()) {
+            assertMatch(gp, testPath, tests.get(testPath));
         }
 
         //  restriction /*cat  matches all children of /a/b/c whose path ends with "cat"
         gp = GlobPattern.create("/a/b/c", "/*cat");
         tests = new HashMap<String,Boolean>();
+        // matching
         tests.put("/a/b/c/cat", true);
         tests.put("/a/b/c/acat", true);
         tests.put("/a/b/c/f/cat", true);
         tests.put("/a/b/c/f/acat", true);
-
+        // not-matching
         tests.put("/a/b/c/d", false);
         tests.put("/a/b/c/d/cat/e", false);  // cat only intermediate segment
         tests.put("/a/b/c/d/acat/e", false);  // cat only intermediate segment
@@ -181,17 +257,17 @@ public class GlobPatternTest extends JUn
         tests.put("/a/b/cat/ed/f/f", false); // ... nor do siblings' children
         tests.put("/a/b/ced/cat", false);    // ... nor do siblings' children
 
-        for (String toTest : tests.keySet()) {
-            log.info(gp + " - " + toTest + " : " + tests.get(toTest));
-            assertTrue(gp + " : " + toTest, tests.get(toTest) == gp.matches(toTest));
+        for (String testPath : tests.keySet()) {
+            assertMatch(gp, testPath, tests.get(testPath));
         }
 
         //  restriction /*/cat  matches all non-direct descendants of /foo named "cat"
         gp = GlobPattern.create("/a/b/c", "/*/cat");
         tests = new HashMap<String,Boolean>();
+        // matching
         tests.put("/a/b/c/a/cat", true);
         tests.put("/a/b/c/d/e/f/cat", true);
-
+        // not-matching
         tests.put("/a/b/c/cat", false);
         tests.put("/a/b/c/cate", false);
         tests.put("/a/b/c/acat", false);
@@ -206,21 +282,20 @@ public class GlobPatternTest extends JUn
         tests.put("/a/b/ced/cat", false);    // ... nor do siblings' children
         tests.put("/a/b/ced/f/cat", false);  // ... nor do siblings' children
         
-        for (String toTest : tests.keySet()) {
-            log.info(gp + " - " + toTest + " : " + tests.get(toTest));
-            assertTrue(gp + " : " + toTest, tests.get(toTest) == gp.matches(toTest));
+        for (String testPath : tests.keySet()) {
+            assertMatch(gp, testPath, tests.get(testPath));
         }
 
         //  restriction /cat* matches all descendant paths of /foo that have the
         //  direct foo-descendant segment starting with "cat"
         gp = GlobPattern.create("/a/b/c", "/cat*");
         tests = new HashMap<String,Boolean>();
+        // matching
         tests.put("/a/b/c/cat", true);
         tests.put("/a/b/c/cats", true);
         tests.put("/a/b/c/cat/s", true);
         tests.put("/a/b/c/cats/d/e/f", true);
-
-
+        // not-matching
         tests.put("/a/b/c/d/cat", false);
         tests.put("/a/b/c/d/cats", false);
         tests.put("/a/b/c/d/e/cat", false);
@@ -235,16 +310,30 @@ public class GlobPatternTest extends JUn
         tests.put("/a/b/ced/cat", false);    // ... nor do siblings' children
         tests.put("/a/b/ced/f/cat", false);  // ... nor do siblings' children
 
-        for (String toTest : tests.keySet()) {
-            log.info(gp + " - " + toTest + " : " + tests.get(toTest));
-            assertTrue(gp + " : " + toTest, tests.get(toTest) == gp.matches(toTest));
+        for (String testPath : tests.keySet()) {
+            assertMatch(gp, testPath, tests.get(testPath));
         }
     }
 
     public void testEmptyRestriction() {
-        GlobPattern gp = GlobPattern.create("/a/b/c", "");
-
+        GlobPattern gp = GlobPattern.create("/", "");
         Map<String,Boolean> tests = new HashMap<String,Boolean>();
+        tests.put("/", true);
+
+        tests.put("/a/b/c/d", false);
+        tests.put("/a/b/c/d/e", false);
+        tests.put("/a/b/c/d/e/f", false);
+        tests.put("/a/b/c", false);
+        tests.put("/a", false);
+        tests.put("/a/b/cde", false);
+
+        for (String toTest : tests.keySet()) {
+            assertTrue(gp + " : " + toTest, tests.get(toTest) == gp.matches(toTest));
+        }
+
+        gp = GlobPattern.create("/a/b/c", "");
+
+        tests = new HashMap<String,Boolean>();
         tests.put("/a/b/c", true);
 
         tests.put("/a/b/c/d", false);
@@ -255,7 +344,6 @@ public class GlobPatternTest extends JUn
         tests.put("/a/b/cde", false);
 
         for (String toTest : tests.keySet()) {
-            log.info(gp + " - " + toTest + " : " + tests.get(toTest));
             assertTrue(gp + " : " + toTest, tests.get(toTest) == gp.matches(toTest));
         }
     }
@@ -263,4 +351,4 @@ public class GlobPatternTest extends JUn
     public void testMatchesItem() {
        // TODO
     }
-}
\ No newline at end of file
+}



Mime
View raw message