Fix edge case scenario when deleting and republishing a XAML policy to the PDP
@@ -78,6 +78,11 @@ public class PolicyCache extends EntitlementBaseCache<IdentityCacheKey, PolicySt
synchronized (localPolicyCacheMap) {
if (localPolicyCacheMap.get(identityCacheKey.getTenantId()) != null) {
if(localPolicyCacheMap.get(identityCacheKey.getTenantId()).get(identityCacheKey.getKey())!=null){
+ if (policyStatus != null && policyStatus.getPolicyId()
+ .equals(localPolicyCacheMap.get(identityCacheKey.getTenantId())
+ .get(identityCacheKey.getKey()).getPolicyId())) {
+ validateAndUpdatePolicyAction(identityCacheKey, policyStatus);
+ }
PolicyStatus status = localPolicyCacheMap.get(identityCacheKey.getTenantId()).get(identityCacheKey.getKey());
status.setPolicyAction(getPriorityAction(status.getPolicyAction(),policyStatus.getPolicyAction()));
if(log.isDebugEnabled()){
@@ -109,6 +114,26 @@ public class PolicyCache extends EntitlementBaseCache<IdentityCacheKey, PolicySt
}
}
+ /**
+ * To update the localPolicyCacheMap whenever the deletion and publishing are carried out at the same time.
+ * <p>
+ * In this edge case, When the user deletes the policy, the deleted policy is added to the policy cache
+ * (policies to be invalidated) with the status- "DELETE" and when the policy is published back again since
+ * there is already a cache entry with the status- "DELETE" the status would not be changed to "UPDATE".
+ *
+ * @param identityCacheKey identity Cache key which wraps the identity related cache key values
+ * @param policyStatus the status of the policy
+ */
+ private static void validateAndUpdatePolicyAction(IdentityCacheKey identityCacheKey, PolicyStatus policyStatus) {
+
+ if (("UPDATE").equals(policyStatus.getPolicyAction()) &&
+ ("DELETE").equals(localPolicyCacheMap.get(identityCacheKey.getTenantId()).get(identityCacheKey.getKey())
+ .getPolicyAction())) {
+ localPolicyCacheMap.get(identityCacheKey.getTenantId()).get(identityCacheKey.getKey())
+ .setPolicyAction(policyStatus.getPolicyAction());
+ }
+ }
+
/**
* Do invalidate all policy cache
*/
