SLING-7148: Do not fail when disabling or deleting a non existing service user.
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 ca88864..41ef4e1 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
@@ -86,10 +86,9 @@
 
     public static void deleteUser(Session session, String id) throws RepositoryException {
         final Authorizable authorizable = getUserManager(session).getAuthorizable(id);
-        if(authorizable == null) {
-            throw new IllegalStateException("Authorizable not found:" + id);
+        if(authorizable != null) {
+            authorizable.remove();
         }
-        authorizable.remove();
     }
 
     public static void disableUser(Session session, String id, String reason) throws RepositoryException {
@@ -97,13 +96,12 @@
             throw new IllegalArgumentException("reason can't be null");
         }
         Authorizable authorizable = getUserManager(session).getAuthorizable(id);
-        if (authorizable == null) {
-            throw new IllegalStateException("Authorizable not found: " + id);
+        if (authorizable != null) {
+            if (authorizable.isGroup()) {
+                throw new IllegalStateException("Can't disable a group: " + id);
+            }
+            ((User)authorizable).disable(reason);
         }
-        if (authorizable.isGroup()) {
-            throw new IllegalStateException("Can't disable a group: " + id);
-        }
-        ((User)authorizable).disable(reason);
     }
 
     /** Create a user - fails if it already exists */
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/CreateServiceUsersTest.java b/src/test/java/org/apache/sling/jcr/repoinit/CreateServiceUsersTest.java
index fe6c339..8d52847 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/CreateServiceUsersTest.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/CreateServiceUsersTest.java
@@ -52,6 +52,34 @@
         U.parseAndExecute("delete service user " + userId);
         U.assertServiceUser("after deleting user", userId, false);
     }
+
+    @Test
+    public void disableTest() throws Exception {
+        final String userId = namePrefix + "_cdst";
+        U.assertServiceUser("at start of test", userId, false);
+        U.parseAndExecute("create service user " + userId);
+        U.assertServiceUser("after creating user", userId, true);
+        U.assertEnabledUser("after creating user", userId);
+        U.parseAndExecute("disable service user " + userId + " : \"Test\"");
+        U.assertServiceUser("after disable user", userId, true);
+        U.assertDisabledUser("after disable user", userId);
+    }
+
+    @Test
+    public void deleteNonExistingUserTest() throws Exception {
+        final String userId = namePrefix + "_cdst";
+        U.assertServiceUser("at start of test", userId, false);
+        U.parseAndExecute("delete service user " + userId);
+        U.assertServiceUser("after deleting user", userId, false);
+    }
+
+    @Test
+    public void disableNonExistingUserTest() throws Exception {
+        final String userId = namePrefix + "_cdst";
+        U.assertServiceUser("at start of test", userId, false);
+        U.parseAndExecute("disable service user " + userId + " : \"Test\"");
+        U.assertServiceUser("after disable user", userId, false);
+    }
     
     private String user(int index) {
         return namePrefix + "_" + index;
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java b/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java
index 8da7c72..e1320ee 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java
@@ -106,6 +106,16 @@
         }
     }
 
+    public void assertEnabledUser(String info, String id) throws RepositoryException {
+        final Authorizable a = UserUtil.getUserManager(adminSession).getAuthorizable(id);
+        assertFalse(info + ", expecting Principal to not be disabled: " + id, ((User) a).isDisabled());
+    }
+
+    public void assertDisabledUser(String info, String id) throws RepositoryException {
+        final Authorizable a = UserUtil.getUserManager(adminSession).getAuthorizable(id);
+        assertTrue(info + ", expecting Principal to be disabled: " + id, ((User) a).isDisabled());
+    }
+
     public void assertNodeExists(String path) throws RepositoryException {
         assertNodeExists(path, null, null);
     }