You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2018/01/30 10:47:39 UTC

[sling-org-apache-sling-jcr-repoinit] branch issues/SLING-7148 updated: SLING-7148: Add a debug message when user doesn't exist and we noop.

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

pauls pushed a commit to branch issues/SLING-7148
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git


The following commit(s) were added to refs/heads/issues/SLING-7148 by this push:
     new af5b352  SLING-7148: Add a debug message when user doesn't exist and we noop.
af5b352 is described below

commit af5b352d26d2477490fcf1f40b449017b23667dc
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Tue Jan 30 11:47:31 2018 +0100

    SLING-7148: Add a debug message when user doesn't exist and we noop.
---
 .../java/org/apache/sling/jcr/repoinit/impl/UserUtil.java    | 12 ++++++++++--
 .../java/org/apache/sling/jcr/repoinit/impl/UserVisitor.java |  8 ++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/UserUtil.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/UserUtil.java
index 41ef4e1..0f8eb63 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/UserUtil.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/UserUtil.java
@@ -84,14 +84,18 @@ public class UserUtil {
         return result;
     }
 
-    public static void deleteUser(Session session, String id) throws RepositoryException {
+    public static boolean deleteUser(Session session, String id) throws RepositoryException {
         final Authorizable authorizable = getUserManager(session).getAuthorizable(id);
         if(authorizable != null) {
             authorizable.remove();
+            return true;
+        }
+        else {
+            return false;
         }
     }
 
-    public static void disableUser(Session session, String id, String reason) throws RepositoryException {
+    public static boolean disableUser(Session session, String id, String reason) throws RepositoryException {
         if (reason == null) {
             throw new IllegalArgumentException("reason can't be null");
         }
@@ -101,6 +105,10 @@ public class UserUtil {
                 throw new IllegalStateException("Can't disable a group: " + id);
             }
             ((User)authorizable).disable(reason);
+            return true;
+        }
+        else {
+            return false;
         }
     }
 
diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/UserVisitor.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/UserVisitor.java
index e53047e..ceb833a 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/UserVisitor.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/UserVisitor.java
@@ -95,7 +95,9 @@ class UserVisitor extends DoNothingVisitor {
         final String username = u.getUsername();
         log.info("Deleting user {}", username);
         try {
-            UserUtil.deleteUser(session, username);
+            if (!UserUtil.deleteUser(session, username)) {
+                log.debug("User {} doesn't exist - assuming delete to be a noop.", username);
+            }
         } catch(Exception e) {
             report(e, "Unable to delete user [" + username + "]:" + e);
         }
@@ -107,7 +109,9 @@ class UserVisitor extends DoNothingVisitor {
         final String reason = dsu.getParametersDescription();
         log.info("Disabling service user {} reason {}", new String[]{username, reason});
         try {
-            UserUtil.disableUser(session, username, reason);
+            if (!UserUtil.disableUser(session, username, reason)) {
+                log.debug("Service user {} doesn't existing - assuming disable to be a noop.", username);
+            }
         } catch(Exception e) {
             report(e, "Unable to disable service user [" + username + "]:" + e);
         }

-- 
To stop receiving notification emails like this one, please contact
pauls@apache.org.