@Test public void testPrepareToSave() { logger.debug("test PrepareToSave Policy: enter"); boolean response = true; try { response = component.prepareToSave(); } catch (Exception e) { logger.error("Exception Occured" + e); } assertTrue(response); }
@Override public boolean prepareToSave() throws PAPException { if (isPreparedToSave()) { return true; } int version = 0; String policyID = policyAdapter.getPolicyID(); version = policyAdapter.getHighestVersion(); if (policyAdapter.getPolicyType().equals("Action")) { PolicyType policyConfig = new PolicyType(); policyConfig.setVersion(Integer.toString(version)); policyConfig.setPolicyId(policyID); policyConfig.setTarget(new TargetType()); policyAdapter.setData(policyConfig); } policyName = policyAdapter.getNewFileName(); if (policyAdapter.getData() != null) { String comboDictValue = policyAdapter.getActionAttribute(); String actionBody = policyAdapter.getActionBody(); setAttribute(false); if (!(actionBody == null || "".equals(actionBody))) { saveActionBody(policyName, actionBody); setAttribute(true); } else { if (!getAttribute()) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not find " + comboDictValue + " in the ActionPolicyDict table."); return false; } } PolicyType actionPolicy = (PolicyType) policyAdapter.getData(); actionPolicy.setDescription(policyAdapter.getPolicyDescription()); actionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId()); AllOfType allOf = new AllOfType(); Map<String, String> dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes(); for (String keyField : dynamicFieldComponentAttributes.keySet()) { String key = keyField; String value = dynamicFieldComponentAttributes.get(key); MatchType dynamicMatch = createDynamicMatch(key, value); allOf.getMatch().add(dynamicMatch); } AnyOfType anyOf = new AnyOfType(); anyOf.getAllOf().add(allOf); TargetType target = new TargetType(); target.getAnyOf().add(anyOf); actionPolicy.setTarget(target); RuleType rule = new RuleType(); rule.setRuleId(policyAdapter.getRuleID()); rule.setEffect(EffectType.PERMIT); rule.setTarget(new TargetType()); dynamicLabelRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmLabels(); dynamicFieldFunctionRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo(); dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1(); dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2(); if (dynamicLabelRuleAlgorithms != null && !dynamicLabelRuleAlgorithms.isEmpty()) { boolean isCompound = false; ConditionType condition = new ConditionType(); int index = dynamicFieldOneRuleAlgorithms.size() - 1; for (String labelAttr : dynamicLabelRuleAlgorithms) { if (dynamicFieldOneRuleAlgorithms.get(index).equals(labelAttr)) { ApplyType actionApply = new ApplyType(); String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index); String value1 = dynamicFieldOneRuleAlgorithms.get(index); String value2 = dynamicFieldTwoRuleAlgorithms.get(index); actionApply.setFunctionId(getFunctionDefinitionId(selectedFunction)); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1))); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2))); condition.setExpression(new ObjectFactory().createApply(actionApply)); isCompound = true; } } if (!isCompound) { condition.setExpression(new ObjectFactory() .createApply(getInnerActionApply(dynamicLabelRuleAlgorithms.get(index)))); } rule.setCondition(condition); } rule.setObligationExpressions(getObligationExpressions()); actionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); policyAdapter.setPolicyData(actionPolicy); } else { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object." + Objects.requireNonNull(policyAdapter.getData()).getClass().getCanonicalName()); } setPreparedToSave(true); return true; }
ActionPolicy extends Policy { @Override public boolean prepareToSave() throws PAPException { if (isPreparedToSave()) { return true; } int version = 0; String policyID = policyAdapter.getPolicyID(); version = policyAdapter.getHighestVersion(); if (policyAdapter.getPolicyType().equals("Action")) { PolicyType policyConfig = new PolicyType(); policyConfig.setVersion(Integer.toString(version)); policyConfig.setPolicyId(policyID); policyConfig.setTarget(new TargetType()); policyAdapter.setData(policyConfig); } policyName = policyAdapter.getNewFileName(); if (policyAdapter.getData() != null) { String comboDictValue = policyAdapter.getActionAttribute(); String actionBody = policyAdapter.getActionBody(); setAttribute(false); if (!(actionBody == null || "".equals(actionBody))) { saveActionBody(policyName, actionBody); setAttribute(true); } else { if (!getAttribute()) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not find " + comboDictValue + " in the ActionPolicyDict table."); return false; } } PolicyType actionPolicy = (PolicyType) policyAdapter.getData(); actionPolicy.setDescription(policyAdapter.getPolicyDescription()); actionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId()); AllOfType allOf = new AllOfType(); Map<String, String> dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes(); for (String keyField : dynamicFieldComponentAttributes.keySet()) { String key = keyField; String value = dynamicFieldComponentAttributes.get(key); MatchType dynamicMatch = createDynamicMatch(key, value); allOf.getMatch().add(dynamicMatch); } AnyOfType anyOf = new AnyOfType(); anyOf.getAllOf().add(allOf); TargetType target = new TargetType(); target.getAnyOf().add(anyOf); actionPolicy.setTarget(target); RuleType rule = new RuleType(); rule.setRuleId(policyAdapter.getRuleID()); rule.setEffect(EffectType.PERMIT); rule.setTarget(new TargetType()); dynamicLabelRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmLabels(); dynamicFieldFunctionRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo(); dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1(); dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2(); if (dynamicLabelRuleAlgorithms != null && !dynamicLabelRuleAlgorithms.isEmpty()) { boolean isCompound = false; ConditionType condition = new ConditionType(); int index = dynamicFieldOneRuleAlgorithms.size() - 1; for (String labelAttr : dynamicLabelRuleAlgorithms) { if (dynamicFieldOneRuleAlgorithms.get(index).equals(labelAttr)) { ApplyType actionApply = new ApplyType(); String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index); String value1 = dynamicFieldOneRuleAlgorithms.get(index); String value2 = dynamicFieldTwoRuleAlgorithms.get(index); actionApply.setFunctionId(getFunctionDefinitionId(selectedFunction)); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1))); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2))); condition.setExpression(new ObjectFactory().createApply(actionApply)); isCompound = true; } } if (!isCompound) { condition.setExpression(new ObjectFactory() .createApply(getInnerActionApply(dynamicLabelRuleAlgorithms.get(index)))); } rule.setCondition(condition); } rule.setObligationExpressions(getObligationExpressions()); actionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); policyAdapter.setPolicyData(actionPolicy); } else { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object." + Objects.requireNonNull(policyAdapter.getData()).getClass().getCanonicalName()); } setPreparedToSave(true); return true; } }
ActionPolicy extends Policy { @Override public boolean prepareToSave() throws PAPException { if (isPreparedToSave()) { return true; } int version = 0; String policyID = policyAdapter.getPolicyID(); version = policyAdapter.getHighestVersion(); if (policyAdapter.getPolicyType().equals("Action")) { PolicyType policyConfig = new PolicyType(); policyConfig.setVersion(Integer.toString(version)); policyConfig.setPolicyId(policyID); policyConfig.setTarget(new TargetType()); policyAdapter.setData(policyConfig); } policyName = policyAdapter.getNewFileName(); if (policyAdapter.getData() != null) { String comboDictValue = policyAdapter.getActionAttribute(); String actionBody = policyAdapter.getActionBody(); setAttribute(false); if (!(actionBody == null || "".equals(actionBody))) { saveActionBody(policyName, actionBody); setAttribute(true); } else { if (!getAttribute()) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not find " + comboDictValue + " in the ActionPolicyDict table."); return false; } } PolicyType actionPolicy = (PolicyType) policyAdapter.getData(); actionPolicy.setDescription(policyAdapter.getPolicyDescription()); actionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId()); AllOfType allOf = new AllOfType(); Map<String, String> dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes(); for (String keyField : dynamicFieldComponentAttributes.keySet()) { String key = keyField; String value = dynamicFieldComponentAttributes.get(key); MatchType dynamicMatch = createDynamicMatch(key, value); allOf.getMatch().add(dynamicMatch); } AnyOfType anyOf = new AnyOfType(); anyOf.getAllOf().add(allOf); TargetType target = new TargetType(); target.getAnyOf().add(anyOf); actionPolicy.setTarget(target); RuleType rule = new RuleType(); rule.setRuleId(policyAdapter.getRuleID()); rule.setEffect(EffectType.PERMIT); rule.setTarget(new TargetType()); dynamicLabelRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmLabels(); dynamicFieldFunctionRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo(); dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1(); dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2(); if (dynamicLabelRuleAlgorithms != null && !dynamicLabelRuleAlgorithms.isEmpty()) { boolean isCompound = false; ConditionType condition = new ConditionType(); int index = dynamicFieldOneRuleAlgorithms.size() - 1; for (String labelAttr : dynamicLabelRuleAlgorithms) { if (dynamicFieldOneRuleAlgorithms.get(index).equals(labelAttr)) { ApplyType actionApply = new ApplyType(); String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index); String value1 = dynamicFieldOneRuleAlgorithms.get(index); String value2 = dynamicFieldTwoRuleAlgorithms.get(index); actionApply.setFunctionId(getFunctionDefinitionId(selectedFunction)); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1))); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2))); condition.setExpression(new ObjectFactory().createApply(actionApply)); isCompound = true; } } if (!isCompound) { condition.setExpression(new ObjectFactory() .createApply(getInnerActionApply(dynamicLabelRuleAlgorithms.get(index)))); } rule.setCondition(condition); } rule.setObligationExpressions(getObligationExpressions()); actionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); policyAdapter.setPolicyData(actionPolicy); } else { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object." + Objects.requireNonNull(policyAdapter.getData()).getClass().getCanonicalName()); } setPreparedToSave(true); return true; } ActionPolicy();  ActionPolicy(PolicyRestAdapter policyAdapter, CommonClassDao commonClassDao); }
ActionPolicy extends Policy { @Override public boolean prepareToSave() throws PAPException { if (isPreparedToSave()) { return true; } int version = 0; String policyID = policyAdapter.getPolicyID(); version = policyAdapter.getHighestVersion(); if (policyAdapter.getPolicyType().equals("Action")) { PolicyType policyConfig = new PolicyType(); policyConfig.setVersion(Integer.toString(version)); policyConfig.setPolicyId(policyID); policyConfig.setTarget(new TargetType()); policyAdapter.setData(policyConfig); } policyName = policyAdapter.getNewFileName(); if (policyAdapter.getData() != null) { String comboDictValue = policyAdapter.getActionAttribute(); String actionBody = policyAdapter.getActionBody(); setAttribute(false); if (!(actionBody == null || "".equals(actionBody))) { saveActionBody(policyName, actionBody); setAttribute(true); } else { if (!getAttribute()) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not find " + comboDictValue + " in the ActionPolicyDict table."); return false; } } PolicyType actionPolicy = (PolicyType) policyAdapter.getData(); actionPolicy.setDescription(policyAdapter.getPolicyDescription()); actionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId()); AllOfType allOf = new AllOfType(); Map<String, String> dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes(); for (String keyField : dynamicFieldComponentAttributes.keySet()) { String key = keyField; String value = dynamicFieldComponentAttributes.get(key); MatchType dynamicMatch = createDynamicMatch(key, value); allOf.getMatch().add(dynamicMatch); } AnyOfType anyOf = new AnyOfType(); anyOf.getAllOf().add(allOf); TargetType target = new TargetType(); target.getAnyOf().add(anyOf); actionPolicy.setTarget(target); RuleType rule = new RuleType(); rule.setRuleId(policyAdapter.getRuleID()); rule.setEffect(EffectType.PERMIT); rule.setTarget(new TargetType()); dynamicLabelRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmLabels(); dynamicFieldFunctionRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo(); dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1(); dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2(); if (dynamicLabelRuleAlgorithms != null && !dynamicLabelRuleAlgorithms.isEmpty()) { boolean isCompound = false; ConditionType condition = new ConditionType(); int index = dynamicFieldOneRuleAlgorithms.size() - 1; for (String labelAttr : dynamicLabelRuleAlgorithms) { if (dynamicFieldOneRuleAlgorithms.get(index).equals(labelAttr)) { ApplyType actionApply = new ApplyType(); String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index); String value1 = dynamicFieldOneRuleAlgorithms.get(index); String value2 = dynamicFieldTwoRuleAlgorithms.get(index); actionApply.setFunctionId(getFunctionDefinitionId(selectedFunction)); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1))); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2))); condition.setExpression(new ObjectFactory().createApply(actionApply)); isCompound = true; } } if (!isCompound) { condition.setExpression(new ObjectFactory() .createApply(getInnerActionApply(dynamicLabelRuleAlgorithms.get(index)))); } rule.setCondition(condition); } rule.setObligationExpressions(getObligationExpressions()); actionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); policyAdapter.setPolicyData(actionPolicy); } else { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object." + Objects.requireNonNull(policyAdapter.getData()).getClass().getCanonicalName()); } setPreparedToSave(true); return true; } ActionPolicy();  ActionPolicy(PolicyRestAdapter policyAdapter, CommonClassDao commonClassDao); @Override Map<String, String> savePolicies(); @Override boolean prepareToSave(); @Override Object getCorrectPolicyDataObject(); String getFunctionDefinitionId(String key); }
ActionPolicy extends Policy { @Override public boolean prepareToSave() throws PAPException { if (isPreparedToSave()) { return true; } int version = 0; String policyID = policyAdapter.getPolicyID(); version = policyAdapter.getHighestVersion(); if (policyAdapter.getPolicyType().equals("Action")) { PolicyType policyConfig = new PolicyType(); policyConfig.setVersion(Integer.toString(version)); policyConfig.setPolicyId(policyID); policyConfig.setTarget(new TargetType()); policyAdapter.setData(policyConfig); } policyName = policyAdapter.getNewFileName(); if (policyAdapter.getData() != null) { String comboDictValue = policyAdapter.getActionAttribute(); String actionBody = policyAdapter.getActionBody(); setAttribute(false); if (!(actionBody == null || "".equals(actionBody))) { saveActionBody(policyName, actionBody); setAttribute(true); } else { if (!getAttribute()) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not find " + comboDictValue + " in the ActionPolicyDict table."); return false; } } PolicyType actionPolicy = (PolicyType) policyAdapter.getData(); actionPolicy.setDescription(policyAdapter.getPolicyDescription()); actionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId()); AllOfType allOf = new AllOfType(); Map<String, String> dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes(); for (String keyField : dynamicFieldComponentAttributes.keySet()) { String key = keyField; String value = dynamicFieldComponentAttributes.get(key); MatchType dynamicMatch = createDynamicMatch(key, value); allOf.getMatch().add(dynamicMatch); } AnyOfType anyOf = new AnyOfType(); anyOf.getAllOf().add(allOf); TargetType target = new TargetType(); target.getAnyOf().add(anyOf); actionPolicy.setTarget(target); RuleType rule = new RuleType(); rule.setRuleId(policyAdapter.getRuleID()); rule.setEffect(EffectType.PERMIT); rule.setTarget(new TargetType()); dynamicLabelRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmLabels(); dynamicFieldFunctionRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo(); dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1(); dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2(); if (dynamicLabelRuleAlgorithms != null && !dynamicLabelRuleAlgorithms.isEmpty()) { boolean isCompound = false; ConditionType condition = new ConditionType(); int index = dynamicFieldOneRuleAlgorithms.size() - 1; for (String labelAttr : dynamicLabelRuleAlgorithms) { if (dynamicFieldOneRuleAlgorithms.get(index).equals(labelAttr)) { ApplyType actionApply = new ApplyType(); String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index); String value1 = dynamicFieldOneRuleAlgorithms.get(index); String value2 = dynamicFieldTwoRuleAlgorithms.get(index); actionApply.setFunctionId(getFunctionDefinitionId(selectedFunction)); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1))); actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2))); condition.setExpression(new ObjectFactory().createApply(actionApply)); isCompound = true; } } if (!isCompound) { condition.setExpression(new ObjectFactory() .createApply(getInnerActionApply(dynamicLabelRuleAlgorithms.get(index)))); } rule.setCondition(condition); } rule.setObligationExpressions(getObligationExpressions()); actionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); policyAdapter.setPolicyData(actionPolicy); } else { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object." + Objects.requireNonNull(policyAdapter.getData()).getClass().getCanonicalName()); } setPreparedToSave(true); return true; } ActionPolicy();  ActionPolicy(PolicyRestAdapter policyAdapter, CommonClassDao commonClassDao); @Override Map<String, String> savePolicies(); @Override boolean prepareToSave(); @Override Object getCorrectPolicyDataObject(); String getFunctionDefinitionId(String key); static final String JSON_CONFIG; static final String PDP_ACTION; static final String PEP_ACTION; static final String TYPE_ACTION; static final String GET_METHOD; static final String PUT_METHOD; static final String POST_METHOD; static final String PERFORMER_ATTRIBUTEID; static final String TYPE_ATTRIBUTEID; static final String METHOD_ATTRIBUTEID; static final String HEADERS_ATTRIBUTEID; static final String URL_ATTRIBUTEID; static final String BODY_ATTRIBUTEID; }