From 6b4f9b69bc4acec28da8ef50b8f234d0182f0d78 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Mon, 16 Mar 2020 11:09:36 -0400 Subject: Missing support for PolicySetType Adds support for PolicySetType specifically for Native policies. When/If the other applications change to support they can easily do so. Adding some more code coverage for Native application and translator. Issue-ID: POLICY-2433 Change-Id: I463ca9f04928d759624a2176598b463057d386bd Signed-off-by: Pamela Dragosh --- .../nativ/NativePdpApplicationTranslator.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'applications/native/src/main') diff --git a/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java b/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java index 546c29eb..5ce25fac 100644 --- a/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java +++ b/applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java @@ -27,11 +27,9 @@ import com.att.research.xacml.api.Response; import com.att.research.xacml.util.XACMLPolicyScanner; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.Map; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; import org.onap.policy.models.decisions.concepts.DecisionRequest; import org.onap.policy.models.decisions.concepts.DecisionResponse; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; @@ -56,7 +54,7 @@ public class NativePdpApplicationTranslator implements ToscaPolicyTranslator { } @Override - public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException { + public Object convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException { // // Extract the Base64 encoded policy xml string and decode it // @@ -67,16 +65,19 @@ public class NativePdpApplicationTranslator implements ToscaPolicyTranslator { } catch (IllegalArgumentException exc) { throw new ToscaPolicyConversionException("error on Base64 decoding the native policy", exc); } - LOGGER.debug("Decoded xacml policy {}",decodedXacmlPolicy); + LOGGER.debug("Decoded xacml policy {}", decodedXacmlPolicy); // // Scan the string and convert to xacml PolicyType // - try (InputStream is = new ByteArrayInputStream(decodedXacmlPolicy.getBytes(StandardCharsets.UTF_8))) { + try (ByteArrayInputStream is = new ByteArrayInputStream(decodedXacmlPolicy.getBytes(StandardCharsets.UTF_8))) { // - // Here we assume it is PolicyType, not PolicySetType - // PolicySetType will be addressed later + // Read the Policy In // - return (PolicyType) XACMLPolicyScanner.readPolicy(is); + Object policy = XACMLPolicyScanner.readPolicy(is); + if (policy == null) { + throw new ToscaPolicyConversionException("Invalid XACML Policy"); + } + return policy; } catch (IOException exc) { throw new ToscaPolicyConversionException("Failed to read policy", exc); } -- cgit 1.2.3-korg