XACML to accept properties as null 64/116464/3
authorliamfallon <liam.fallon@est.tech>
Thu, 17 Dec 2020 16:57:10 +0000 (16:57 +0000)
committerliamfallon <liam.fallon@est.tech>
Mon, 21 Dec 2020 16:30:57 +0000 (16:30 +0000)
xacml-pdp expects the property map to exist in all policies, even if it
is sometimes empty. Now, the propperty map can be null. The code is
updated to cope with a null property map.

Issue-ID: POLICY-2900
Change-Id: Ie31a2770aff1435a1d1064512d0c2fa2088d3183
Signed-off-by: liamfallon <liam.fallon@est.tech>
applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java
applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java
applications/guard/src/test/resources/test-bad-policies.yaml
applications/native/src/main/java/org/onap/policy/xacml/pdp/application/native/NativePdpApplication.java [moved from applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplication.java with 100% similarity]
applications/native/src/main/java/org/onap/policy/xacml/pdp/application/native/NativePdpApplicationTranslator.java [moved from applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java with 95% similarity]
applications/native/src/test/java/org/onap/policy/xacml/pdp/application/native/NativePdpApplicationTest.java [moved from applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java with 100% similarity]

index b3ee36b..2b71374 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -129,6 +130,12 @@ public class GuardTranslator implements ToscaPolicyTranslator {
         //
         this.fillMetadataSection(newPolicyType, toscaPolicy.getMetadata());
         //
+        // There should be properties metadata section
+        //
+        if (toscaPolicy.getProperties() == null) {
+            throw new ToscaPolicyConversionException("no properties specified on guard policy: " + policyName);
+        }
+        //
         // Generate the TargetType - add true if not blacklist
         //
         newPolicyType.setTarget(this.generateTargetType(toscaPolicy.getProperties(),
@@ -694,4 +701,4 @@ public class GuardTranslator implements ToscaPolicyTranslator {
         return rule;
     }
 
-}
\ No newline at end of file
+}
index 7e5e3ed..e4c958b 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -35,6 +36,7 @@ import com.att.research.xacml.std.StdStatusCode;
 import com.att.research.xacml.util.XACMLPolicyWriter;
 import java.io.ByteArrayOutputStream;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
@@ -204,6 +206,16 @@ public class GuardTranslatorTest {
                 }
             }
         }
+
+        ToscaPolicy testPol = completedJtst.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
+
+        testPol.setProperties(new LinkedHashMap<>());
+        assertThatExceptionOfType(ToscaPolicyConversionException.class)
+                .isThrownBy(() -> translator.convertPolicy(testPol));
+
+        testPol.setProperties(null);
+        assertThatExceptionOfType(ToscaPolicyConversionException.class)
+                .isThrownBy(() -> translator.convertPolicy(testPol));
     }
 
     private void validateCommon(ToscaPolicy policy, PolicyType xacmlPolicy) {
index 07040c5..eb39ade 100644 (file)
@@ -5,6 +5,8 @@ topology_template:
          type: onap.policies.controlloop.guard.common.FrequencyLimiter
          type_version: 1.0.0
          version: 1.0.0
+         properties:
+            badProperty: badValue
    -  frequency-timewindow:
          type: onap.policies.controlloop.guard.common.FrequencyLimiter
          type_version: 1.0.0
@@ -16,7 +18,8 @@ topology_template:
          type: onap.policies.controlloop.guard.common.MinMax
          type_version: 1.0.0
          version: 1.0.0
-         properties: null
+         properties:
+            badProperty: badValue
    -  minmax-nominmax:
          type: onap.policies.controlloop.guard.common.MinMax
          type_version: 1.0.0
@@ -27,12 +30,14 @@ topology_template:
          type: onap.policies.controlloop.guard.common.Blacklist
          type_version: 1.0.0
          version: 1.0.0
-         properties: null
+         properties:
+            badProperty: badValue
    -  filter-noalgorithm:
          type: onap.policies.controlloop.guard.common.Filter
          type_version: 1.0.0
          version: 1.0.0
-         properties: null
+         properties:
+            badProperty: badValue
    -  filter-badalgorithm:
          type: onap.policies.controlloop.guard.common.Filter
          type_version: 1.0.0
@@ -3,6 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -30,6 +31,7 @@ import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.Base64;
 import java.util.Map;
+import org.apache.commons.collections4.MapUtils;
 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;
@@ -86,7 +88,7 @@ public class NativePdpApplicationTranslator implements ToscaPolicyTranslator {
     private String getNativeXacmlPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
 
         Map<String, Object> propertyMap = toscaPolicy.getProperties();
-        if (propertyMap.isEmpty() || !propertyMap.containsKey(POLICY)) {
+        if (MapUtils.isEmpty(propertyMap) || !propertyMap.containsKey(POLICY)) {
             throw new ToscaPolicyConversionException("no xacml native policy found in the tosca policy");
         }
 
@@ -107,4 +109,4 @@ public class NativePdpApplicationTranslator implements ToscaPolicyTranslator {
         //
         return null;
     }
-}
\ No newline at end of file
+}