Commit 39ec0c06 authored by cdanger's avatar cdanger
Browse files

refactoring

parent 592d668a
...@@ -94,23 +94,27 @@ public class BaseXacmlJaxbResultPostprocessor implements DecisionResultPostproce ...@@ -94,23 +94,27 @@ public class BaseXacmlJaxbResultPostprocessor implements DecisionResultPostproce
final ImmutableList<PepAction> pepActions = result.getPepActions(); final ImmutableList<PepAction> pepActions = result.getPepActions();
assert pepActions != null; assert pepActions != null;
final List<Obligation> obligationList; final List<Obligation> xacmlObligations;
final List<Advice> adviceList; final List<Advice> xacmlAdvices;
if (pepActions.isEmpty()) if (pepActions.isEmpty())
{ {
obligationList = null; xacmlObligations = null;
adviceList = null; xacmlAdvices = null;
} else }
else
{ {
obligationList = new ArrayList<>(pepActions.size()); xacmlObligations = new ArrayList<>(pepActions.size());
adviceList = new ArrayList<>(pepActions.size()); xacmlAdvices = new ArrayList<>(pepActions.size());
pepActions.forEach(pepAction -> { pepActions.forEach(pepAction -> {
final String pepActionId = pepAction.getId();
final List<AttributeAssignment> xacmlAttAssignments = convert(pepAction.getAttributeAssignments());
if (pepAction.isMandatory()) if (pepAction.isMandatory())
{ {
obligationList.add(new Obligation(convert(pepAction.getAttributeAssignments()), pepAction.getId())); xacmlObligations.add(new Obligation(xacmlAttAssignments, pepActionId));
} else }
else
{ {
adviceList.add(new Advice(convert(pepAction.getAttributeAssignments()), pepAction.getId())); xacmlAdvices.add(new Advice(xacmlAttAssignments, pepActionId));
} }
}); });
} }
...@@ -120,7 +124,8 @@ public class BaseXacmlJaxbResultPostprocessor implements DecisionResultPostproce ...@@ -120,7 +124,8 @@ public class BaseXacmlJaxbResultPostprocessor implements DecisionResultPostproce
if (applicablePolicies == null || applicablePolicies.isEmpty()) if (applicablePolicies == null || applicablePolicies.isEmpty())
{ {
jaxbPolicyIdentifiers = null; jaxbPolicyIdentifiers = null;
} else }
else
{ {
final List<JAXBElement<IdReferenceType>> jaxbPolicyIdRefs = new ArrayList<>(applicablePolicies.size()); final List<JAXBElement<IdReferenceType>> jaxbPolicyIdRefs = new ArrayList<>(applicablePolicies.size());
for (final PrimaryPolicyMetadata applicablePolicy : applicablePolicies) for (final PrimaryPolicyMetadata applicablePolicy : applicablePolicies)
...@@ -135,8 +140,8 @@ public class BaseXacmlJaxbResultPostprocessor implements DecisionResultPostproce ...@@ -135,8 +140,8 @@ public class BaseXacmlJaxbResultPostprocessor implements DecisionResultPostproce
jaxbPolicyIdentifiers = new PolicyIdentifierList(jaxbPolicyIdRefs); jaxbPolicyIdentifiers = new PolicyIdentifierList(jaxbPolicyIdRefs);
} }
return new Result(result.getDecision(), result.getStatus(), obligationList == null || obligationList.isEmpty() ? null : new Obligations(obligationList), return new Result(result.getDecision(), result.getStatus(), xacmlObligations == null || xacmlObligations.isEmpty() ? null : new Obligations(xacmlObligations),
adviceList == null || adviceList.isEmpty() ? null : new AssociatedAdvice(adviceList), request == null ? null : request.getAttributesToBeReturned(), jaxbPolicyIdentifiers); xacmlAdvices == null || xacmlAdvices.isEmpty() ? null : new AssociatedAdvice(xacmlAdvices), request == null ? null : request.getAttributesToBeReturned(), jaxbPolicyIdentifiers);
} }
private static void addStatusMessageForEachCause(final Throwable cause, final int currentCauseDepth, final int maxIncludedCauseDepth, final List<Element> statusDetailElements, private static void addStatusMessageForEachCause(final Throwable cause, final int currentCauseDepth, final int maxIncludedCauseDepth, final List<Element> statusDetailElements,
...@@ -220,7 +225,8 @@ public class BaseXacmlJaxbResultPostprocessor implements DecisionResultPostproce ...@@ -220,7 +225,8 @@ public class BaseXacmlJaxbResultPostprocessor implements DecisionResultPostproce
if (maxDepthOfErrorCauseIncludedInResult == 0) if (maxDepthOfErrorCauseIncludedInResult == 0)
{ {
finalStatus = error.getTopLevelStatus(); finalStatus = error.getTopLevelStatus();
} else }
else
{ {
/* /*
* Get Status with detailed cause description. The resulting status contains a StatusDetail element with a list of StatusMessage elements. The nth StatusMessage contains the message of the * Get Status with detailed cause description. The resulting status contains a StatusDetail element with a list of StatusMessage elements. The nth StatusMessage contains the message of the
...@@ -235,7 +241,8 @@ public class BaseXacmlJaxbResultPostprocessor implements DecisionResultPostproce ...@@ -235,7 +241,8 @@ public class BaseXacmlJaxbResultPostprocessor implements DecisionResultPostproce
try try
{ {
marshaller = Xacml3JaxbHelper.createXacml3Marshaller(); marshaller = Xacml3JaxbHelper.createXacml3Marshaller();
} catch (final JAXBException e) }
catch (final JAXBException e)
{ {
// Should not happen // Should not happen
throw new RuntimeException("Failed to create XACML/JAXB marshaller to marshall IndeterminateEvaluationException causes into StatusDetail/StatusMessages of Indeterminate Result", e); throw new RuntimeException("Failed to create XACML/JAXB marshaller to marshall IndeterminateEvaluationException causes into StatusDetail/StatusMessages of Indeterminate Result", e);
...@@ -244,7 +251,8 @@ public class BaseXacmlJaxbResultPostprocessor implements DecisionResultPostproce ...@@ -244,7 +251,8 @@ public class BaseXacmlJaxbResultPostprocessor implements DecisionResultPostproce
try try
{ {
addStatusMessageForEachCause(error.getCause(), 1, maxDepthOfErrorCauseIncludedInResult, statusDetailElements, marshaller); addStatusMessageForEachCause(error.getCause(), 1, maxDepthOfErrorCauseIncludedInResult, statusDetailElements, marshaller);
} catch (final JAXBException e) }
catch (final JAXBException e)
{ {
// Should not happen // Should not happen
throw new RuntimeException("Failed to marshall IndeterminateEvaluationException causes into StatusDetail/StatusMessages of Indeterminate Result", e); throw new RuntimeException("Failed to marshall IndeterminateEvaluationException causes into StatusDetail/StatusMessages of Indeterminate Result", e);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment