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 2021/04/27 15:08:52 UTC

[sling-org-apache-sling-repoinit-parser] branch master updated: SLING-10333 - add support for 'disable user'

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 d11efee  SLING-10333 - add support for 'disable user'
d11efee is described below

commit d11efee382dae72a1efde048003892a81862f570
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Apr 27 17:05:42 2021 +0200

    SLING-10333 - add support for 'disable user'
---
 bnd.bnd                                              |  2 +-
 .../parser/operations/DisableServiceUser.java        | 20 +++++++++++++++++++-
 src/main/javacc/RepoInitGrammar.jjt                  | 11 +++++++----
 .../repoinit/parser/test/DisableServiceUserTest.java | 11 +++++++++++
 .../repoinit/parser/test/ParsingErrorsTest.java      |  3 ++-
 src/test/resources/testcases/test-61-output.txt      | 10 +++++-----
 src/test/resources/testcases/test-69-output.txt      |  5 +++++
 src/test/resources/testcases/test-69.txt             |  6 ++++++
 src/test/resources/testcases/test-99-output.txt      |  3 ++-
 src/test/resources/testcases/test-99.txt             |  1 +
 10 files changed, 59 insertions(+), 13 deletions(-)

diff --git a/bnd.bnd b/bnd.bnd
index 47de961..71eddae 100644
--- a/bnd.bnd
+++ b/bnd.bnd
@@ -1,4 +1,4 @@
 -includeresource:\
   @jackrabbit-jcr-commons-*.jar!/org/apache/jackrabbit/util/ISO8601.*
 
-Provide-Capability: org.apache.sling.repoinit.language;version:Version="8.2"
+Provide-Capability: org.apache.sling.repoinit.language;version:Version="8.3"
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/DisableServiceUser.java b/src/main/java/org/apache/sling/repoinit/parser/operations/DisableServiceUser.java
index 433a041..0aedc58 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/DisableServiceUser.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/DisableServiceUser.java
@@ -21,8 +21,12 @@ import org.jetbrains.annotations.NotNull;
 import org.osgi.annotation.versioning.ProviderType;
 
 @ProviderType
+/** The class name is for historical reasons but this actually manages
+ *  both service and regular users.
+ */
 public class DisableServiceUser extends ServiceUserOperation {
     private final String reason;
+    private boolean isServiceUser;
     
     public DisableServiceUser(String username, String reason) {
         super(username, null);
@@ -32,10 +36,19 @@ public class DisableServiceUser extends ServiceUserOperation {
         }
     }
 
+    public void setServiceUser(boolean b) {
+        isServiceUser = b;
+    }
+
     @Override
     public String getParametersDescription() {
         final StringBuilder sb = new StringBuilder();
         sb.append(super.getParametersDescription());
+        if(isServiceUser) {
+            sb.append(" (service user)");
+        } else {
+            sb.append(" (regular user)");
+        }
         if(reason!=null) {
             sb.append(" : ");
             sb.append(reason);
@@ -46,7 +59,8 @@ public class DisableServiceUser extends ServiceUserOperation {
     @NotNull
     @Override
     public String asRepoInitString() {
-        return String.format("disable service user %s : %s%n", username, escapeQuotes(reason));
+        final String userType = isServiceUser ? "service " : "";
+        return String.format("disable %s user %s : %s%n", userType, username, escapeQuotes(reason));
     }
 
     @Override
@@ -57,4 +71,8 @@ public class DisableServiceUser extends ServiceUserOperation {
     public String getReason() {
         return reason;
     }
+
+    public boolean isServiceUser() {
+        return isServiceUser;
+    }
 }
diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index 9bb7004..f255b47 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -151,7 +151,7 @@ List<Operation> parse() :
         | deleteGroupStatement(result)
         | createUserStatement(result)
         | deleteUserStatement(result)
-        | disableServiceUserStatement(result)
+        | disableUserStatement(result)
         | addToGroupStatement(result)
         | removeFromGroupStatement(result)
         | setPropertiesStatement(result)
@@ -676,17 +676,20 @@ Token quotedString() :
     }
 }
 
-void disableServiceUserStatement(List<Operation> result) :
+void disableUserStatement(List<Operation> result) :
 {
     Token user = null;
     Token msg = null;
+    Token isServiceUser = null;
 }
 {
-    <DISABLE> <SERVICE> <USER> 
+    <DISABLE> ( isServiceUser = <SERVICE> )? <USER>
     ( user = <STRING> )
     ( <COLON> msg = quotedString() )
     {
-        result.add(new DisableServiceUser(user.image, msg.image));
+        DisableServiceUser dsu = new DisableServiceUser(user.image, msg.image);
+        dsu.setServiceUser(isServiceUser != null);
+        result.add(dsu);
     }
 }
 
diff --git a/src/test/java/org/apache/sling/repoinit/parser/test/DisableServiceUserTest.java b/src/test/java/org/apache/sling/repoinit/parser/test/DisableServiceUserTest.java
index cc4851d..4ea39e8 100644
--- a/src/test/java/org/apache/sling/repoinit/parser/test/DisableServiceUserTest.java
+++ b/src/test/java/org/apache/sling/repoinit/parser/test/DisableServiceUserTest.java
@@ -48,4 +48,15 @@ public class DisableServiceUserTest {
         final String reason = "because " + UUID.randomUUID();
         assertEquals(reason, new DisableServiceUser(USERNAME, reason).getReason());
     }
+
+    @Test
+    public void userType() {
+        final String reason = "nothing";
+        final boolean [] values = { false, true };
+        for(boolean value : values) {
+            final DisableServiceUser dsu = new DisableServiceUser(USERNAME, reason);
+            dsu.setServiceUser(value);
+            assertEquals(value, dsu.isServiceUser());
+        }
+    }
 }
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 2b3db6c..7efc057 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
@@ -68,8 +68,9 @@ public class ParsingErrorsTest {
             add(new Object[] { "CREATE service user bob, alice, tom21", ParseException.class });
             add(new Object[] { "create SERVICE user bob, alice, tom21", ParseException.class });
             
-            // Disable service user with missing reason
+            // Disable users with missing reason
             add(new Object[] { "disable service user foo", ParseException.class });
+            add(new Object[] { "disable user regularfoo", ParseException.class });
             
             // Quoted strings in disable service user
             add(new Object[] { "disable service user foo", ParseException.class });
diff --git a/src/test/resources/testcases/test-61-output.txt b/src/test/resources/testcases/test-61-output.txt
index ac995c0..96b4042 100644
--- a/src/test/resources/testcases/test-61-output.txt
+++ b/src/test/resources/testcases/test-61-output.txt
@@ -1,5 +1,5 @@
-DisableServiceUser svcA : This message explains why it's disabled.  Whitespace   is  preserved.
-DisableServiceUser svcB : Testing escaped double "quote" in this string.
-DisableServiceUser svcC : Testing escaped backslash \ in this string.
-DisableServiceUser svcD : Testing quoted escaped backslash "\" in this string.
-DisableServiceUser svcE : Testing unescaped single backslash \ in this string.
\ No newline at end of file
+DisableServiceUser svcA (service user) : This message explains why it's disabled.  Whitespace   is  preserved.
+DisableServiceUser svcB (service user) : Testing escaped double "quote" in this string.
+DisableServiceUser svcC (service user) : Testing escaped backslash \ in this string.
+DisableServiceUser svcD (service user) : Testing quoted escaped backslash "\" in this string.
+DisableServiceUser svcE (service user) : Testing unescaped single backslash \ in this string.
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-69-output.txt b/src/test/resources/testcases/test-69-output.txt
new file mode 100644
index 0000000..84bf0e0
--- /dev/null
+++ b/src/test/resources/testcases/test-69-output.txt
@@ -0,0 +1,5 @@
+DisableServiceUser A (regular user) : This message explains why it's disabled.  Whitespace   is  preserved.
+DisableServiceUser uB (regular user) : Testing escaped double "quote" in this string.
+DisableServiceUser userC (regular user) : Testing escaped backslash \ in this string.
+DisableServiceUser D (regular user) : Testing quoted escaped backslash "\" in this string.
+DisableServiceUser E (regular user) : Testing unescaped single backslash \ in this string.
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-69.txt b/src/test/resources/testcases/test-69.txt
new file mode 100644
index 0000000..72e23e0
--- /dev/null
+++ b/src/test/resources/testcases/test-69.txt
@@ -0,0 +1,6 @@
+# Test "disable user" statements
+disable user A : "This message explains why it's disabled.  Whitespace   is  preserved."
+disable user uB : "Testing escaped double \"quote\" in this string."
+disable user userC : "Testing escaped backslash \\ in this string."
+disable user D : "Testing quoted escaped backslash \"\\\" in this string."
+disable user E : "Testing unescaped single backslash \ in this string."
\ 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 00af423..3d5039c 100644
--- a/src/test/resources/testcases/test-99-output.txt
+++ b/src/test/resources/testcases/test-99-output.txt
@@ -43,7 +43,8 @@ CreateUser userG with path /for/userG (with password), password=ggg
 CreateUser userH with path for/userH
 CreateUser userJ with path for/userJ (with password), password=jjj
 CreateServiceUser the-last-one
-DisableServiceUser svc1 : This  is the message
+DisableServiceUser svc1 (service user) : This  is the message
+DisableServiceUser spongeBob (regular user) : Left the company
 DeleteUser userA
 DeleteUser userB_listsAreNotSupported
 DeleteServiceUser svcA
diff --git a/src/test/resources/testcases/test-99.txt b/src/test/resources/testcases/test-99.txt
index 5b3a255..427c414 100644
--- a/src/test/resources/testcases/test-99.txt
+++ b/src/test/resources/testcases/test-99.txt
@@ -78,6 +78,7 @@ create user userJ with path for/userJ with password jjj
 create service user the-last-one
 
 disable service user svc1 : "This  is the message"
+disable user spongeBob : "Left the company"
 
 # Delete (service) users
 delete user userA