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 2017/12/22 10:46:32 UTC
[sling-org-apache-sling-repoinit-parser] branch master updated:
SLING-7226 - support optional 'with path' statement for user and service
user creation
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git
The following commit(s) were added to refs/heads/master by this push:
new 02c0d96 SLING-7226 - support optional 'with path' statement for user and service user creation
02c0d96 is described below
commit 02c0d968fdac73240821873d930fabd190c1c9a8
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Dec 22 11:46:23 2017 +0100
SLING-7226 - support optional 'with path' statement for user and service user creation
---
.../parser/operations/CreateServiceUser.java | 21 ++++++++++++++++++++-
.../repoinit/parser/operations/CreateUser.java | 11 ++++++++++-
.../repoinit/parser/operations/package-info.java | 2 +-
src/main/javacc/RepoInitGrammar.jjt | 20 +++++++++++++++++---
.../repoinit/parser/test/ParsingErrorsTest.java | 2 ++
src/test/resources/testcases/test-1-output.txt | 1 +
src/test/resources/testcases/test-1.txt | 3 ++-
src/test/resources/testcases/test-60-output.txt | 4 +++-
src/test/resources/testcases/test-60.txt | 5 ++++-
src/test/resources/testcases/test-99-output.txt | 3 +++
src/test/resources/testcases/test-99.txt | 3 +++
11 files changed, 66 insertions(+), 9 deletions(-)
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/CreateServiceUser.java b/src/main/java/org/apache/sling/repoinit/parser/operations/CreateServiceUser.java
index ef10180..c1e4e11 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/CreateServiceUser.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/CreateServiceUser.java
@@ -18,12 +18,31 @@
package org.apache.sling.repoinit.parser.operations;
public class CreateServiceUser extends ServiceUserOperation {
- public CreateServiceUser(String username) {
+ private final String path;
+
+ public CreateServiceUser(String username, String path) {
super(username);
+ this.path = path;
}
@Override
public void accept(OperationVisitor v) {
v.visitCreateServiceUser(this);
}
+
+ @Override
+ protected String getParametersDescription() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append(super.getParametersDescription());
+
+ if(path != null) {
+ sb.append(" with path ").append(path);
+ }
+
+ return sb.toString();
+ }
+
+ public String getPath() {
+ return path;
+ }
}
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
index f9190e6..c27039a 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/CreateUser.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/CreateUser.java
@@ -21,16 +21,18 @@ public class CreateUser extends Operation {
private final String username;
private final String passwordEncoding;
private final String password;
+ private final String path;
/** 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) {
+ public CreateUser(String username, String passwordEncoding, String password, String path) {
this.username = username;
this.passwordEncoding = passwordEncoding;
this.password = password;
+ this.path = path;
}
@Override
@@ -41,6 +43,9 @@ public class CreateUser extends Operation {
@Override
protected String getParametersDescription() {
final StringBuilder sb = new StringBuilder(username);
+ if(path != null) {
+ sb.append(" with path ").append(path);
+ }
if(password != null) {
if(passwordEncoding == null) {
sb.append(" (with password)");
@@ -62,4 +67,8 @@ public class CreateUser extends Operation {
public String getPasswordEncoding() {
return passwordEncoding;
}
+
+ public String getPath() {
+ return path;
+ }
}
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 bf39090..1db1f72 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
@@ -15,6 +15,6 @@
* limitations under the License.
******************************************************************************/
-@org.osgi.annotation.versioning.Version("4.0.0")
+@org.osgi.annotation.versioning.Version("5.0.0")
package org.apache.sling.repoinit.parser.operations;
diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index e406be2..82da4b8 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -159,21 +159,32 @@ List<String> principalsList() :
{ return principals; }
}
+String withPathStatement() :
+{
+ Token t = null;
+}
+{
+ <WITH> <PATH> t=<PATH_STRING>
+ { return t.image; }
+}
+
void serviceUserStatement(List<Operation> result) :
{
Token t;
List<String> principals;
+ String path = null;
}
{
(t=<CREATE> | t=<DELETE>)
<SERVICE> <USER>
principals = principalsList()
+ ( path = withPathStatement() ) ?
(<EOL> | <EOF>)
{
for(String principal : principals) {
if(CREATE == t.kind) {
- result.add(new CreateServiceUser(principal));
+ result.add(new CreateServiceUser(principal, path));
} else {
result.add(new DeleteServiceUser(principal));
}
@@ -496,16 +507,19 @@ void createUserStatement(List<Operation> result) :
Token user = null;
Token encoding = null;
Token password = null;
+ String path = null;
}
{
<CREATE> <USER>
( user = <STRING> )
+ ( path = withPathStatement() ) ?
( <WITH> <PASSWORD> ( <LCURLY> encoding = <STRING> <RCURLY> )? password = <STRING> )?
-
+
{
result.add(new CreateUser(user.image,
(encoding == null ? null : encoding.image),
- (password == null ? null : password.image)
+ (password == null ? null : password.image),
+ path
));
}
}
diff --git a/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java b/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java
index 91fe551..36b6c36 100644
--- a/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java
+++ b/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java
@@ -82,6 +82,8 @@ public class ParsingErrorsTest {
// SLING-7061
add(new Object[] { "set repository ACL for principal1\nallow jcr:somePermission on /\nend", ParseException.class });
+ // path must come before password if used
+ add(new Object[] { "create user E with password PWD with path P", ParseException.class });
}};
return result;
}
diff --git a/src/test/resources/testcases/test-1-output.txt b/src/test/resources/testcases/test-1-output.txt
index d4fde81..2b66939 100644
--- a/src/test/resources/testcases/test-1-output.txt
+++ b/src/test/resources/testcases/test-1-output.txt
@@ -2,3 +2,4 @@ CreateServiceUser bob
CreateServiceUser alice
CreateServiceUser tom21
CreateServiceUser lonesome
+CreateServiceUser pathA with path /some/test/path
diff --git a/src/test/resources/testcases/test-1.txt b/src/test/resources/testcases/test-1.txt
index 1ad451a..89684f3 100644
--- a/src/test/resources/testcases/test-1.txt
+++ b/src/test/resources/testcases/test-1.txt
@@ -1,2 +1,3 @@
create service user bob,alice, tom21
-create service user lonesome
\ No newline at end of file
+create service user lonesome
+create service user pathA with path /some/test/path
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-60-output.txt b/src/test/resources/testcases/test-60-output.txt
index 1a70cdf..428cd59 100644
--- a/src/test/resources/testcases/test-60-output.txt
+++ b/src/test/resources/testcases/test-60-output.txt
@@ -3,4 +3,6 @@ CreateUser userB
CreateUser userC (with password), password=some_password
CreateUser userD (with encoded password), password=dc460da4ad72c, passwordEncoding=SHA-256
CreateUser userE (with encoded password), password=afdgwdsdf, passwordEncoding=someEncoding
-CreateUser one_with-more-chars.ok:/123456 (with encoded password), password=pw-with.ok-:/13456, passwordEncoding=encoding_with.ok-:/12345
\ No newline at end of file
+CreateUser one_with-more-chars.ok:/123456 (with encoded password), password=pw-with.ok-:/13456, passwordEncoding=encoding_with.ok-:/12345
+CreateUser userF with path /thePathF
+CreateUser userG with path /thePathG (with encoded password), password=userGpwd, passwordEncoding=theEncoding
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-60.txt b/src/test/resources/testcases/test-60.txt
index 9e9a8df..5ac827b 100644
--- a/src/test/resources/testcases/test-60.txt
+++ b/src/test/resources/testcases/test-60.txt
@@ -8,4 +8,7 @@ create user userD with password {SHA-256}dc460da4ad72c
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
+create user one_with-more-chars.ok:/123456 with password {encoding_with.ok-:/12345} pw-with.ok-:/13456
+
+create user userF with path /thePathF
+create user userG with path /thePathG with password {theEncoding} userGpwd
\ 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 1748434..ee17510 100644
--- a/src/test/resources/testcases/test-99-output.txt
+++ b/src/test/resources/testcases/test-99-output.txt
@@ -7,6 +7,7 @@ SetAclPaths on /libs /apps
AclLine DENY {principals=[user1], privileges=[jcr:lockManagement]}
AclLine REMOVE {principals=[u3], privileges=[jcr:understand, some:other]}
CreateServiceUser bob_the_service
+CreateServiceUser zoo_the_keeper with path /keeper/zoo
SetAclPaths on /tmp
AclLine ALLOW {principals=[bob_the_service], privileges=[some:otherPrivilege]}
CreatePath [content, example.com(sling:Folder)]
@@ -31,5 +32,7 @@ RegisterNodetypes:
- slingevent:properties (binary)
CreateUser userE (with encoded password), password=afdgwdsdf, passwordEncoding=someEncoding
CreateUser one_with-more-chars.ok:/123456 (with encoded password), password=pw-with.ok-:/13456, passwordEncoding=encoding_with.ok-:/12345
+CreateUser userF with path /for/userF
+CreateUser userG with path /for/userG (with password), password=ggg
CreateServiceUser the-last-one
DisableServiceUser svc1 : This is the message
diff --git a/src/test/resources/testcases/test-99.txt b/src/test/resources/testcases/test-99.txt
index 0f2b9ff..cd288c4 100644
--- a/src/test/resources/testcases/test-99.txt
+++ b/src/test/resources/testcases/test-99.txt
@@ -11,6 +11,7 @@ set ACL on /libs,/apps
end
create service user bob_the_service
+create service user zoo_the_keeper with path /keeper/zoo
# Verify that indent is not required
set ACL on /tmp
@@ -54,6 +55,8 @@ register nodetypes
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 user userF with path /for/userF
+create user userG with path /for/userG with password ggg
create service user the-last-one
disable service user svc1 : "This is the message"
--
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].