You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/03/09 13:38:09 UTC

svn commit: r1665212 - /sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrSystemUserValidator.java

Author: cziegeler
Date: Mon Mar  9 12:38:09 2015
New Revision: 1665212

URL: http://svn.apache.org/r1665212
Log:
SLING-4485 : JcrSystemUserValidator uses a non synchronized set

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrSystemUserValidator.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrSystemUserValidator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrSystemUserValidator.java?rev=1665212&r1=1665211&r2=1665212&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrSystemUserValidator.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrSystemUserValidator.java Mon Mar  9 12:38:09 2015
@@ -55,20 +55,21 @@ public class JcrSystemUserValidator impl
     @Reference
     private volatile SlingRepository repository;
 
-    private  Method isSystemUserMethod;
+    private final Method isSystemUserMethod;
 
-    private Set<String> validIds = new CopyOnWriteArraySet<String>();
+    private final Set<String> validIds = new CopyOnWriteArraySet<String>();
 
     public JcrSystemUserValidator() {
+        Method m = null;
         try {
-            isSystemUserMethod = User.class.getMethod("isSystemUser");
+            m = User.class.getMethod("isSystemUser");
         } catch (Exception e) {
             log.debug("Exception while accessing isSystemUser method", e);
-            isSystemUserMethod = null;
         }
+        isSystemUserMethod = m;
     }
 
-    public boolean isValid(String serviceUserId, String serviceName, String subServiceName) {
+    public boolean isValid(final String serviceUserId, final String serviceName, final String subServiceName) {
         if (serviceUserId == null) {
             log.debug("the provided service user id is null");
             return false;
@@ -89,14 +90,14 @@ public class JcrSystemUserValidator impl
                      */
                     administrativeSession = repository.loginAdministrative(null);
                     if (administrativeSession instanceof JackrabbitSession) {
-                        UserManager userManager = ((JackrabbitSession) administrativeSession).getUserManager();
-                        Authorizable authorizable = userManager.getAuthorizable(serviceUserId);
+                        final UserManager userManager = ((JackrabbitSession) administrativeSession).getUserManager();
+                        final Authorizable authorizable = userManager.getAuthorizable(serviceUserId);
                         if (authorizable != null && !authorizable.isGroup() && (isSystemUser((User)authorizable))) {
                             validIds.add(serviceUserId);
                             return true;
                         }
                     }
-                } catch (RepositoryException e) {
+                } catch (final RepositoryException e) {
                     log.debug(e.getMessage());
                 }
             } finally {
@@ -109,7 +110,7 @@ public class JcrSystemUserValidator impl
     }
 
 
-    private boolean isSystemUser(User user){
+    private boolean isSystemUser(final User user){
         if (isSystemUserMethod != null) {
             try {
                 return (Boolean) isSystemUserMethod.invoke(user);