You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:50:35 UTC
[sling-org-apache-sling-jcr-repoinit] 11/14: SLING-6629 UserUtil
reports user is not existing when user is system user
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.jcr.repoinit-1.1.4
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git
commit 7620d65a00711f6a9d4de0f72752954ce118a704
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Thu Mar 9 17:54:20 2017 +0000
SLING-6629 UserUtil reports user is not existing when user is system user
improve and straighten user handling
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1786208 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/sling/jcr/repoinit/impl/UserUtil.java | 18 +++++-------------
.../apache/sling/jcr/repoinit/impl/UserVisitor.java | 9 ++++++---
2 files changed, 11 insertions(+), 16 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 513d5cb..801a2e7 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
@@ -44,11 +44,11 @@ public class UserUtil {
}
/** True if specified service user exists */
- public static boolean serviceUserExists(Session session, String username) throws RepositoryException {
+ public static boolean isServiceUser(Session session, String id) throws RepositoryException {
boolean result = false;
- final Authorizable authorizable = getAuthorizable(session, username);
- if(authorizable != null) {
- final User user = (User)authorizable;
+ final Authorizable authorizable = getAuthorizable(session, id);
+ if (authorizable != null && !authorizable.isGroup()) {
+ final User user = (User) authorizable;
result = user.isSystemUser();
}
return result;
@@ -72,17 +72,9 @@ public class UserUtil {
boolean result = false;
final Authorizable authorizable = getAuthorizable(session, id);
if (authorizable != null) {
- final User user = (User)authorizable;
- result = !user.isSystemUser(); // TODO
+ result = !authorizable.isGroup();
}
return result;
}
- public static void deleteServiceUser(Session s, String username) throws RepositoryException {
- final Authorizable authorizable = getUserManager(s).getAuthorizable(username);
- if(authorizable == null) {
- throw new IllegalStateException("Authorizable not found:" + username);
- }
- authorizable.remove();
- }
}
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 cd7ac9a..a245f80 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
@@ -41,11 +41,14 @@ class UserVisitor extends DoNothingVisitor {
public void visitCreateServiceUser(CreateServiceUser s) {
final String username = s.getUsername();
try {
- if(!UserUtil.serviceUserExists(session, username)) {
+ if (!UserUtil.userExists(session, username)) {
log.info("Creating service user {}", username);
UserUtil.createServiceUser(session, username);
+ } else if (UserUtil.isServiceUser(session, username)) {
+ log.info("Service user {} already exists, no changes made.", username);
} else {
- log.info("Service user {} already exists, no changes made", username);
+ final String message = String.format("Existing user %s is not a service user.", username);
+ throw new RuntimeException(message);
}
} catch(Exception e) {
report(e, "Unable to create service user [" + username + "]:" + e);
@@ -57,7 +60,7 @@ class UserVisitor extends DoNothingVisitor {
final String username = s.getUsername();
log.info("Deleting service user {}", username);
try {
- UserUtil.deleteServiceUser(session, username);
+ UserUtil.deleteUser(session, username);
} catch(Exception e) {
report(e, "Unable to delete service user [" + username + "]:" + e);
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.