You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2021/05/05 12:52:52 UTC

[sling-org-apache-sling-repoinit-parser] branch SLING-10299 created (now 859cd43)

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

angela pushed a change to branch SLING-10299
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git.


      at 859cd43  SLING-10299 : Allow for removal of access control policies (not just individual entries)

This branch includes the following new commits:

     new 859cd43  SLING-10299 : Allow for removal of access control policies (not just individual entries)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-org-apache-sling-repoinit-parser] 01/01: SLING-10299 : Allow for removal of access control policies (not just individual entries)

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 859cd4386eb11f30422d223e122a144027d64243
Author: angela <an...@adobe.com>
AuthorDate: Wed May 5 14:52:36 2021 +0200

    SLING-10299 : Allow for removal of access control policies (not just individual entries)
---
 .../parser/operations/OperationVisitor.java        |  4 ++
 .../{package-info.java => RemoveAclPaths.java}     | 43 ++++++++++++++++---
 .../parser/operations/RemoveAclPrincipalBased.java | 50 ++++++++++++++++++++++
 ...{package-info.java => RemoveAclPrincipals.java} | 43 ++++++++++++++++---
 .../repoinit/parser/operations/package-info.java   |  2 +-
 src/main/javacc/RepoInitGrammar.jjt                | 39 +++++++++++++++++
 .../parser/test/OperationToStringVisitor.java      | 37 ++++++++++++++++
 src/test/resources/testcases/test-70-output.txt    |  7 +++
 src/test/resources/testcases/test-70.txt           | 13 ++++++
 src/test/resources/testcases/test-99-output.txt    |  9 +++-
 src/test/resources/testcases/test-99.txt           |  9 ++++
 11 files changed, 240 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java b/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
index 7eb2006..9bd3775 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
@@ -38,4 +38,8 @@ public interface OperationVisitor {
     void visitAddGroupMembers(AddGroupMembers am);
     void visitRemoveGroupMembers(RemoveGroupMembers rm);
     void visitSetProperties(SetProperties sp);
+    default void visitRemoveAclPrincipals(RemoveAclPrincipals s) { throw new UnsupportedOperationException(); }
+    default void visitRemoveAclPaths(RemoveAclPaths s) { throw new UnsupportedOperationException(); }
+    default void visitRemoveAclPrincipalBased(RemoveAclPrincipalBased s) { throw new UnsupportedOperationException(); }
+
 }
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java b/src/main/java/org/apache/sling/repoinit/parser/operations/RemoveAclPaths.java
similarity index 52%
copy from src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
copy to src/main/java/org/apache/sling/repoinit/parser/operations/RemoveAclPaths.java
index 14e9006..ef97188 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/RemoveAclPaths.java
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -6,17 +6,46 @@
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- ******************************************************************************/
-
- // DO NOT use version 5.x here, once a major change is
- // needed skip directly to 6.x (SLING-10139)
-@org.osgi.annotation.versioning.Version("4.7.0")
+ */
 package org.apache.sling.repoinit.parser.operations;
 
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+public class RemoveAclPaths extends Operation {
+
+    private final List<String> paths;
+    
+    public RemoveAclPaths(@NotNull List<String> paths) {
+        this.paths = paths;
+    }
+
+    @Override
+    public void accept(OperationVisitor v) {
+        v.visitRemoveAclPaths(this);
+    }
+
+    @Override
+    protected String getParametersDescription() {
+        return paths.toString();
+    }
+
+    @Override
+    public @NotNull String asRepoInitString() {
+        return String.format("remove ACL on %s%n", pathsToString(paths));
+    }
+
+    @NotNull
+    public List<String> getPaths() {
+        return paths;
+    }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/RemoveAclPrincipalBased.java b/src/main/java/org/apache/sling/repoinit/parser/operations/RemoveAclPrincipalBased.java
new file mode 100644
index 0000000..c16811a
--- /dev/null
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/RemoveAclPrincipalBased.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.repoinit.parser.operations;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+public class RemoveAclPrincipalBased extends Operation {
+
+    private final List<String> principals;
+
+    public RemoveAclPrincipalBased(@NotNull List<String> principals) {
+        this.principals = principals;
+    }
+
+    @Override
+    public void accept(OperationVisitor v) {
+        v.visitRemoveAclPrincipalBased(this);
+    }
+
+    @Override
+    protected String getParametersDescription() {
+        return principals.toString();
+    }
+
+    @Override
+    public @NotNull String asRepoInitString() {
+        return String.format("remove principal ACL for %s%n", listToString(principals));
+    }
+
+    @NotNull
+    public List<String> getPrincipals() {
+        return principals;
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java b/src/main/java/org/apache/sling/repoinit/parser/operations/RemoveAclPrincipals.java
similarity index 50%
copy from src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
copy to src/main/java/org/apache/sling/repoinit/parser/operations/RemoveAclPrincipals.java
index 14e9006..815fbab 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/RemoveAclPrincipals.java
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -6,17 +6,46 @@
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- ******************************************************************************/
-
- // DO NOT use version 5.x here, once a major change is
- // needed skip directly to 6.x (SLING-10139)
-@org.osgi.annotation.versioning.Version("4.7.0")
+ */
 package org.apache.sling.repoinit.parser.operations;
 
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+public class RemoveAclPrincipals extends Operation {
+    
+    private final List<String> principals;
+    
+    public RemoveAclPrincipals(@NotNull List<String> principals) {
+        this.principals = principals;
+    }
+
+    @Override
+    public void accept(OperationVisitor v) {
+        v.visitRemoveAclPrincipals(this);
+    }
+
+    @Override
+    protected String getParametersDescription() {
+        return principals.toString();
+    }
+
+    @Override
+    public @NotNull String asRepoInitString() {
+        return String.format("remove ACL for %s%n", listToString(principals));
+    }
+
+    @NotNull
+    public List<String> getPrincipals() {
+        return principals;
+    }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java b/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
index 14e9006..737bebc 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/package-info.java
@@ -17,6 +17,6 @@
 
  // DO NOT use version 5.x here, once a major change is
  // needed skip directly to 6.x (SLING-10139)
-@org.osgi.annotation.versioning.Version("4.7.0")
+@org.osgi.annotation.versioning.Version("4.8.0")
 package org.apache.sling.repoinit.parser.operations;
 
diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index f255b47..960d45e 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -143,6 +143,9 @@ List<Operation> parse() :
         | setAclPrincipals(result)
         | setAclPrincipalBased(result)
         | setAclRepository(result)
+        | removeAclPaths(result) 
+        | removeAclPrincipals(result)
+        | removeAclPrincipalBased(result)
         | createPathStatement(result)
         | registerNamespaceStatement(result)
         | registerNodetypesStatement(result)
@@ -541,6 +544,42 @@ void setAclPrincipalBased(List<Operation> result) :
     }
 }
 
+void removeAclPaths(List<Operation> result) :
+{
+    List<String> paths;
+} 
+{
+    <REMOVE> <ACL> <ON> paths  = pathsList()
+    ( <EOL> | <EOF> )  
+    {
+        result.add(new RemoveAclPaths(paths));
+    }
+}
+
+void removeAclPrincipals(List<Operation> result) :
+{
+    List <String> principals;
+}
+{
+    <REMOVE> <ACL> <FOR> principals = principalsList()
+    ( <EOL> | <EOF> )
+    {
+        result.add(new RemoveAclPrincipals(principals));
+    }
+}
+
+void removeAclPrincipalBased(List<Operation> result) :
+{
+    List <String> principals;
+}
+{
+    <REMOVE> <PRINCIPAL> <ACL> <FOR> principals = principalsList()
+    ( <EOL> | <EOF> )
+    {
+        result.add(new RemoveAclPrincipalBased(principals));
+    }
+}
+
 void registerNamespaceStatement(List<Operation> result) :
 {
     Token prefix = null;
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 88c9e62..711c9c9 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
@@ -34,6 +34,9 @@ import org.apache.sling.repoinit.parser.operations.RegisterNodetypes;
 import org.apache.sling.repoinit.parser.operations.OperationVisitor;
 import org.apache.sling.repoinit.parser.operations.RegisterNamespace;
 import org.apache.sling.repoinit.parser.operations.RegisterPrivilege;
+import org.apache.sling.repoinit.parser.operations.RemoveAclPaths;
+import org.apache.sling.repoinit.parser.operations.RemoveAclPrincipalBased;
+import org.apache.sling.repoinit.parser.operations.RemoveAclPrincipals;
 import org.apache.sling.repoinit.parser.operations.SetAclPaths;
 import org.apache.sling.repoinit.parser.operations.SetAclPrincipalBased;
 import org.apache.sling.repoinit.parser.operations.SetAclPrincipals;
@@ -127,6 +130,40 @@ class OperationToStringVisitor implements OperationVisitor {
     }
 
     @Override
+    public void visitRemoveAclPrincipals(RemoveAclPrincipals s) {
+        out.print(s.getClass().getSimpleName());
+        out.print(" for");
+        for (String p : s.getPrincipals()) {
+            out.print(' ');
+            out.print(p);
+        }
+        out.println();
+    }
+
+    @Override
+    public void visitRemoveAclPaths(RemoveAclPaths s) {
+        out.print(s.getClass().getSimpleName());
+        out.print(" on");
+        for (String p : s.getPaths()) {
+            out.print(' ');
+            out.print(p);
+        }
+        out.println();
+
+    }
+
+    @Override
+    public void visitRemoveAclPrincipalBased(RemoveAclPrincipalBased s) {
+        out.print(s.getClass().getSimpleName());
+        out.print(" for");
+        for (String p : s.getPrincipals()) {
+            out.print(' ');
+            out.print(p);
+        }
+        out.println();
+    }
+
+    @Override
     public void visitCreatePath(CreatePath cp) {
         out.println(cp.toString());
     }
diff --git a/src/test/resources/testcases/test-70-output.txt b/src/test/resources/testcases/test-70-output.txt
new file mode 100644
index 0000000..81feb97
--- /dev/null
+++ b/src/test/resources/testcases/test-70-output.txt
@@ -0,0 +1,7 @@
+RemoveAclPrincipals for ana
+RemoveAclPrincipals for alice aida
+RemoveAclPaths on :repository :home:anni# :functionNamesAreFree:aendu#
+RemoveAclPaths on / /var /etc
+RemoveAclPaths on /content
+RemoveAclPrincipalBased for ada amy
+RemoveAclPrincipalBased for adi
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-70.txt b/src/test/resources/testcases/test-70.txt
new file mode 100644
index 0000000..ba886f5
--- /dev/null
+++ b/src/test/resources/testcases/test-70.txt
@@ -0,0 +1,13 @@
+remove ACL for ana
+
+remove ACL for alice, aida
+
+remove ACL on :repository, home(anni), functionNamesAreFree(aendu)
+
+remove ACL on /, /var, /etc
+
+remove ACL on /content
+
+remove principal ACL for ada, amy
+
+remove principal ACL for adi
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-99-output.txt b/src/test/resources/testcases/test-99-output.txt
index 3d5039c..ca475c8 100644
--- a/src/test/resources/testcases/test-99-output.txt
+++ b/src/test/resources/testcases/test-99-output.txt
@@ -75,4 +75,11 @@ SetProperties on :authorizable:bob# :authorizable:grpB#/nested
   PropertyLine default someInteger{Long}=[{Long}42]
   PropertyLine someFlag{Boolean}=[{Boolean}true]
   PropertyLine default someDate{Date}=[{GregorianCalendar}2020-03-19T11:39:33.437+05:30]
-  PropertyLine quotedMix{String}=[{String}quoted, {String}non-quoted, {String}the last " one]
\ No newline at end of file
+  PropertyLine quotedMix{String}=[{String}quoted, {String}non-quoted, {String}the last " one]
+RemoveAclPrincipals for ana
+RemoveAclPrincipals for alice aida
+RemoveAclPaths on :repository :home:anni# :functionNamesAreFree:aendu#
+RemoveAclPaths on / /var /etc
+RemoveAclPaths on /content
+RemoveAclPrincipalBased for ada amy
+RemoveAclPrincipalBased for adi  
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-99.txt b/src/test/resources/testcases/test-99.txt
index 427c414..f97ac95 100644
--- a/src/test/resources/testcases/test-99.txt
+++ b/src/test/resources/testcases/test-99.txt
@@ -135,3 +135,12 @@ set properties on authorizable(bob), authorizable(grpB)/nested
   default someDate{Date} to "2020-03-19T11:39:33.437+05:30"
   set quotedMix to "quoted", non-quoted, "the last \" one"
 end
+
+# Remove AC policies entirely (not just individual entries)
+remove ACL for ana
+remove ACL for alice, aida
+remove ACL on :repository, home(anni), functionNamesAreFree(aendu)
+remove ACL on /, /var, /etc
+remove ACL on /content
+remove principal ACL for ada, amy
+remove principal ACL for adi
\ No newline at end of file