From 1134bd40da28d3833a0dd4f821e75ec938f6061f Mon Sep 17 00:00:00 2001 From: rb7147 Date: Thu, 6 Sep 2018 16:36:22 -0400 Subject: Resolved XACML Platform Sonar issues Issue-ID: POLICY-902 Change-Id: If22627dfe7df993b5c725ddf3a66c10ebbaa73ca Signed-off-by: rb7147 --- .../controller/DecisionPolicyController.java | 53 +++++++++++----------- 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'POLICY-SDK-APP/src') diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java index fdbee2a99..69c3d2fcb 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java @@ -63,27 +63,28 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableReferenceType; @RequestMapping("/") public class DecisionPolicyController extends RestrictedBaseController { private static final Logger policyLogger = FlexLogger.getLogger(DecisionPolicyController.class); - - public DecisionPolicyController() { - // This constructor is empty - } - + + public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not"; + private static final String BLENTRY = "@blEntry@"; + private static final String DECISIONRAWTYPE = "@#RuleProvider@#Decision_Raw@#RuleProvider@#"; + private static final String GUARD_YAML= "GUARD_YAML"; + private static final String GUARD_BL_YAML= "GUARD_BL_YAML"; + protected PolicyRestAdapter policyAdapter = null; - private ArrayList attributeList; - private ArrayList decisionList; private ArrayList ruleAlgorithmList; private ArrayList treatmentList = null; protected LinkedList ruleAlgoirthmTracker; - public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not"; - private static final String blEntry = "@blEntry@"; - private static final String decisionRawType = "@#RuleProvider@#Decision_Raw@#RuleProvider@#"; - + + public DecisionPolicyController() { + // This constructor is empty + } + public void rawXACMLPolicy(PolicyRestAdapter policyAdapter, PolicyEntity entity) { try (InputStream policyXmlStream = XACMLPolicyWriter.getXmlAsInputStream(policyAdapter.getPolicyData())) { String name = StringUtils.substringAfter(entity.getPolicyName(), "Decision_"); policyAdapter.setPolicyName(name.substring(0, name.indexOf('.'))); policyAdapter.setRuleProvider("Raw"); - policyAdapter.setRawXacmlPolicy(IOUtils.toString(policyXmlStream).replaceAll(decisionRawType, "")); + policyAdapter.setRawXacmlPolicy(IOUtils.toString(policyXmlStream).replaceAll(DECISIONRAWTYPE, "")); } catch (IOException e) { policyLogger.error("Exception Occured while setting XACML Raw Object" + e); } @@ -91,16 +92,16 @@ public class DecisionPolicyController extends RestrictedBaseController { @SuppressWarnings("unchecked") public void prePopulateDecisionPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { - attributeList = new ArrayList<>(); - decisionList = new ArrayList<>(); + List attributeList = new ArrayList<>(); + List decisionList = new ArrayList<>(); ruleAlgorithmList = new ArrayList<>(); treatmentList = new ArrayList<>(); boolean rawPolicyCheck = false; if (policyAdapter.getPolicyData() instanceof PolicySetType) { - rawPolicyCheck = ((PolicySetType) policyAdapter.getPolicyData()).getDescription().contains(decisionRawType); + rawPolicyCheck = ((PolicySetType) policyAdapter.getPolicyData()).getDescription().contains(DECISIONRAWTYPE); } else { - rawPolicyCheck = ((PolicyType) policyAdapter.getPolicyData()).getDescription().contains(decisionRawType); + rawPolicyCheck = ((PolicyType) policyAdapter.getPolicyData()).getDescription().contains(DECISIONRAWTYPE); } if (rawPolicyCheck) { @@ -115,9 +116,9 @@ public class DecisionPolicyController extends RestrictedBaseController { String description = ""; String blackListEntryType = "Use Manual Entry"; try { - if (policy.getDescription().contains(blEntry)) { - blackListEntryType = policy.getDescription().substring(policy.getDescription().indexOf(blEntry) + 9, - policy.getDescription().lastIndexOf(blEntry)); + if (policy.getDescription().contains(BLENTRY)) { + blackListEntryType = policy.getDescription().substring(policy.getDescription().indexOf(BLENTRY) + 9, + policy.getDescription().lastIndexOf(BLENTRY)); } policyAdapter.setBlackListEntryType(blackListEntryType); description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); @@ -226,12 +227,12 @@ public class DecisionPolicyController extends RestrictedBaseController { .getAdviceExpression().get(0).getAdviceId())) { policyAdapter.setRuleProvider("AAF"); break; - } else if ("GUARD_YAML".equalsIgnoreCase(((RuleType) object).getAdviceExpressions() + } else if (GUARD_YAML.equalsIgnoreCase(((RuleType) object).getAdviceExpressions() .getAdviceExpression().get(0).getAdviceId())) { - policyAdapter.setRuleProvider("GUARD_YAML"); - } else if ("GUARD_BL_YAML".equalsIgnoreCase(((RuleType) object).getAdviceExpressions() + policyAdapter.setRuleProvider(GUARD_YAML); + } else if (GUARD_BL_YAML.equalsIgnoreCase(((RuleType) object).getAdviceExpressions() .getAdviceExpression().get(0).getAdviceId())) { - policyAdapter.setRuleProvider("GUARD_BL_YAML"); + policyAdapter.setRuleProvider(GUARD_BL_YAML); } } else { policyAdapter.setRuleProvider("Custom"); @@ -242,8 +243,8 @@ public class DecisionPolicyController extends RestrictedBaseController { decisionApply = (ApplyType) decisionApply.getExpression().get(0).getValue(); ruleAlgoirthmTracker = new LinkedList<>(); if (policyAdapter.getRuleProvider() != null - && ("GUARD_YAML".equals(policyAdapter.getRuleProvider()) - || ("GUARD_BL_YAML".equals(policyAdapter.getRuleProvider())))) { + && (GUARD_YAML.equals(policyAdapter.getRuleProvider()) + || (GUARD_BL_YAML.equals(policyAdapter.getRuleProvider())))) { YAMLParams yamlParams = new YAMLParams(); for (int i = 0; i < attributeList.size(); i++) { Map map = (Map) attributeList.get(i); @@ -266,7 +267,7 @@ public class DecisionPolicyController extends RestrictedBaseController { yamlParams.setGuardActiveEnd( ((AttributeValueType) apply.getExpression().get(2).getValue()).getContent() .get(0).toString()); - if ("GUARD_BL_YAML".equals(policyAdapter.getRuleProvider())) { + if (GUARD_BL_YAML.equals(policyAdapter.getRuleProvider())) { apply = (ApplyType) ((ApplyType) ((ApplyType) decisionApply.getExpression() .get(0).getValue()).getExpression().get(1).getValue()).getExpression() .get(2).getValue(); -- cgit 1.2.3-korg