Commits

hani  committed 5ab7ed0

Fix from USER-79

  • Participants
  • Parent commits eb722dd

Comments (0)

Files changed (5)

File src/java/com/opensymphony/user/provider/jdbc/JDBCAccessProvider.java

  * DOCUMENT ME!
  *
  * @author $author$
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
  */
 public class JDBCAccessProvider extends BaseJDBCProvider implements AccessProvider {
     //~ Static fields/initializers /////////////////////////////////////////////
 
             // now try if the group exists
             if (handles == false) {
-              // close before reuse
-              rs.close();
-              ps.close();
+                // close before reuse
+                rs.close();
+                ps.close();
 
                 ps = conn.prepareStatement("SELECT " + groupName + " FROM " + groupTable + " WHERE " + groupName + " = ?");
                 ps.setString(1, name);
             ps = conn.prepareStatement("DELETE FROM " + membershipTable + " WHERE " + membershipGroupName + " = ?");
             ps.setString(1, name);
             ps.executeUpdate();
-            ps.close();  // close before reuse of handle
+            ps.close(); // close before reuse of handle
 
             ps = conn.prepareStatement("DELETE FROM " + groupTable + " WHERE " + groupName + " = ?");
             ps.setString(1, name);
             if (rows == 1) {
                 removed = true;
             }
-
         } catch (SQLException e) {
             log.fatal("Could not remove group [" + name + "]", e);
         } finally {

File src/java/com/opensymphony/user/provider/ldap/LDAPCredentialsProvider.java

     //~ Static fields/initializers /////////////////////////////////////////////
 
     private static final Log log = LogFactory.getLog(LDAPCredentialsProvider.class);
-    static private HashMap cache = new HashMap();
+    static private Map cache = Collections.synchronizedMap(new HashMap());
 
     //~ Instance fields ////////////////////////////////////////////////////////
 
 
     public void flushCaches() {
         // flush the TimeAndPassword cache
-        cache = new HashMap();
+        cache = Collections.synchronizedMap(new HashMap());
     }
 
     public boolean handles(String name) {
 
     public boolean init(Properties properties) {
         if (log.isDebugEnabled()) {
-            log.debug("Credentials Provider " + providerName() + " $Revision: 1.7 $ initializing");
+            log.debug("Credentials Provider " + providerName() + " $Revision: 1.8 $ initializing");
         }
 
         env = new Hashtable(properties);

File src/java/com/opensymphony/user/provider/ofbiz/OFBizAbstractProvider.java

 import org.ofbiz.core.entity.GenericValue;
 import org.ofbiz.core.util.UtilMisc;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
 
 
 /**
     }
 
     public void flushCaches() {
-        nameCache = new HashMap();
+        nameCache = Collections.synchronizedMap(new HashMap());
         clearAllCache();
     }
 
 
         if ((properties.getProperty("exclusive-access") != null) && "true".equalsIgnoreCase(properties.getProperty("exclusive-access"))) {
             exclusiveAccess = true;
-            nameCache = new HashMap();
+            nameCache = Collections.synchronizedMap(new HashMap());
         }
 
         delegator = (String) properties.getProperty("delegator", "default");

File src/java/com/opensymphony/user/provider/ofbiz/OFBizAccessProvider.java

  *
  * @author <a href="mailto:salaman@qoretech.com">Victor Salaman</a>
  * @author <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a>
- * $Revision: 1.1.1.1 $
+ * $Revision: 1.2 $
  */
 public class OFBizAccessProvider extends OFBizAbstractProvider implements AccessProvider {
     //~ Static fields/initializers /////////////////////////////////////////////
 
     // caches for exclusive access
     protected Map userGroupsCache; // caching user -> groups (list)
+    protected Object groupsCacheLock = new Object();
 
     // Attributes ----------------------------------------------------
     protected String groupEntity;
             v.create();
 
             if (exclusiveAccess) {
-                groupsCache.add(name);
-                Collections.sort(groupsCache);
+                synchronized (groupsCacheLock) {
+                    groupsCache.add(name);
+                    Collections.sort(groupsCache);
+                }
             }
         } catch (GenericEntityException e) {
             LOG.error("Could not create group", e);
         super.flushCaches();
 
         if (exclusiveAccess) {
-            groupsCache = null;
-            userGroupsCache = new HashMap();
-            groupUsersCache = new HashMap();
+            synchronized (groupsCacheLock) {
+                groupsCache = null;
+            }
+
+            userGroupsCache = Collections.synchronizedMap(new HashMap());
+            groupUsersCache = Collections.synchronizedMap(new HashMap());
         }
     }
 
             LOG.debug("membershipSequence: " + membershipSequence);
         }
 
-        userGroupsCache = new HashMap();
-        groupUsersCache = new HashMap();
+        userGroupsCache = Collections.synchronizedMap(new HashMap());
+        groupUsersCache = Collections.synchronizedMap(new HashMap());
 
         return superResult;
     }
     // Methods dealing with groups -------------------------------------------------------------------------------------
     public List list() {
         try {
-            if (exclusiveAccess && (groupsCache != null)) {
-                return groupsCache;
+            if (exclusiveAccess) {
+                synchronized (groupsCacheLock) {
+                    if (groupsCache != null) {
+                        return groupsCache;
+                    }
+                }
             }
 
             Collection col = getDelegator().findAll(groupEntity, UtilMisc.toList("name ASC"));
             }
 
             if (exclusiveAccess) {
-                groupsCache = list;
+                synchronized (groupsCacheLock) {
+                    groupsCache = list;
+                }
             }
 
             return list;
     }
 
     public List listGroupsContainingUser(String userName) {
-        if (exclusiveAccess && (userGroupsCache.get(userName) != null)) {
-            return (List) userGroupsCache.get(userName);
+        if (exclusiveAccess) {
+            Object cachedValue = userGroupsCache.get(userName);
+
+            if (cachedValue != null) {
+                return (List) cachedValue;
+            }
         }
 
         List list = new ArrayList();
     }
 
     public List listUsersInGroup(String groupName) {
-        if (exclusiveAccess && (groupUsersCache.get(groupName) != null)) {
-            return (List) groupUsersCache.get(groupName);
+        if (exclusiveAccess) {
+            Object cachedValue = groupUsersCache.get(groupName);
+
+            if ((cachedValue != null)) {
+                return (List) cachedValue;
+            }
         }
 
         List list = new ArrayList();
             getDelegator().removeByAnd(groupEntity, UtilMisc.toMap("name", name));
 
             if (exclusiveAccess) {
-                groupsCache.remove(name);
+                synchronized (groupsCacheLock) {
+                    groupsCache.remove(name);
+                }
             }
 
             return true;

File src/java/com/opensymphony/user/provider/ofbiz/OFBizProfileProvider.java

 import org.ofbiz.core.entity.GenericEntityException;
 import org.ofbiz.core.entity.GenericValue;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
  *
  * @author <a href="mailto:salaman@qoretech.com">Victor Salaman</a>
  * @author <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a>
- * $Revision: 1.1.1.1 $
+ * $Revision: 1.2 $
  */
 public class OFBizProfileProvider extends OFBizAbstractProvider implements ProfileProvider {
     //~ Static fields/initializers /////////////////////////////////////////////
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public PropertySet getPropertySet(String name) {
-        if (exclusiveAccess && (psCache.get(name) != null)) {
-            return (PropertySet) psCache.get(name);
+        if (exclusiveAccess) {
+            Object cachedValue = psCache.get(name);
+
+            if (cachedValue != null) {
+                return (PropertySet) cachedValue;
+            }
         }
 
         try {
         super.flushCaches();
 
         if (exclusiveAccess) {
-            psCache = new HashMap();
+            psCache = Collections.synchronizedMap(new HashMap());
         }
     }
 
         }
 
         if (exclusiveAccess) {
-            psCache = new HashMap();
+            psCache = Collections.synchronizedMap(new HashMap());
         }
 
         return superResult;