diff --git a/applications/securityext/script/org/ofbiz/securityext/securitygroup/SecurityGroupServices.xml b/applications/securityext/script/org/ofbiz/securityext/securitygroup/SecurityGroupServices.xml index 4ad1114dcc..3072cd83ad 100644 --- a/applications/securityext/script/org/ofbiz/securityext/securitygroup/SecurityGroupServices.xml +++ b/applications/securityext/script/org/ofbiz/securityext/securitygroup/SecurityGroupServices.xml @@ -72,9 +72,6 @@ under the License. - - - @@ -85,9 +82,6 @@ under the License. - - - @@ -105,9 +99,6 @@ under the License. - - - @@ -118,9 +109,6 @@ under the License. - - - @@ -130,9 +118,6 @@ under the License. - - - @@ -144,9 +129,6 @@ under the License. - - - @@ -157,9 +139,6 @@ under the License. - - - @@ -169,8 +148,5 @@ under the License. - - - diff --git a/framework/security/src/org/ofbiz/security/OFBizSecurity.java b/framework/security/src/org/ofbiz/security/OFBizSecurity.java index 193dd305e0..abe0e75230 100644 --- a/framework/security/src/org/ofbiz/security/OFBizSecurity.java +++ b/framework/security/src/org/ofbiz/security/OFBizSecurity.java @@ -47,18 +47,6 @@ public class OFBizSecurity implements Security { public static final String module = OFBizSecurity.class.getName(); - /** - * UtilCache to cache a Collection of UserLoginSecurityGroup entities for each UserLogin, by userLoginId. - */ - protected static UtilCache> userLoginSecurityGroupByUserLoginId = new UtilCache>("security.UserLoginSecurityGroupByUserLoginId"); - - /** - * UtilCache to cache whether or not a certain SecurityGroupPermission row exists or not. - * For each SecurityGroupPermissionPK there is a Boolean in the cache specifying whether or not it exists. - * In this way the cache speeds things up whether or not the user has a permission. - */ - protected static UtilCache securityGroupPermissionCache = new UtilCache("security.SecurityGroupPermissionCache"); - protected GenericDelegator delegator = null; protected static final Map> simpleRoleEntity = UtilMisc.toMap( @@ -84,17 +72,13 @@ public class OFBizSecurity implements Security { * @see org.ofbiz.security.Security#findUserLoginSecurityGroupByUserLoginId(java.lang.String) */ public Iterator findUserLoginSecurityGroupByUserLoginId(String userLoginId) { - List collection = userLoginSecurityGroupByUserLoginId.get(userLoginId); - - if (collection == null) { - try { - collection = delegator.findByAnd("UserLoginSecurityGroup", UtilMisc.toMap("userLoginId", userLoginId), null); - // make an empty collection to speed up the case where a userLogin belongs to no security groups, only with no exception of course - if (collection == null) collection = FastList.newInstance(); - userLoginSecurityGroupByUserLoginId.put(userLoginId, collection); - } catch (GenericEntityException e) { - Debug.logWarning(e, module); - } + List collection; + try { + collection = delegator.findByAnd("UserLoginSecurityGroup", UtilMisc.toMap("userLoginId", userLoginId), null); + } catch (GenericEntityException e) { + // make an empty collection to speed up the case where a userLogin belongs to no security groups, only with no exception of course + collection = FastList.newInstance(); + Debug.logWarning(e, module); } // filter each time after cache retreival, ie cache will contain entire list collection = EntityUtil.filterByDate(collection, true); @@ -107,22 +91,12 @@ public class OFBizSecurity implements Security { public boolean securityGroupPermissionExists(String groupId, String permission) { GenericValue securityGroupPermissionValue = delegator.makeValue("SecurityGroupPermission", UtilMisc.toMap("groupId", groupId, "permissionId", permission)); - Boolean exists = (Boolean) securityGroupPermissionCache.get(securityGroupPermissionValue); - - if (exists == null) { - try { - if (delegator.findOne(securityGroupPermissionValue.getEntityName(), securityGroupPermissionValue, false) != null) { - exists = Boolean.TRUE; - } else { - exists = Boolean.FALSE; - } - } catch (GenericEntityException e) { - exists = Boolean.FALSE; - Debug.logWarning(e, module); - } - securityGroupPermissionCache.put(securityGroupPermissionValue, exists); + try { + return delegator.findOne(securityGroupPermissionValue.getEntityName(), securityGroupPermissionValue, false) != null; + } catch (GenericEntityException e) { + Debug.logWarning(e, module); + return false; } - return exists.booleanValue(); } /** @@ -293,7 +267,7 @@ public class OFBizSecurity implements Security { public void clearUserData(GenericValue userLogin) { if (userLogin != null) { - userLoginSecurityGroupByUserLoginId.remove(userLogin.getString("userLoginId")); + delegator.getCache().remove("UserLoginSecurityGroup", EntityCondition.makeCondition("userLoginId", EntityOperator.EQUALS, userLogin.getString("userLoginId"))); } } diff --git a/framework/security/src/org/ofbiz/security/Security.java b/framework/security/src/org/ofbiz/security/Security.java index 821620f1d8..6aff95275c 100644 --- a/framework/security/src/org/ofbiz/security/Security.java +++ b/framework/security/src/org/ofbiz/security/Security.java @@ -46,7 +46,6 @@ public interface Security { /** * Finds whether or not a SecurityGroupPermission row exists given a groupId and permission. - * Uses the securityGroupPermissionCache to speed this up. * The groupId,permission pair is cached instead of the userLoginId,permission pair to keep the cache small and to * make it more changeable. * diff --git a/framework/security/src/org/ofbiz/security/authz/EntityAuthorization.java b/framework/security/src/org/ofbiz/security/authz/EntityAuthorization.java index 817adb902a..4f4c2864a3 100644 --- a/framework/security/src/org/ofbiz/security/authz/EntityAuthorization.java +++ b/framework/security/src/org/ofbiz/security/authz/EntityAuthorization.java @@ -33,6 +33,8 @@ import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.cache.Cache; +import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.security.authz.da.DynamicAccessFactory; import org.ofbiz.security.authz.da.DynamicAccessHandler; @@ -41,23 +43,6 @@ public class EntityAuthorization extends AbstractAuthorization { private static final String module = EntityAuthorization.class.getName(); - /** - * UtilCache to cache a Collection of UserLoginSecurityGroup entities for each UserLogin, by userLoginId. - */ - private static UtilCache> userLoginSecurityGroupByUserLoginId = new UtilCache>("security.UserLoginSecurityGroupByUserLoginId"); - - /** - * UtilCache to cache whether or not a certain SecurityGroupPermission row exists or not. - * For each SecurityGroupPermissionPK there is a Boolean in the cache specifying whether or not it exists. - * In this way the cache speeds things up whether or not the user has a permission. - */ - private static UtilCache securityGroupPermissionCache = new UtilCache("security.SecurityGroupPermissionCache"); - - /** - * UtilCache to cache Permission Auto Grant permissions - */ - private static UtilCache> permissionAutoGrantCache = new UtilCache>("security.PermissionAutoGrantCache"); - protected GenericDelegator delegator; @Override @@ -158,20 +143,14 @@ public class EntityAuthorization extends AbstractAuthorization { } private Iterator getUserLoginSecurityGroupByUserLoginId(String userId) { - List collection = userLoginSecurityGroupByUserLoginId.get(userId); + List collection; - if (collection == null) { - try { - collection = delegator.findByAnd("UserLoginSecurityGroup", UtilMisc.toMap("userLoginId", userId), null); - - // make an empty collection to speed up the case where a userLogin belongs to no security groups, only with no exception of course - if (collection == null) { - collection = FastList.newInstance(); - } - userLoginSecurityGroupByUserLoginId.put(userId, collection); - } catch (GenericEntityException e) { - Debug.logWarning(e, module); - } + try { + collection = delegator.findByAnd("UserLoginSecurityGroup", UtilMisc.toMap("userLoginId", userId), null); + } catch (GenericEntityException e) { + // make an empty collection to speed up the case where a userLogin belongs to no security groups, only with no exception of course + collection = FastList.newInstance(); + Debug.logWarning(e, module); } // filter each time after cache retrieval, i.e. cache will contain entire list @@ -182,32 +161,25 @@ public class EntityAuthorization extends AbstractAuthorization { private boolean securityGroupHasPermission(String groupId, String permission) { GenericValue securityGroupPermissionValue = delegator.makeValue("SecurityGroupPermission", UtilMisc.toMap("groupId", groupId, "permissionId", permission)); - Boolean exists = (Boolean) securityGroupPermissionCache.get(securityGroupPermissionValue); - if (exists == null) { - try { - if (delegator.findOne(securityGroupPermissionValue.getEntityName(), securityGroupPermissionValue, false) != null) { - exists = Boolean.TRUE; - } else { - exists = Boolean.FALSE; - } - } catch (GenericEntityException e) { - exists = Boolean.FALSE; - Debug.logWarning(e, module); - } - securityGroupPermissionCache.put(securityGroupPermissionValue, exists); + try { + return delegator.findOne(securityGroupPermissionValue.getEntityName(), securityGroupPermissionValue, false) != null; + } catch (GenericEntityException e) { + Debug.logWarning(e, module); + return false; } - return exists.booleanValue(); } private List getPermissionAutoGrant(String permission) { - List autoGrants = permissionAutoGrantCache.get(permission); + Cache cache = delegator.getCache(); + EntityCondition condition = EntityCondition.makeCondition(UtilMisc.toMap("permissionId", permission)); + List autoGrants = cache.get("SecurityPermissionAutoGrant", condition, "EntityAuthorization.autoGrants"); if (autoGrants == null) { autoGrants = FastList.newInstance(); List values = null; try { - values = delegator.findByAnd("SecurityPermissionAutoGrant", UtilMisc.toMap("permissionId", permission), null); + values = delegator.findList("SecurityPermissionAutoGrant", condition, null, null, null, true); } catch (GenericEntityException e) { Debug.logWarning(e, module); } @@ -217,7 +189,7 @@ public class EntityAuthorization extends AbstractAuthorization { autoGrants.add(v.getString("grantPermission")); } } - permissionAutoGrantCache.put(permission, autoGrants); + cache.put("SecurityPermissionAutoGrant", condition, "EntityAuthorization.autoGrants", autoGrants); } return autoGrants; }