This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git

commit c5eb647411efe6d2103d5905e7e94f47f2b56f9c
Author: Bertrand Delacretaz <bdelacre...@apache.org>
AuthorDate: Mon Jan 16 10:44:56 2017 +0000

    SLING-6423 - support ACLOptions in repoinit parser - contributed by Nitin 
Nizhawan, thanks!
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1779004 
13f79535-47bb-0310-9956-ffa450edef68
---
 .../repoinit/parser/operations/AclGroupBase.java   | 16 ++++++++++
 .../repoinit/parser/operations/SetAclPaths.java    |  7 ++++-
 .../parser/operations/SetAclPrincipals.java        |  9 ++++--
 src/main/javacc/RepoInitGrammar.jjt                | 34 +++++++++++++++++++---
 .../parser/test/OperationToStringVisitor.java      | 13 +++++++++
 src/test/resources/testcases/test-12-output.txt    | 10 +++++++
 src/test/resources/testcases/test-12.txt           | 17 +++++++++++
 src/test/resources/testcases/test-31-output.txt    |  6 ++++
 src/test/resources/testcases/test-31.txt           | 11 +++++++
 9 files changed, 116 insertions(+), 7 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/repoinit/parser/operations/AclGroupBase.java 
b/src/main/java/org/apache/sling/repoinit/parser/operations/AclGroupBase.java
index 3e67eae..1cc7f97 100644
--- 
a/src/main/java/org/apache/sling/repoinit/parser/operations/AclGroupBase.java
+++ 
b/src/main/java/org/apache/sling/repoinit/parser/operations/AclGroupBase.java
@@ -17,16 +17,28 @@
 
 package org.apache.sling.repoinit.parser.operations;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
 /** Base class for operations that group AclLines */
  abstract class AclGroupBase extends Operation {
+    /**
+     * Supported ACL options
+     */
+    public static final String ACL_OPTION_MERGE = "merge";
+    public static final String ACL_OPTION_MERGE_PRESERVE = "mergePreserve";
+
     private final List<AclLine> lines;
+    private final List<String> aclOptions;
     
     protected AclGroupBase(List<AclLine> lines) {
+        this(lines,new ArrayList<String>());
+    }
+    protected AclGroupBase(List<AclLine> lines, List<String> aclOptions) {
         this.lines = Collections.unmodifiableList(lines);
+        this.aclOptions = Collections.unmodifiableList(aclOptions);
     }
     
     protected String getParametersDescription() {
@@ -40,4 +52,8 @@ import java.util.List;
     public Collection<AclLine> getLines() {
         return lines;
     }
+
+    public List<String> getOptions() {
+        return aclOptions;
+    }
 }
diff --git 
a/src/main/java/org/apache/sling/repoinit/parser/operations/SetAclPaths.java 
b/src/main/java/org/apache/sling/repoinit/parser/operations/SetAclPaths.java
index b2673dc..9cb236f 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/SetAclPaths.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/SetAclPaths.java
@@ -17,6 +17,7 @@
 
 package org.apache.sling.repoinit.parser.operations;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -28,7 +29,11 @@ public class SetAclPaths extends AclGroupBase {
     private final List<String> paths;
     
     public SetAclPaths(List<String> paths, List<AclLine> lines) {
-        super(lines);
+        this(paths,lines,new ArrayList<String>());
+    }
+
+    public SetAclPaths(List<String> paths,List<AclLine> lines, List<String> 
aclOptions){
+        super(lines,aclOptions);
         this.paths = Collections.unmodifiableList(paths);
     }
     
diff --git 
a/src/main/java/org/apache/sling/repoinit/parser/operations/SetAclPrincipals.java
 
b/src/main/java/org/apache/sling/repoinit/parser/operations/SetAclPrincipals.java
index b3bb548..0281bc9 100644
--- 
a/src/main/java/org/apache/sling/repoinit/parser/operations/SetAclPrincipals.java
+++ 
b/src/main/java/org/apache/sling/repoinit/parser/operations/SetAclPrincipals.java
@@ -17,6 +17,7 @@
 
 package org.apache.sling.repoinit.parser.operations;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -28,10 +29,14 @@ public class SetAclPrincipals extends AclGroupBase {
     private final List<String> principals;
     
     public SetAclPrincipals(List<String> principals, List<AclLine> lines) {
-        super(lines);
+        this(principals,lines,new ArrayList<String>());
+    }
+
+    public SetAclPrincipals(List<String> principals,List<AclLine> lines, 
List<String> aclOptions) {
+        super(lines,aclOptions);
         this.principals = Collections.unmodifiableList(principals);
     }
-    
+
     protected String getParametersDescription() {
         final StringBuilder sb = new StringBuilder();
         sb.append(principals);
diff --git a/src/main/javacc/RepoInitGrammar.jjt 
b/src/main/javacc/RepoInitGrammar.jjt
index eae990c..4dc521f 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -78,7 +78,9 @@ TOKEN:
 |   < RCURLY: "}" >
 |   < COMMA: "," >
 |   < STAR: "*" >
+|   < EQUALS: "=" >
 |   < RESTRICTION: "restriction" >
+|   < ACL_OPTIONS: "ACLOptions" >
 
 /* The order of these fuzzy statements is important (first match wins?) */ 
 |   < NAMESPACED_ITEM: (["a"-"z"] | ["A"-"Z"])+ ":" (["a"-"z"] | ["A"-"Z"])+ >
@@ -211,15 +213,16 @@ void setAclPaths(List<Operation> result) :
 {
     List<String> paths;
     List<AclLine> lines = new ArrayList<AclLine>();
+    List<String> aclOptions;
 } 
 {
-    <SET> <ACL> <ON> paths  = pathsList() <EOL>
+    <SET> <ACL> <ON> paths  = pathsList() aclOptions=aclOptions() <EOL>
     ( removeStarLine(lines) | userPrivilegesLine(lines) | blankLine() ) +
     <END> 
     ( <EOL> | <EOF> )
     
     {
-        result.add(new SetAclPaths(paths, lines));
+        result.add(new SetAclPaths(paths, lines, aclOptions));
     }
 }
 
@@ -351,20 +354,43 @@ void pathPrivilegesLine(List<AclLine> lines) :
         lines.add(line); 
     }
 }
+void aclOption(List<String> options) :
+{
+   Token t;
+}
+{
+    (t=<NAMESPACED_ITEM> | t=<STRING>)
+    {
+        options.add(t.image);
+    }
+}
+List<String> aclOptions() :
+{
+    List<String> aclOptionList = new ArrayList<String>();
+    Token t;
+}
+{
+    ( <LPAREN> <ACL_OPTIONS> <EQUALS> aclOption(aclOptionList) ( <COMMA> 
aclOption(aclOptionList) )*  <RPAREN> )?
+
+    {
+       return aclOptionList;
+    }
+}
 
 void setAclPrincipals(List<Operation> result) :
 {
     List <String> principals;
     List<AclLine> lines = new ArrayList<AclLine>();
+    List<String> aclOptions;
 }
 {
-    <SET> <ACL> <FOR> principals = principalsList() <EOL>
+    <SET> <ACL> <FOR> principals = principalsList() aclOptions=aclOptions() 
<EOL>
     ( removeStarLine(lines) | pathPrivilegesLine(lines) | blankLine() ) +
     <END> 
     ( <EOL> | <EOF> )
     
     {
-        result.add(new SetAclPrincipals(principals, lines));
+        result.add(new SetAclPrincipals(principals, lines, aclOptions));
     }
 }
 
diff --git 
a/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
 
b/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
index 9ac4601..d8d0c47 100644
--- 
a/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
+++ 
b/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
@@ -19,6 +19,7 @@ package org.apache.sling.repoinit.parser.test;
 
 import java.io.PrintWriter;
 import java.util.Collection;
+import java.util.List;
 
 import org.apache.sling.repoinit.parser.operations.AclLine;
 import org.apache.sling.repoinit.parser.operations.CreatePath;
@@ -79,6 +80,9 @@ class OperationToStringVisitor implements OperationVisitor {
             out.print(p);
             out.print(' ');
         }
+
+        dumpAclOptions(s.getOptions());
+
         out.println();
         dumpAclLines(s.getLines());
     }
@@ -91,6 +95,9 @@ class OperationToStringVisitor implements OperationVisitor {
             out.print(p);
             out.print(' ');
         }
+
+        dumpAclOptions(s.getOptions());
+
         out.println();
         dumpAclLines(s.getLines());
     }
@@ -116,4 +123,10 @@ class OperationToStringVisitor implements OperationVisitor 
{
             out.println(line);
         }
     }
+
+    private void dumpAclOptions(List<String> options){
+        if(options != null && options.size() > 0){
+            out.print("ACLOptions="+options);
+        }
+    }
 }
diff --git a/src/test/resources/testcases/test-12-output.txt 
b/src/test/resources/testcases/test-12-output.txt
new file mode 100644
index 0000000..2efd9a5
--- /dev/null
+++ b/src/test/resources/testcases/test-12-output.txt
@@ -0,0 +1,10 @@
+SetAclPaths on /libs /apps ACLOptions=[merge]
+  AclLine REMOVE_ALL {principals=[user1, user2]}
+  AclLine ALLOW {principals=[user1, user2], privileges=[jcr:read]}
+  AclLine REMOVE_ALL {principals=[another]}
+  AclLine ALLOW {principals=[another], privileges=[x:y]}
+SetAclPaths on /libs /apps ACLOptions=[mergePreserve, someOtherOption, 
someOther123, namespaced:option]
+  AclLine REMOVE_ALL {principals=[user1, user2]}
+  AclLine ALLOW {principals=[user1, user2], privileges=[jcr:read]}
+  AclLine REMOVE_ALL {principals=[another]}
+  AclLine ALLOW {principals=[another], privileges=[x:y]}
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-12.txt 
b/src/test/resources/testcases/test-12.txt
new file mode 100644
index 0000000..1d13158
--- /dev/null
+++ b/src/test/resources/testcases/test-12.txt
@@ -0,0 +1,17 @@
+# Test Path centring Set Acl with options SLING-6423
+set ACL on /libs,/apps (ACLOptions=merge)
+    remove * for user1,user2
+    allow jcr:read for user1,user2
+
+    remove * for another
+    allow x:y for another
+end
+
+#multiple options test
+set ACL on /libs,/apps 
(ACLOptions=mergePreserve,someOtherOption,someOther123,namespaced:option)
+    remove * for user1,user2
+    allow jcr:read for user1,user2
+
+    remove * for another
+    allow x:y for another
+end
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-31-output.txt 
b/src/test/resources/testcases/test-31-output.txt
new file mode 100644
index 0000000..5daeb54
--- /dev/null
+++ b/src/test/resources/testcases/test-31-output.txt
@@ -0,0 +1,6 @@
+SetAclPrincipals for user1 u2 ACLOptions=[mergePreserve]
+  AclLine REMOVE_ALL {paths=[/libs, /apps]}
+  AclLine ALLOW {paths=[/content], privileges=[jcr:read]}
+SetAclPrincipals for user1 u2 ACLOptions=[mergePreserve, someOtherOption, 
someOther123, namespaced:option]
+  AclLine REMOVE_ALL {paths=[/libs, /apps]}
+  AclLine ALLOW {paths=[/content], privileges=[jcr:read]}
diff --git a/src/test/resources/testcases/test-31.txt 
b/src/test/resources/testcases/test-31.txt
new file mode 100644
index 0000000..5e6539b
--- /dev/null
+++ b/src/test/resources/testcases/test-31.txt
@@ -0,0 +1,11 @@
+# Test the principal-centered ACL syntax with options SLING-6423
+
+set ACL for user1,u2 (ACLOptions=mergePreserve)
+    remove * on /libs,/apps
+    allow jcr:read on /content
+end
+# with multiple options
+set ACL for user1,u2 
(ACLOptions=mergePreserve,someOtherOption,someOther123,namespaced:option)
+    remove * on /libs,/apps
+    allow jcr:read on /content
+end
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Reply via email to