AbstractPolicyEvaluationCache implements PolicyEvaluationCache { @Override public PolicyEvaluationResult get(final PolicyEvaluationRequestCacheKey evalRequestkey) { DecisionCacheEntries cachedEntries = new DecisionCacheEntries(evalRequestkey); String cachedEvalResultString = cachedEntries.getDecisionString(); if (null == cachedEvalResultString) { return null; } PolicyEvaluationResult cachedEvalResult = toPolicyEvaluationResult(cachedEvalResultString); List<String> attributeInvalidationTimeStamps = new ArrayList<>(); List<String> policyInvalidationTimeStamps = new ArrayList<>(); attributeInvalidationTimeStamps.add(cachedEntries.getSubjectLastModified()); policyInvalidationTimeStamps.addAll(cachedEntries.getPolicySetsLastModified()); Set<String> cachedResolvedResourceUris = cachedEvalResult.getResolvedResourceUris(); if (cachedResolvedResourceUris.size() == 1 && cachedResolvedResourceUris.iterator().next() .equals(evalRequestkey.getResourceId())) { attributeInvalidationTimeStamps.add(cachedEntries.getRequestedResourceLastModified()); } else { List<String> cacheResolvedResourceKeys = cachedResolvedResourceUris.stream() .map(resolvedResourceUri -> resourceKey(evalRequestkey.getZoneId(), resolvedResourceUri)) .collect(Collectors.toList()); attributeInvalidationTimeStamps.addAll(multiGet(cacheResolvedResourceKeys)); } if (isCachedRequestInvalid(attributeInvalidationTimeStamps, policyInvalidationTimeStamps, timestampToDateUTC(cachedEvalResult.getTimestamp()))) { delete(cachedEntries.getDecisionKey()); LOGGER.debug("Cached decision for key '{}' is not valid.", cachedEntries.getDecisionKey()); return null; } return cachedEvalResult; }  @Override PolicyEvaluationResult get(final PolicyEvaluationRequestCacheKey evalRequestkey); @Override void set(final PolicyEvaluationRequestCacheKey key, final PolicyEvaluationResult result); @Override void reset(); @Override void reset(final PolicyEvaluationRequestCacheKey key); @Override void resetForPolicySet(final String zoneId, final String policySetId); @Override void resetForResource(final String zoneId, final String resourceId); @Override void resetForResourcesByIds(final String zoneId, final Set<String> resourceIds); @Override void resetForResources(final String zoneId, final List<ResourceEntity> resourceEntities); @Override void resetForSubject(final String zoneId, final String subjectId); @Override void resetForSubjectsByIds(final String zoneId, final Set<String> subjectIds); @Override void resetForSubjects(final String zoneId, final List<SubjectEntity> subjectEntities);  }
@Test public void testGetWithCacheMissForPolicyEvaluation() { PolicyEvaluationRequestV1 request = new PolicyEvaluationRequestV1(); request.setAction(ACTION_GET); request.setSubjectIdentifier(AGENT_MULDER); request.setResourceIdentifier(XFILES_ID); PolicyEvaluationRequestCacheKey key = new PolicyEvaluationRequestCacheKey.Builder().zoneId(ZONE_NAME) .request(request).build(); assertNull(this.cache.get(key)); }
@Test public void testGetWithCacheMissForPolicyEvaluation() { PolicyEvaluationRequestV1 request = new PolicyEvaluationRequestV1(); request.setAction(ACTION_GET); request.setSubjectIdentifier(AGENT_MULDER); request.setResourceIdentifier(XFILES_ID); PolicyEvaluationRequestCacheKey key = new PolicyEvaluationRequestCacheKey(request, ZONE_NAME); assertNull(this.cache.get(key)); }