/** * Returns the id of this policy. If the policy is invalid or can't be * retrieved, then a runtime exception is thrown. * * @return the policy id * * @throws ProcessingException if the referenced policy can't be retrieved */ public URI getId() { return resolvePolicy().getId(); }
/** * Returns the target for this policy. If the policy is invalid or can't be * retrieved, then a runtime exception is thrown. * * @return the policy's target * * @throws ProcessingException if the referenced policy can't be retrieved */ public Target getTarget() { return resolvePolicy().getTarget(); }
/** * Returns the child policy nodes and their associated parameters. If * the policy is invalid or can't be retrieved, then a runtime exception * is thrown. * * @return a <code>List</code> of <code>CombinerElement</code>s * * @throws ProcessingException if the referenced policy can't be retrieved */ public List getChildElements() { return resolvePolicy().getChildElements(); }
MatchResult match = policy.match(context); int result = match.getResult();
/** * A private helper routine that resolves a policy for the given * context, and then tries to evaluate based on the policy */ private Result evaluateContext(EvaluationCtx context) { // first off, try to find a policy PolicyFinderResult finderResult = policyFinder.findPolicy(context); // see if there weren't any applicable policies if (finderResult.notApplicable()) return new Result(Result.DECISION_NOT_APPLICABLE, context.getResourceId().encode()); // see if there were any errors in trying to get a policy if (finderResult.indeterminate()) return new Result(Result.DECISION_INDETERMINATE, finderResult.getStatus(), context.getResourceId().encode()); // we found a valid policy, so we can do the evaluation return finderResult.getPolicy().evaluate(context); }
/** * Returns the default version for this policy. If the policy is * invalid or can't be retrieved, then a runtime exception is thrown. * * @return the policy's default version * * @throws ProcessingException if the referenced policy can't be retrieved */ public String getDefaultVersion() { return resolvePolicy().getDefaultVersion(); }
/** * Returns the combining algorithm used by this policy. If the policy is * invalid or can't be retrieved, then a runtime exception is thrown. * * @return the combining algorithm * * @throws ProcessingException if the referenced policy can't be retrieved */ public CombiningAlgorithm getCombiningAlg() { return resolvePolicy().getCombiningAlg(); }
/** * Returns the child policy nodes under this node in the policy tree. If * the policy is invalid or can't be retrieved, then a runtime exception * is thrown. * * @return the <code>List</code> of child policy nodes * * @throws ProcessingException if the referenced policy can't be retrieved */ public List getChildren() { return resolvePolicy().getChildren(); }
AbstractPolicy policy = policyList.get(policyId); MatchResult match = policy.match(eval);
/** * Tries to evaluate the policy by calling the combining algorithm on * the given policies or rules. The <code>match</code> method must always * be called first, and must always return MATCH, before this method * is called. * * @param context the representation of the request * * @return the result of evaluation */ public Result evaluate(EvaluationCtx context) { // if there is no finder, then we return NotApplicable if (finder == null) return new Result(Result.DECISION_NOT_APPLICABLE, context.getResourceId().encode()); PolicyFinderResult pfr = finder.findPolicy(reference, policyType, constraints, parentMetaData); // if we found nothing, then we return NotApplicable if (pfr.notApplicable()) return new Result(Result.DECISION_NOT_APPLICABLE, context.getResourceId().encode()); // if there was an error, we return that status data if (pfr.indeterminate()) return new Result(Result.DECISION_INDETERMINATE, pfr.getStatus(), context.getResourceId().encode()); // we must have found a policy return pfr.getPolicy().evaluate(context); }
/** * Adds a new policy to the collection, and uses the policy's identifier * as the reference identifier. If this identifier already exists in the * collection, and this policy does not represent a new version of the * policy, then the policy is not added. * * @param policy the policy to add * * @return true if the policy was added, false otherwise */ public boolean addPolicy(AbstractPolicy policy) { return addPolicy(policy, policy.getId().toString()); }
MatchResult match = policy.match(context); int result = match.getResult();
@Override public Map<String, AbstractPolicy> loadPolicies(PolicyParser policyParser, boolean validate, File dir) throws IOException, ValidationException { Map<String,AbstractPolicy> policies = new HashMap<String,AbstractPolicy>(); File defaultDir = new File(dir,"default"); if (defaultDir.exists()){ policies.putAll(loadPolicies(policyParser, validate,defaultDir)); } for (File file: dir.listFiles()) { if (!file.getName().equals("default")){ if (file.isDirectory()) { policies.putAll(loadPolicies(policyParser, validate, file)); } else { if (file.getName().endsWith(".xml")) { logger.info("Loading policy: {}", file.getPath()); InputStream policyStream = new FileInputStream(file); AbstractPolicy policy = policyParser.parse(policyStream, validate); logger.info("Loaded policy ID: {}", policy.getId()); String key = null; if (m_override == Strategy.FILENAME) { key = file.getName(); } else key = policy.getId().toString(); policies.put(key, policy); } } } } return policies; }