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:27:48 UTC
[sling-org-apache-sling-jcr-repoinit] 01/01: SLING-7148: Do not
fail when disabling or deleting a non existing service user.
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
commit 0752a818b3e6caa88d2d93903a67e9d0d4f39c42
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Tue Jan 30 11:27:36 2018 +0100
SLING-7148: Do not fail when disabling or deleting a non existing service user.
---
.../apache/sling/jcr/repoinit/impl/UserUtil.java | 16 ++++++-------
.../sling/jcr/repoinit/CreateServiceUsersTest.java | 28 ++++++++++++++++++++++
.../apache/sling/jcr/repoinit/impl/TestUtil.java | 10 ++++++++
3 files changed, 45 insertions(+), 9 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 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 class UserUtil {
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 @@ public class UserUtil {
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.isGroup()) {
- throw new IllegalStateException("Can't disable a group: " + id);
+ if (authorizable != null) {
+ if (authorizable.isGroup()) {
+ throw new IllegalStateException("Can't disable a group: " + id);
+ }
+ ((User)authorizable).disable(reason);
}
- ((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 @@ public class CreateServiceUsersTest {
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 class TestUtil {
}
}
+ 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);
}
--
To stop receiving notification emails like this one, please contact
pauls@apache.org.