You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:58:30 UTC
[sling-org-apache-sling-repoinit-parser] 02/15: SLING-6219 -
reponit grammar support for create/delete user
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.repoinit.parser-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git
commit 4380dd94eabf0d9df21682c663844ec3ea03eb0e
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Nov 7 13:41:00 2016 +0000
SLING-6219 - reponit grammar support for create/delete user
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/repoinit/parser@1768509 13f79535-47bb-0310-9956-ffa450edef68
---
.../repoinit/parser/operations/CreateUser.java | 53 ++++++++++++++++++++++
.../{OperationVisitor.java => DeleteUser.java} | 27 +++++++----
.../parser/operations/OperationVisitor.java | 2 +
src/main/javacc/RepoInitGrammar.jjt | 38 ++++++++++++++++
.../parser/test/OperationToStringVisitor.java | 12 +++++
src/test/resources/testcases/test-60-output.txt | 6 +++
src/test/resources/testcases/test-60.txt | 11 +++++
src/test/resources/testcases/test-99-output.txt | 2 +
src/test/resources/testcases/test-99.txt | 2 +
9 files changed, 145 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/CreateUser.java b/src/main/java/org/apache/sling/repoinit/parser/operations/CreateUser.java
new file mode 100644
index 0000000..48e9316
--- /dev/null
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/CreateUser.java
@@ -0,0 +1,53 @@
+/*
+ * 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;
+
+public class CreateUser extends Operation {
+ private final String username;
+ private final String passwordEncoding;
+ private final String password;
+
+ /** Operation that creates a user.
+ * @param username the name of the user to create
+ * @param passwordEncoding optional encoding for the supplied password
+ * @param password optional password
+ */
+ public CreateUser(String username, String passwordEncoding, String password) {
+ this.username = username;
+ this.passwordEncoding = passwordEncoding;
+ this.password = password;
+ }
+
+ @Override
+ public void accept(OperationVisitor v) {
+ v.visitCreateUser(this);
+ }
+
+ @Override
+ protected String getParametersDescription() {
+ final StringBuilder sb = new StringBuilder(username);
+ if(password != null) {
+ if(passwordEncoding == null) {
+ sb.append(" (with password)");
+ } else {
+ sb.append(" (with encoded password)");
+ }
+ }
+ return sb.toString();
+ }
+}
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java b/src/main/java/org/apache/sling/repoinit/parser/operations/DeleteUser.java
similarity index 65%
copy from src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
copy to src/main/java/org/apache/sling/repoinit/parser/operations/DeleteUser.java
index 8693a99..a74bb8d 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/DeleteUser.java
@@ -17,12 +17,23 @@
package org.apache.sling.repoinit.parser.operations;
-public interface OperationVisitor {
- void visitCreateServiceUser(CreateServiceUser s);
- void visitDeleteServiceUser(DeleteServiceUser s);
- void visitSetAclPrincipal(SetAclPrincipals s);
- void visitSetAclPaths(SetAclPaths s);
- void visitCreatePath(CreatePath cp);
- void visitRegisterNamespace(RegisterNamespace rn);
- void visitRegisterNodetypes(RegisterNodetypes b);
+public class DeleteUser extends Operation {
+ private final String username;
+
+ /** Operation that deletes a user.
+ * @param username the name of the user to delete
+ */
+ public DeleteUser(String username) {
+ this.username = username;
+ }
+
+ @Override
+ public void accept(OperationVisitor v) {
+ v.visitDeleteUser(this);
+ }
+
+ @Override
+ protected String getParametersDescription() {
+ return username;
+ }
}
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 8693a99..e38c4f0 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
@@ -18,6 +18,8 @@
package org.apache.sling.repoinit.parser.operations;
public interface OperationVisitor {
+ void visitCreateUser(CreateUser u);
+ void visitDeleteUser(DeleteUser u);
void visitCreateServiceUser(CreateServiceUser s);
void visitDeleteServiceUser(DeleteServiceUser s);
void visitSetAclPrincipal(SetAclPrincipals s);
diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index 288b6d5..930c4a7 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -69,9 +69,13 @@ TOKEN:
| < NODETYPES: "nodetypes" >
| < REGISTER: "register" >
| < NAMESPACE: "namespace" >
+| < WITH: "with" >
+| < PASSWORD: "password" >
| < START_TEXTBLOCK: "<<===" > : TEXTBLOCK
| < LPAREN: "(" >
| < RPAREN: ")" >
+| < LCURLY: "{" >
+| < RCURLY: "}" >
| < COMMA: "," >
| < STAR: "*" >
@@ -105,6 +109,8 @@ List<Operation> parse() :
| createPathStatement(result)
| registerNamespaceStatement(result)
| registerNodetypesStatement(result)
+ | createUserStatement(result)
+ | deleteUserStatement(result)
| blankLine()
) *
<EOF>
@@ -333,4 +339,36 @@ void registerNodetypesStatement(List<Operation> result) :
{
result.add(new RegisterNodetypes(b.toString()));
}
+}
+
+void createUserStatement(List<Operation> result) :
+{
+ Token user = null;
+ Token encoding = null;
+ Token password = null;
+}
+{
+ <CREATE> <USER>
+ ( user = <STRING> )
+ ( <WITH> <PASSWORD> ( <LCURLY> encoding = <STRING> <RCURLY> )? password = <STRING> )?
+
+ {
+ result.add(new CreateUser(user.image,
+ (encoding == null ? null : encoding.image),
+ (password == null ? null : password.image)
+ ));
+ }
+}
+
+void deleteUserStatement(List<Operation> result) :
+{
+ Token user = null;
+}
+{
+ <DELETE> <USER>
+ ( user = <STRING> )
+
+ {
+ result.add(new DeleteUser(user.image));
+ }
}
\ No newline at end of file
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 ede1c58..0663e59 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
@@ -23,7 +23,9 @@ import java.util.Collection;
import org.apache.sling.repoinit.parser.operations.AclLine;
import org.apache.sling.repoinit.parser.operations.CreatePath;
import org.apache.sling.repoinit.parser.operations.CreateServiceUser;
+import org.apache.sling.repoinit.parser.operations.CreateUser;
import org.apache.sling.repoinit.parser.operations.DeleteServiceUser;
+import org.apache.sling.repoinit.parser.operations.DeleteUser;
import org.apache.sling.repoinit.parser.operations.RegisterNodetypes;
import org.apache.sling.repoinit.parser.operations.OperationVisitor;
import org.apache.sling.repoinit.parser.operations.RegisterNamespace;
@@ -52,6 +54,16 @@ class OperationToStringVisitor implements OperationVisitor {
}
@Override
+ public void visitCreateUser(CreateUser u) {
+ out.println(u.toString());
+ }
+
+ @Override
+ public void visitDeleteUser(DeleteUser u) {
+ out.println(u.toString());
+ }
+
+ @Override
public void visitSetAclPrincipal(SetAclPrincipals s) {
out.print(s.getClass().getSimpleName());
out.print(" for ");
diff --git a/src/test/resources/testcases/test-60-output.txt b/src/test/resources/testcases/test-60-output.txt
new file mode 100644
index 0000000..db94843
--- /dev/null
+++ b/src/test/resources/testcases/test-60-output.txt
@@ -0,0 +1,6 @@
+DeleteUser userB
+CreateUser userB
+CreateUser userC (with password)
+CreateUser userD (with encoded password)
+CreateUser userE (with encoded password)
+CreateUser one_with-more-chars.ok:/123456 (with encoded password)
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-60.txt b/src/test/resources/testcases/test-60.txt
new file mode 100644
index 0000000..e39f331
--- /dev/null
+++ b/src/test/resources/testcases/test-60.txt
@@ -0,0 +1,11 @@
+# Test create/delete user statements
+
+delete user userB
+create user userB
+
+create user userC with password some_password
+create user userD with password {SHA-256}dc460da4ad72c482231e28e688e01f2778a88ce31a08826899d54ef7183998b5
+
+create user userE with password {someEncoding} afdgwdsdf
+
+create user one_with-more-chars.ok:/123456 with password {encoding_with.ok-:/12345} pw-with.ok-:/13456
\ 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 0544b4a..b7927c7 100644
--- a/src/test/resources/testcases/test-99-output.txt
+++ b/src/test/resources/testcases/test-99-output.txt
@@ -23,4 +23,6 @@ RegisterNodetypes:
[slingevent:Event] > nt:unstructured, nt:hierarchyNode
- slingevent:topic (string)
- slingevent:properties (binary)
+CreateUser userE (with encoded password)
+CreateUser one_with-more-chars.ok:/123456 (with encoded password)
CreateServiceUser the-last-one
\ 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 c8b16a0..740c439 100644
--- a/src/test/resources/testcases/test-99.txt
+++ b/src/test/resources/testcases/test-99.txt
@@ -42,4 +42,6 @@ register nodetypes
- slingevent:properties (binary)
===>>
+create user userE with password {someEncoding} afdgwdsdf
+create user one_with-more-chars.ok:/123456 with password {encoding_with.ok-:/12345} pw-with.ok-:/13456
create service user the-last-one
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.