private ResultType create(Result result) { ResultType r = new ResultType(); r.setStatus(createStatus(result.getStatus())); r.setResourceId(getResourceId(result)); r.setObligations(getObligations(result)); r.setDecision(V30_TO_V20_DECISION_MAPPING.get(result.getDecision())); return r; }
private ObligationsType getObligations(Result result) { Collection<Obligation> obligations = result.getObligations(); Collection<Advice> advices = result.getAssociatedAdvice(); if (obligations.isEmpty() && advices.isEmpty()) { return null; } ObligationsType obligationsv2 = new ObligationsType(); for (Obligation o : obligations) { obligationsv2.getObligation().add(create(o)); } // Map advice to XACML 2.0 obligations for (Advice a : advices) { obligationsv2.getObligation().add(create(a)); } return obligationsv2; }
/** * Tries to locate resource id attribute * * @param result an evaluation result * @return a resource id attribute */ private String getResourceId(Result result) { if (log.isDebugEnabled()) { log.debug("Mapping result=\"{}\" to resourceId", result); } Category resource = result.getAttribute(Categories.RESOURCE); if (resource == null) { return null; } Collection<Attribute> attrs = resource.getEntity().getAttributes(RESOURCE_ID); if (attrs.size() == 1) { Attribute resourceId = Iterables.getOnlyElement(attrs); AttributeExp v = Iterables.getOnlyElement(resourceId.getValues()); Optional<TypeToString> toString = TypeToString.Types.getIndex().get(v.getType()); Preconditions.checkState(toString.isPresent()); return toString.get().toString(v); } Collection<AttributeExp> values = resource.getEntity().getAttributeValues(CONTENT_SELECTOR, XacmlTypes.XPATH); if (values.isEmpty() || values.size() > 1) { return null; } AttributeExp v = Iterables.getOnlyElement(values); Optional<TypeToString> toString = TypeToString.Types.getIndex().get(v.getType()); Preconditions.checkState(toString.isPresent()); return toString.get().toString(v); }