You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2015/12/15 14:56:48 UTC
svn commit: r1720162 - in /sling/trunk/contrib/extensions/acldef-parser/src:
main/java/org/apache/sling/acldef/parser/operations/ main/javacc/
test/resources/testcases/
Author: bdelacretaz
Date: Tue Dec 15 13:56:48 2015
New Revision: 1720162
URL: http://svn.apache.org/viewvc?rev=1720162&view=rev
Log:
SLING-5355 - parser is reasonably complete
Added:
sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/AclLine.java
sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/SetAcl.java
sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-10-output.txt
sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-10.txt
sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-20-output.txt
sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-20.txt
Modified:
sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/OperationVisitor.java
sling/trunk/contrib/extensions/acldef-parser/src/main/javacc/ACLDefinitions.jjt
Added: sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/AclLine.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/AclLine.java?rev=1720162&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/AclLine.java (added)
+++ sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/AclLine.java Tue Dec 15 13:56:48 2015
@@ -0,0 +1,56 @@
+/*
+ * 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.acldef.parser.operations;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+public class AclLine {
+
+ private final Action action;
+
+ public enum Action {
+ REMOVE,
+ REMOVE_ALL,
+ DENY,
+ ALLOW
+ };
+
+ private final List<String> privileges;
+ private final List<String> usernames;
+
+ public AclLine(Action a, List<String> privileges, List<String> usernames) {
+ action = a;
+ this.usernames = Collections.unmodifiableList(usernames);
+ this.privileges = privileges == null ? null : Collections.unmodifiableList(privileges);
+ }
+
+ public Action getAction() {
+ return action;
+ }
+
+ public Collection<String> getUsernames() {
+ return usernames;
+ }
+
+ @Override
+ public String toString() {
+ return action + " " + privileges + " for " + usernames;
+ }
+}
Modified: sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/OperationVisitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/OperationVisitor.java?rev=1720162&r1=1720161&r2=1720162&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/OperationVisitor.java (original)
+++ sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/OperationVisitor.java Tue Dec 15 13:56:48 2015
@@ -20,4 +20,5 @@ package org.apache.sling.acldef.parser.o
public interface OperationVisitor {
void visitCreateServiceUser(CreateServiceUser s);
void visitDeleteServiceUser(DeleteServiceUser s);
+ void visitSetAcl(SetAcl s);
}
Added: sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/SetAcl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/SetAcl.java?rev=1720162&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/SetAcl.java (added)
+++ sling/trunk/contrib/extensions/acldef-parser/src/main/java/org/apache/sling/acldef/parser/operations/SetAcl.java Tue Dec 15 13:56:48 2015
@@ -0,0 +1,47 @@
+/*
+ * 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.acldef.parser.operations;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+public class SetAcl extends Operation {
+ private final List<String> paths;
+ private final List<AclLine> lines;
+
+ public SetAcl(List<String> paths, List<AclLine> lines) {
+ this.paths = Collections.unmodifiableList(paths);
+ this.lines = Collections.unmodifiableList(lines);
+ }
+
+ public void accept(OperationVisitor v) {
+ v.visitSetAcl(this);
+ }
+
+ protected String getParametersDescription() {
+ return "on " + paths.toString() + " : " + lines.toString();
+ }
+
+ public Collection<String> getPaths() {
+ return paths;
+ }
+ public Collection<AclLine> getLines() {
+ return lines;
+ }
+}
Modified: sling/trunk/contrib/extensions/acldef-parser/src/main/javacc/ACLDefinitions.jjt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/acldef-parser/src/main/javacc/ACLDefinitions.jjt?rev=1720162&r1=1720161&r2=1720162&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/acldef-parser/src/main/javacc/ACLDefinitions.jjt (original)
+++ sling/trunk/contrib/extensions/acldef-parser/src/main/javacc/ACLDefinitions.jjt Tue Dec 15 13:56:48 2015
@@ -63,9 +63,13 @@ TOKEN:
| < CREATE: "create" >
| < DELETE: "delete" >
| < SERVICE: "service" >
+| < END: "end" >
| < USER: "user" >
| < USERNAME: (["a"-"z"] | ["A"-"Z"] | ["0"-"9"] | "_" | "-")+ >
| < COMMA: "," >
+| < STAR: "*" >
+| < PRIVILEGE_NAME: (["a"-"z"] | ["A"-"Z"])+ ":" (["a"-"z"] | ["A"-"Z"])+ >
+| < PATH: "/" (["a"-"z"] | ["A"-"Z"] | ["0"-"9"] | ["-"] | ["_"] | ["."]) + >
| < EOL: "\n" >
}
@@ -79,7 +83,7 @@ List<Operation> parse() :
result = new ArrayList<Operation>();
}
- ( blankLine() | serviceUserStatement() ) * <EOF>
+ ( serviceUserStatement() | setAclStatement() | blankLine() ) * <EOF>
{ return result; }
}
@@ -90,7 +94,7 @@ void blankLine() :
<EOL>
}
-List<String> usernameList() :
+List<String> usernamesList() :
{
Token t = null;
List<String> usernames = new ArrayList<String>();
@@ -108,7 +112,7 @@ void serviceUserStatement() :
List<String> usernames;
}
{
- (t=<CREATE> | t=<DELETE>) <SERVICE> <USER> usernames = usernameList() (<EOL> | <EOF>)
+ (t=<CREATE> | t=<DELETE>) <SERVICE> <USER> usernames = usernamesList() (<EOL> | <EOF>)
{
for(String username : usernames) {
if(CREATE == t.kind) {
@@ -118,4 +122,80 @@ void serviceUserStatement() :
}
}
}
+}
+
+List<String> privilegesList() :
+{
+ Token t = null;
+ List<String> priv = new ArrayList<String>();
+
+}
+{
+ t = <PRIVILEGE_NAME> { priv.add(t.image); }
+ ( <COMMA> t = <PRIVILEGE_NAME> { priv.add(t.image); } )*
+ { return priv; }
+}
+
+List<String> pathsList() :
+{
+ Token t = null;
+ List<String> paths = new ArrayList<String>();
+
+}
+{
+ t = <PATH> { paths.add(t.image); }
+ ( <COMMA> t = <PATH> { paths.add(t.image); } )*
+ { return paths; }
+}
+
+void setAclStatement() :
+{
+ List<String> paths;
+ List<AclLine> lines = new ArrayList<AclLine>();
+}
+{
+ <SET> <ACL> <ON> paths = pathsList() <EOL>
+ ( removeStarLine(lines) ) ?
+ ( privilegesOperationLine(lines) | blankLine() ) +
+ <END> ( <EOL> | <EOF> )
+
+ {
+ result.add(new SetAcl(paths, lines));
+ }
+}
+
+void removeStarLine(List<AclLine> lines) :
+{
+ List<String> usernames;
+}
+{
+ <REMOVE> <STAR> <FOR> usernames = usernamesList() <EOL>
+
+ {
+ lines.add(new AclLine(AclLine.Action.REMOVE_ALL, null, usernames));
+ }
+}
+
+void privilegesOperationLine(List<AclLine> lines) :
+{
+ Token t;
+ List<String> privileges;
+ List<String> usernames;
+}
+{
+ ( t = <REMOVE> | t = <ALLOW> | t = <DENY> ) privileges = privilegesList() <FOR> usernames = usernamesList() <EOL>
+
+ {
+ AclLine.Action a = AclLine.Action.REMOVE_ALL;
+ if(t.kind == REMOVE) {
+ a = AclLine.Action.REMOVE;
+ } else if(t.kind == ALLOW) {
+ a = AclLine.Action.ALLOW;
+ } else if(t.kind == DENY) {
+ a = AclLine.Action.DENY;
+ } else {
+ throw new IllegalStateException("Unexpected token kind " + t.kind);
+ }
+ lines.add(new AclLine(a, privileges, usernames));
+ }
}
\ No newline at end of file
Added: sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-10-output.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-10-output.txt?rev=1720162&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-10-output.txt (added)
+++ sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-10-output.txt Tue Dec 15 13:56:48 2015
@@ -0,0 +1 @@
+SetAcl on [/libs, /apps] : [REMOVE_ALL null for [user1, user2], ALLOW [jcr:read] for [user1, user2], DENY [jcr:write] for [user2], DENY [jcr:lockManagement] for [user1]]
\ No newline at end of file
Added: sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-10.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-10.txt?rev=1720162&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-10.txt (added)
+++ sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-10.txt Tue Dec 15 13:56:48 2015
@@ -0,0 +1,10 @@
+# Set ACL example from SLING-5355
+# Without the "with glob" option, we're not planning to support
+# that at this time.
+set ACL on /libs,/apps
+ remove * for user1,user2
+ allow jcr:read for user1,user2
+
+ deny jcr:write for user2
+ deny jcr:lockManagement for user1
+end
\ No newline at end of file
Added: sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-20-output.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-20-output.txt?rev=1720162&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-20-output.txt (added)
+++ sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-20-output.txt Tue Dec 15 13:56:48 2015
@@ -0,0 +1,6 @@
+CreateServiceUser user1
+CreateServiceUser u-ser_2
+SetAcl on [/libs, /apps] : [REMOVE_ALL null for [user1, u-ser_2], ALLOW [jcr:read] for [user1, u-ser_2], DENY [jcr:write] for [u-ser_2], DENY [jcr:lockManagement] for [user1]]
+CreateServiceUser bob_the_service
+SetAcl on [/tmp] : [ALLOW [some:otherPrivilege] for [bob_the_service]]
+CreateServiceUser the-last-one
\ No newline at end of file
Added: sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-20.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-20.txt?rev=1720162&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-20.txt (added)
+++ sling/trunk/contrib/extensions/acldef-parser/src/test/resources/testcases/test-20.txt Tue Dec 15 13:56:48 2015
@@ -0,0 +1,17 @@
+# Complete example with several intermixed statement types
+
+create service user user1, u-ser_2
+set ACL on /libs,/apps
+ remove * for user1,u-ser_2
+ allow jcr:read for user1,u-ser_2
+
+ deny jcr:write for u-ser_2
+ deny jcr:lockManagement for user1
+end
+
+create service user bob_the_service
+set ACL on /tmp
+ allow some:otherPrivilege for bob_the_service
+end
+
+create service user the-last-one
\ No newline at end of file