jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1128050 - in /jackrabbit/branches/2.2: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/GlobPattern.java jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/GlobPatternTest.java
Date Thu, 26 May 2011 19:24:30 GMT
Author: tripod
Date: Thu May 26 19:24:30 2011
New Revision: 1128050

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

Modified:
    jackrabbit/branches/2.2/   (props changed)
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/GlobPattern.java
    jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/GlobPatternTest.java

Propchange: jackrabbit/branches/2.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu May 26 19:24:30 2011
@@ -2,4 +2,4 @@
 /jackrabbit/sandbox/JCR-1456:774917-886178
 /jackrabbit/sandbox/JCR-2170:812417-816332
 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:1038201,1038203,1038205,1038657,1039064,1039347,1039408,1039422-1039423,1039888,1039946,1040033,1040090,1040459,1040601,1040606,1040661,1040958,1041379,1041439,1041761,1042643,1042647,1042978-1042982,1043084-1043086,1043088,1043343,1043357-1043358,1043430,1043554,1043616,1043618,1043637,1043656,1043893,1043897,1044239,1044312,1044451,1044613,1049473,1049491,1049514,1049518,1049520,1049859,1049870,1049874,1049878,1049880,1049883,1049889,1049891,1049894-1049895,1049899-1049901,1049909-1049911,1049915-1049916,1049919,1049923,1049925,1049931,1049936,1049939,1050212,1050298,1050346,1050551,1055068,1055070-1055071,1055116-1055117,1055127,1055134,1055164,1055498,1060431,1060434,1060753,1063756,1064670,1065599,1065622,1066059,1066071,1069831,1071562,1071573,1071680,1074140,1079314,1079317,1080186,1080540,1087304,1088991,1089032,1089053,1089436,1092106,1092117,1092683,1097513-1097514,1098963-1098964,1099033,1100286,1104027
+/jackrabbit/trunk:1038201,1038203,1038205,1038657,1039064,1039347,1039408,1039422-1039423,1039888,1039946,1040033,1040090,1040459,1040601,1040606,1040661,1040958,1041379,1041439,1041761,1042643,1042647,1042978-1042982,1043084-1043086,1043088,1043343,1043357-1043358,1043430,1043554,1043616,1043618,1043637,1043656,1043893,1043897,1044239,1044312,1044451,1044613,1049473,1049491,1049514,1049518,1049520,1049859,1049870,1049874,1049878,1049880,1049883,1049889,1049891,1049894-1049895,1049899-1049901,1049909-1049911,1049915-1049916,1049919,1049923,1049925,1049931,1049936,1049939,1050212,1050298,1050346,1050551,1055068,1055070-1055071,1055116-1055117,1055127,1055134,1055164,1055498,1060431,1060434,1060753,1063756,1064670,1065599,1065622,1066059,1066071,1069831,1071562,1071573,1071680,1074140,1079314,1079317,1080186,1080540,1087304,1088991,1089032,1089053,1089436,1092106,1092117,1092683,1097513-1097514,1098963-1098964,1099033,1099172,1100286,1104027

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/GlobPattern.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/GlobPattern.java?rev=1128050&r1=1128049&r2=1128050&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/GlobPattern.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/GlobPattern.java
Thu May 26 19:24:30 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/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/GlobPatternTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/GlobPatternTest.java?rev=1128050&r1=1128049&r2=1128050&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/GlobPatternTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/GlobPatternTest.java
Thu May 26 19:24:30 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