sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-jcr-repoinit] 08/14: improve readability and fix method name
Date Tue, 07 Nov 2017 09:50:32 GMT
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 2311ca12e98159dc420048fc6fe7facf345b68a9
Author: Oliver Lietz <olli@apache.org>
AuthorDate: Thu Mar 9 16:10:45 2017 +0000

    improve readability and fix method name
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/repoinit@1786196
13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/jcr/repoinit/impl/UserUtil.java   | 50 +++++++++++-----------
 .../sling/jcr/repoinit/impl/UserVisitor.java       | 42 +++++++++---------
 2 files changed, 46 insertions(+), 46 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 168ffd7..513d5cb 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
@@ -24,7 +24,7 @@ import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.api.security.user.UserManager;
 
-/** Utilities for (Service) Users management */
+/** Utilities for User management */
 public class UserUtil {
 
     public static UserManager getUserManager(Session session) throws RepositoryException
{
@@ -34,55 +34,55 @@ public class UserUtil {
         return ((JackrabbitSession)session).getUserManager();
     }
 
-    public static Authorizable getAuthorizable(Session session, String username) throws RepositoryException
{
-        return getUserManager(session).getAuthorizable(username);
+    public static Authorizable getAuthorizable(Session session, String id) throws RepositoryException
{
+        return getUserManager(session).getAuthorizable(id);
     }
 
     /** Create a service user - fails if it already exists */
-    public static void createServiceUser(Session s, String username) throws RepositoryException
{
-        getUserManager(s).createSystemUser(username, null);
+    public static void createServiceUser(Session session, String username) throws RepositoryException
{
+        getUserManager(session).createSystemUser(username, null);
     }
 
     /** True if specified service user exists */
     public static boolean serviceUserExists(Session session, String username) throws RepositoryException
{
         boolean result = false;
-        final Authorizable a = getAuthorizable(session, username);
-        if(a != null) {
-            final User u = (User)a;
-            result = u.isSystemUser();
+        final Authorizable authorizable = getAuthorizable(session, username);
+        if(authorizable != null) {
+            final User user = (User)authorizable;
+            result = user.isSystemUser();
         }
         return result;
     }
 
-    public static void deleteUser(Session s, String username) throws RepositoryException
{
-        final Authorizable a = getUserManager(s).getAuthorizable(username);
-        if(a == null) {
-            throw new IllegalStateException("Authorizable not found:" + username);
+    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);
         }
-        a.remove();
+        authorizable.remove();
     }
 
-    /** Create a service user - fails if it already exists */
-    public static void createUser(Session s, String username, String password) throws RepositoryException
{
-        getUserManager(s).createUser(username, password);
+    /** Create a user - fails if it already exists */
+    public static void createUser(Session session, String username, String password) throws
RepositoryException {
+        getUserManager(session).createUser(username, password);
     }
 
     /** True if specified user exists */
-    public static boolean serviceExists(Session session, String username) throws RepositoryException
{
+    public static boolean userExists(Session session, String id) throws RepositoryException
{
         boolean result = false;
-        final Authorizable a = getAuthorizable(session, username);
-        if (a != null) {
-            final User u = (User)a;
-            result = !u.isSystemUser();
+        final Authorizable authorizable = getAuthorizable(session, id);
+        if (authorizable != null) {
+            final User user = (User)authorizable;
+            result = !user.isSystemUser(); // TODO
         }
         return result;
     }
 
     public static void deleteServiceUser(Session s, String username) throws RepositoryException
{
-        final Authorizable a = getUserManager(s).getAuthorizable(username);
-        if(a == null) {
+        final Authorizable authorizable = getUserManager(s).getAuthorizable(username);
+        if(authorizable == null) {
             throw new IllegalStateException("Authorizable not found:" + username);
         }
-        a.remove();
+        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 5612c0a..cd7ac9a 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
@@ -39,61 +39,61 @@ class UserVisitor extends DoNothingVisitor {
 
     @Override
     public void visitCreateServiceUser(CreateServiceUser s) {
-        final String id = s.getUsername();
+        final String username = s.getUsername();
         try {
-            if(!UserUtil.serviceUserExists(session, id)) {
-                log.info("Creating service user {}", id);
-                UserUtil.createServiceUser(session, id);
+            if(!UserUtil.serviceUserExists(session, username)) {
+                log.info("Creating service user {}", username);
+                UserUtil.createServiceUser(session, username);
             } else {
-                log.info("Service user {} already exists, no changes made", id);
+                log.info("Service user {} already exists, no changes made", username);
             }
         } catch(Exception e) {
-            report(e, "Unable to create service user [" + id + "]:" + e);
+            report(e, "Unable to create service user [" + username + "]:" + e);
         }
     }
 
     @Override
     public void visitDeleteServiceUser(DeleteServiceUser s) {
-        final String id = s.getUsername();
-        log.info("Deleting service user {}", id);
+        final String username = s.getUsername();
+        log.info("Deleting service user {}", username);
         try {
-            UserUtil.deleteServiceUser(session, id);
+            UserUtil.deleteServiceUser(session, username);
         } catch(Exception e) {
-            report(e, "Unable to delete service user [" + id + "]:" + e);
+            report(e, "Unable to delete service user [" + username + "]:" + e);
         }
     }
 
     @Override
     public void visitCreateUser(CreateUser u) {
-        final String id = u.getUsername();
+        final String username = u.getUsername();
         try {
-            if(!UserUtil.serviceExists(session, id)) {
+            if(!UserUtil.userExists(session, username)) {
                 final String pwd = u.getPassword();
                 if(pwd != null) {
                     // TODO we might revise this warning once we're able
                     // to create users by providing their encoded password
                     // using u.getPasswordEncoding - for now I think only cleartext works
-                    log.warn("Creating user {} with cleartext password - should NOT be used
on production systems", id);
+                    log.warn("Creating user {} with cleartext password - should NOT be used
on production systems", username);
                 } else {
-                    log.info("Creating user {}", id);
+                    log.info("Creating user {}", username);
                 }
-                UserUtil.createUser(session, id, pwd);
+                UserUtil.createUser(session, username, pwd);
             } else {
-                log.info("User {} already exists, no changes made", id);
+                log.info("User {} already exists, no changes made", username);
             }
         } catch(Exception e) {
-            report(e, "Unable to create user [" + id + "]:" + e);
+            report(e, "Unable to create user [" + username + "]:" + e);
         }
     }
 
     @Override
     public void visitDeleteUser(DeleteUser u) {
-        final String id = u.getUsername();
-        log.info("Deleting user {}", id);
+        final String username = u.getUsername();
+        log.info("Deleting user {}", username);
         try {
-            UserUtil.deleteUser(session, id);
+            UserUtil.deleteUser(session, username);
         } catch(Exception e) {
-            report(e, "Unable to delete user [" + id + "]:" + e);
+            report(e, "Unable to delete user [" + username + "]:" + e);
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message