Remove custom UtilCache caching of security items; this is actually

a bug fix, the minilang services were referencing fields that no
longer existed.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@817316 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adam Heath
2009-09-21 16:48:34 +00:00
parent 9725979827
commit 28e751cc4e
4 changed files with 32 additions and 111 deletions
@@ -72,9 +72,6 @@ under the License.
<make-value value-field="newEntity" entity-name="SecurityGroupPermission"/>
<set-pk-fields map="parameters" value-field="newEntity"/>
<!-- clear the org.ofbiz.security.Security object's custom cache by newEntity -->
<call-bsh><![CDATA[ org.ofbiz.security.Security.securityGroupPermissionCache.remove(newEntity); ]]></call-bsh>
<create-value value-field="newEntity"/>
</simple-method>
<simple-method method-name="removeSecurityPermissionFromSecurityGroup" short-description="Remove SecurityPermission From SecurityGroup">
@@ -85,9 +82,6 @@ under the License.
<set-pk-fields map="parameters" value-field="lookupPKMap"/>
<find-by-primary-key entity-name="SecurityGroupPermission" map="lookupPKMap" value-field="lookedUpValue"/>
<remove-value value-field="lookedUpValue"/>
<!-- clear the org.ofbiz.security.Security object's custom cache by lookupPKMap -->
<call-bsh><![CDATA[ org.ofbiz.security.Security.securityGroupPermissionCache.remove(lookupPKMap); ]]></call-bsh>
</simple-method>
<!-- UserLogin to SecurityGroup methods -->
@@ -105,9 +99,6 @@ under the License.
</if-empty>
<create-value value-field="newEntity"/>
<!-- clear the org.ofbiz.security.Security object's custom cache by userLoginId -->
<call-bsh><![CDATA[ org.ofbiz.security.Security.userLoginSecurityGroupByUserLoginId.remove(parameters.get("userLoginId")); ]]></call-bsh>
</simple-method>
<simple-method method-name="updateUserLoginToSecurityGroup" short-description="Update UserLogin to SecurityGroup">
<check-permission permission="SECURITY" action="_UPDATE"><fail-message message="Security Error: to run updateUserLoginToSecurityGroup you must have the SECURITY_UPDATE or SECURITY_ADMIN permission"/></check-permission>
@@ -118,9 +109,6 @@ under the License.
<find-by-primary-key entity-name="UserLoginSecurityGroup" map="lookupPKMap" value-field="lookedUpValue"/>
<set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
<store-value value-field="lookedUpValue"/>
<!-- clear the org.ofbiz.security.Security object's custom cache by userLoginId -->
<call-bsh><![CDATA[ org.ofbiz.security.Security.userLoginSecurityGroupByUserLoginId.remove(parameters.get("userLoginId")); ]]></call-bsh>
</simple-method>
<simple-method method-name="removeUserLoginFromSecurityGroup" short-description="Remove UserLogin From SecurityGroup">
<check-permission permission="SECURITY" action="_DELETE"><fail-message message="Security Error: to run removeUserLoginFromSecurityGroup you must have the SECURITY_DELETE or SECURITY_ADMIN permission"/></check-permission>
@@ -130,9 +118,6 @@ under the License.
<set-pk-fields map="parameters" value-field="lookupPKMap"/>
<find-by-primary-key entity-name="UserLoginSecurityGroup" map="lookupPKMap" value-field="lookedUpValue"/>
<remove-value value-field="lookedUpValue"/>
<!-- clear the org.ofbiz.security.Security object's custom cache by userLoginId -->
<call-bsh><![CDATA[ org.ofbiz.security.Security.userLoginSecurityGroupByUserLoginId.remove(parameters.get("userLoginId")); ]]></call-bsh>
</simple-method>
<!-- ProtectedView to SecurityGroup methods -->
@@ -144,9 +129,6 @@ under the License.
<set-pk-fields map="parameters" value-field="newEntity"/>
<set-nonpk-fields map="parameters" value-field="newEntity"/>
<!-- clear the org.ofbiz.security.Security object's custom cache by newEntity -->
<call-bsh><![CDATA[ org.ofbiz.security.Security.userLoginSecurityGroupByUserLoginId.remove(newEntity); ]]></call-bsh>
<create-value value-field="newEntity"/>
</simple-method>
<simple-method method-name="updateProtectedViewToSecurityGroup" short-description="Update ProtectedView to SecurityGroup">
@@ -157,9 +139,6 @@ under the License.
<find-by-primary-key entity-name="ProtectedView" map="lookupPKMap" value-field="lookedUpValue"/>
<set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
<store-value value-field="lookedUpValue"/>
<!-- clear the org.ofbiz.security.Security object's custom cache by lookupPKMap -->
<call-bsh><![CDATA[ org.ofbiz.security.Security.userLoginSecurityGroupByUserLoginId.remove(lookupPKMap); ]]></call-bsh>
</simple-method>
<simple-method method-name="removeProtectedViewFromSecurityGroup" short-description="Remove ProtectedView From SecurityGroup">
<check-permission permission="SECURITY" action="_DELETE"><fail-message message="Security Error: to run removeProtectedViewFromSecurityGroup you must have the SECURITY_DELETE or SECURITY_ADMIN permission"/></check-permission>
@@ -169,8 +148,5 @@ under the License.
<set-pk-fields map="parameters" value-field="lookupPKMap"/>
<find-by-primary-key entity-name="ProtectedView" map="lookupPKMap" value-field="lookedUpValue"/>
<remove-value value-field="lookedUpValue"/>
<!-- clear the org.ofbiz.security.Security object's custom cache by lookupPKMap -->
<call-bsh><![CDATA[ org.ofbiz.security.Security.userLoginSecurityGroupByUserLoginId.remove(lookupPKMap); ]]></call-bsh>
</simple-method>
</simple-methods>
@@ -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<String, List<GenericValue>> userLoginSecurityGroupByUserLoginId = new UtilCache<String, List<GenericValue>>("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<GenericValue, Boolean> securityGroupPermissionCache = new UtilCache<GenericValue, Boolean>("security.SecurityGroupPermissionCache");
protected GenericDelegator delegator = null;
protected static final Map<String, Map<String, String>> simpleRoleEntity = UtilMisc.toMap(
@@ -84,17 +72,13 @@ public class OFBizSecurity implements Security {
* @see org.ofbiz.security.Security#findUserLoginSecurityGroupByUserLoginId(java.lang.String)
*/
public Iterator<GenericValue> findUserLoginSecurityGroupByUserLoginId(String userLoginId) {
List<GenericValue> 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<GenericValue> 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")));
}
}
@@ -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.
*
@@ -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<String, List<GenericValue>> userLoginSecurityGroupByUserLoginId = new UtilCache<String, List<GenericValue>>("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<GenericValue, Boolean> securityGroupPermissionCache = new UtilCache<GenericValue, Boolean>("security.SecurityGroupPermissionCache");
/**
* UtilCache to cache Permission Auto Grant permissions
*/
private static UtilCache<String, List<String>> permissionAutoGrantCache = new UtilCache<String, List<String>>("security.PermissionAutoGrantCache");
protected GenericDelegator delegator;
@Override
@@ -158,20 +143,14 @@ public class EntityAuthorization extends AbstractAuthorization {
}
private Iterator<GenericValue> getUserLoginSecurityGroupByUserLoginId(String userId) {
List<GenericValue> collection = userLoginSecurityGroupByUserLoginId.get(userId);
List<GenericValue> 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<String> getPermissionAutoGrant(String permission) {
List<String> autoGrants = permissionAutoGrantCache.get(permission);
Cache cache = delegator.getCache();
EntityCondition condition = EntityCondition.makeCondition(UtilMisc.toMap("permissionId", permission));
List<String> autoGrants = cache.get("SecurityPermissionAutoGrant", condition, "EntityAuthorization.autoGrants");
if (autoGrants == null) {
autoGrants = FastList.newInstance();
List<GenericValue> 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;
}