aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PAP-REST/src/main/java')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java267
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/Policy.java137
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java596
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java3
4 files changed, 526 insertions, 477 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java
index eece6c017..47ab45894 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java
@@ -36,10 +36,9 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-
import javax.persistence.EntityManager;
import javax.persistence.Query;
-
+import org.apache.commons.lang3.StringEscapeUtils;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
@@ -61,11 +60,9 @@ import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.onap.policy.xacml.std.pip.engines.aaf.AAFEngine;
import org.onap.policy.xacml.util.XACMLPolicyScanner;
-
import com.att.research.xacml.api.XACML3;
import com.att.research.xacml.api.pap.PAPException;
import com.att.research.xacml.std.IdentifierImpl;
-
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
@@ -78,6 +75,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
@@ -86,7 +84,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableReferenceType;
public class DecisionPolicy extends Policy {
- private static final Logger LOGGER = FlexLogger.getLogger(DecisionPolicy.class);
+ private static final Logger LOGGER = FlexLogger.getLogger(DecisionPolicy.class);
public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not";
private static final String AAFPROVIDER = "AAF";
@@ -113,7 +111,7 @@ public class DecisionPolicy extends Policy {
super();
}
- public DecisionPolicy(PolicyRestAdapter policyAdapter, CommonClassDao commonClassDao){
+ public DecisionPolicy(PolicyRestAdapter policyAdapter, CommonClassDao commonClassDao) {
this.policyAdapter = policyAdapter;
this.commonClassDao = commonClassDao;
}
@@ -122,13 +120,13 @@ public class DecisionPolicy extends Policy {
public Map<String, String> savePolicies() throws PAPException {
Map<String, String> successMap = new HashMap<>();
- if(isPolicyExists()){
+ if (isPolicyExists()) {
successMap.put("EXISTS", "This Policy already exist on the PAP");
return successMap;
}
- if(!isPreparedToSave()){
- //Prep and configure the policy for saving
+ if (!isPreparedToSave()) {
+ // Prep and configure the policy for saving
prepareToSave();
}
@@ -136,17 +134,44 @@ public class DecisionPolicy extends Policy {
Path newPolicyPath = null;
newPolicyPath = Paths.get(policyAdapter.getNewFileName());
- successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());
+ successMap = createPolicy(newPolicyPath, getCorrectPolicyDataObject());
return successMap;
}
+
+ /**
+ * Scan the Raw Policy data and set to PolicyAdapter.
+ */
+ private void readRawPolicyData() {
+ Object policy;
+ if ("API".equalsIgnoreCase(policyAdapter.getApiflag())) {
+ policy = XACMLPolicyScanner.readPolicy(new ByteArrayInputStream(StringEscapeUtils
+ .unescapeXml(policyAdapter.getRawXacmlPolicy()).getBytes(StandardCharsets.UTF_8)));
+ } else {
+ policy = XACMLPolicyScanner.readPolicy(
+ new ByteArrayInputStream(policyAdapter.getRawXacmlPolicy().getBytes(StandardCharsets.UTF_8)));
+ }
+ String policyRawDesc;
+ if (policy instanceof PolicySetType) {
+ policyRawDesc =
+ ((PolicySetType) policy).getDescription() + "@#RuleProvider@#Decision_Raw@#RuleProvider@#";
+ ((PolicySetType) policy).setDescription(policyRawDesc);
+ } else {
+ policyRawDesc = ((PolicyType) policy).getDescription() + "@#RuleProvider@#Decision_Raw@#RuleProvider@#";
+ ((PolicyType) policy).setDescription(policyRawDesc);
+ }
+ policyAdapter.setPolicyData(policy);
+ policyAdapter.setData(policy);
+ setPreparedToSave(true);
+
+ }
- //This is the method for preparing the policy for saving. We have broken it out
- //separately because the fully configured policy is used for multiple things
+ // This is the method for preparing the policy for saving. We have broken it out
+ // separately because the fully configured policy is used for multiple things
@Override
- public boolean prepareToSave() throws PAPException{
+ public boolean prepareToSave() throws PAPException {
- if(isPreparedToSave()){
- //we have already done this
+ if (isPreparedToSave()) {
+ // we have already done this
return true;
}
@@ -154,6 +179,10 @@ public class DecisionPolicy extends Policy {
String policyID = policyAdapter.getPolicyID();
version = policyAdapter.getHighestVersion();
+ if ("Raw".equals(policyAdapter.getRuleProvider())) {
+ readRawPolicyData();
+ return true;
+ }
// Create the Instance for pojo, PolicyType object is used in marshalling.
if ("Decision".equals(policyAdapter.getPolicyType())) {
PolicyType policyConfig = new PolicyType();
@@ -165,10 +194,13 @@ public class DecisionPolicy extends Policy {
}
policyName = policyAdapter.getNewFileName();
- if(policyAdapter.getRuleProvider().equals(GUARD_YAML) || policyAdapter.getRuleProvider().equals(GUARD_BL_YAML)){
+ if (policyAdapter.getRuleProvider().equals(GUARD_YAML)
+ || policyAdapter.getRuleProvider().equals(GUARD_BL_YAML)) {
Map<String, String> yamlParams = new HashMap<>();
- String blackListEntryType = policyAdapter.getBlackListEntryType() !=null ? policyAdapter.getBlackListEntryType(): "Use Manual Entry";
- String description = policyAdapter.getPolicyDescription() != null? policyAdapter.getPolicyDescription(): "YAML Guard Policy";
+ String blackListEntryType = policyAdapter.getBlackListEntryType() != null
+ ? policyAdapter.getBlackListEntryType() : "Use Manual Entry";
+ String description = policyAdapter.getPolicyDescription() != null ? policyAdapter.getPolicyDescription()
+ : "YAML Guard Policy";
yamlParams.put(DESCRIPTION, description + "@blEntry@" + blackListEntryType + "@blEntry@");
String fileName = policyAdapter.getNewFileName();
String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
@@ -190,8 +222,8 @@ public class DecisionPolicy extends Policy {
LOGGER.error(e);
throw new PAPException(e);
}
- }else if (policyAdapter.getData() != null) {
- PolicyType decisionPolicy = (PolicyType) policyAdapter.getData();
+ } else if (policyAdapter.getData() != null) {
+ PolicyType decisionPolicy = (PolicyType) policyAdapter.getData();
decisionPolicy.setDescription(policyAdapter.getPolicyDescription());
@@ -210,7 +242,7 @@ public class DecisionPolicy extends Policy {
allOf.getMatch().add(createMatch(ONAPNAME, (policyAdapter.getOnapName())));
Map<String, String> dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes();
- if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals(AAFPROVIDER)){
+ if (policyAdapter.getRuleProvider() != null && policyAdapter.getRuleProvider().equals(AAFPROVIDER)) {
dynamicFieldComponentAttributes = new HashMap<>();
}
@@ -231,8 +263,8 @@ public class DecisionPolicy extends Policy {
decisionPolicy.setTarget(target);
Map<String, String> dynamicFieldDecisionSettings = policyAdapter.getDynamicSettingsMap();
- if(policyAdapter.getRuleProvider()!=null && (policyAdapter.getRuleProvider().equals(AAFPROVIDER)||
- policyAdapter.getRuleProvider().equals(RAINY_DAY))){
+ if (policyAdapter.getRuleProvider() != null && (policyAdapter.getRuleProvider().equals(AAFPROVIDER)
+ || policyAdapter.getRuleProvider().equals(RAINY_DAY))) {
dynamicFieldDecisionSettings = new HashMap<>();
}
@@ -246,8 +278,8 @@ public class DecisionPolicy extends Policy {
}
Map<String, String> dynamicFieldTreatmentAttributes = policyAdapter.getRainydayMap();
- if(policyAdapter.getRuleProvider().equals(RAINY_DAY)){
- for(String keyField : dynamicFieldTreatmentAttributes.keySet()) {
+ if (policyAdapter.getRuleProvider().equals(RAINY_DAY)) {
+ for (String keyField : dynamicFieldTreatmentAttributes.keySet()) {
String errorcode = keyField;
String treatment = dynamicFieldTreatmentAttributes.get(errorcode);
createRainydayRule(decisionPolicy, errorcode, treatment, true);
@@ -262,47 +294,47 @@ public class DecisionPolicy extends Policy {
return true;
}
- public PolicyType getGuardPolicy(Map<String, String> yamlParams, String ruleProvider) throws BuilderException{
+ public PolicyType getGuardPolicy(Map<String, String> yamlParams, String ruleProvider) throws BuilderException {
try {
ControlLoopGuardBuilder builder = ControlLoopGuardBuilder.Factory.buildControlLoopGuard(new Guard());
MatchParameters matchParameters = new MatchParameters(yamlParams.get("actor"), yamlParams.get("recipe"));
matchParameters.setControlLoopName(yamlParams.get("clname"));
- if(yamlParams.containsKey("targets")){
+ if (yamlParams.containsKey("targets")) {
String targetString = yamlParams.get("targets");
List<String> targets = null;
- if(targetString!=null && !targetString.isEmpty()){
- if (targetString.contains(",")){
+ if (targetString != null && !targetString.isEmpty()) {
+ if (targetString.contains(",")) {
targets = Arrays.asList(targetString.split(","));
- }
- else{
+ } else {
targets = new ArrayList<>();
targets.add(targetString);
}
}
matchParameters.setTargets(targets);
}
- GuardPolicy policy1 = new GuardPolicy((policyAdapter.getUuid()!=null? policyAdapter.getUuid(): UUID.randomUUID().toString()) ,yamlParams.get(POLICY_NAME), yamlParams.get(DESCRIPTION), matchParameters);
+ GuardPolicy policy1 = new GuardPolicy(
+ (policyAdapter.getUuid() != null ? policyAdapter.getUuid() : UUID.randomUUID().toString()),
+ yamlParams.get(POLICY_NAME), yamlParams.get(DESCRIPTION), matchParameters);
builder = builder.addGuardPolicy(policy1);
Map<String, String> activeTimeRange = new HashMap<>();
activeTimeRange.put("start", yamlParams.get("guardActiveStart"));
activeTimeRange.put("end", yamlParams.get("guardActiveEnd"));
String blackListString = yamlParams.get("blackList");
List<String> blackList = null;
- if(blackListString!=null && !blackListString.trim().isEmpty()){
- if (blackListString.contains(",")){
+ if (blackListString != null && !blackListString.trim().isEmpty()) {
+ if (blackListString.contains(",")) {
blackList = Arrays.asList(blackListString.split(","));
- }
- else{
+ } else {
blackList = new ArrayList<>();
blackList.add(blackListString);
}
}
- if(yamlParams.containsKey("appendBlackList")){
+ if (yamlParams.containsKey("appendBlackList")) {
String appendBlackListString = yamlParams.get("appendBlackList");
List<String> appendBlackList = null;
- if(appendBlackListString!=null && !appendBlackListString.trim().isEmpty()){
+ if (appendBlackListString != null && !appendBlackListString.trim().isEmpty()) {
appendBlackList = Arrays.asList(appendBlackListString.split(","));
- for(int i=0; i<appendBlackList.size();i++){
+ for (int i = 0; i < appendBlackList.size(); i++) {
blackList.remove(appendBlackList.get(i));
}
}
@@ -311,32 +343,34 @@ public class DecisionPolicy extends Policy {
Path xacmlTemplatePath;
ClassLoader classLoader = getClass().getClassLoader();
Constraint cons = new Constraint();
- switch (ruleProvider){
- case GUARD_BL_YAML:
- templateFile = new File(classLoader.getResource(XACML_BLGUARD_TEMPLATE).getFile());
- xacmlTemplatePath = templateFile.toPath();
- cons.setActive_time_range(activeTimeRange);
- if(blackList==null || blackList.isEmpty()){
- throw new BuilderException("blackList is required");
- }
- cons.setBlacklist(blackList);
- break;
- default:
- templateFile = new File(classLoader.getResource(XACML_GUARD_TEMPLATE).getFile());
- xacmlTemplatePath = templateFile.toPath();
- Map<String,String> timeWindow = new HashMap<>();
- if(!PolicyUtils.isInteger(yamlParams.get("timeWindow"))){
- throw new BuilderException("time window is not in Integer format.");
- }
- String timeUnits = yamlParams.get("timeUnits");
- if(timeUnits==null || !(timeUnits.equalsIgnoreCase("minute") || timeUnits.equalsIgnoreCase("hour") || timeUnits.equalsIgnoreCase("day")
- || timeUnits.equalsIgnoreCase("week") || timeUnits.equalsIgnoreCase("month")||timeUnits.equalsIgnoreCase("year"))){
- throw new BuilderException("time Units is not in proper format.");
- }
- timeWindow.put("value", yamlParams.get("timeWindow"));
- timeWindow.put("units", yamlParams.get("timeUnits"));
- cons = new Constraint(Integer.parseInt(yamlParams.get("limit")),timeWindow,activeTimeRange);
- break;
+ switch (ruleProvider) {
+ case GUARD_BL_YAML:
+ templateFile = new File(classLoader.getResource(XACML_BLGUARD_TEMPLATE).getFile());
+ xacmlTemplatePath = templateFile.toPath();
+ cons.setActive_time_range(activeTimeRange);
+ if (blackList == null || blackList.isEmpty()) {
+ throw new BuilderException("blackList is required");
+ }
+ cons.setBlacklist(blackList);
+ break;
+ default:
+ templateFile = new File(classLoader.getResource(XACML_GUARD_TEMPLATE).getFile());
+ xacmlTemplatePath = templateFile.toPath();
+ Map<String, String> timeWindow = new HashMap<>();
+ if (!PolicyUtils.isInteger(yamlParams.get("timeWindow"))) {
+ throw new BuilderException("time window is not in Integer format.");
+ }
+ String timeUnits = yamlParams.get("timeUnits");
+ if (timeUnits == null
+ || !("minute".equalsIgnoreCase(timeUnits) || "hour".equalsIgnoreCase(timeUnits)
+ || "day".equalsIgnoreCase(timeUnits) || "week".equalsIgnoreCase(timeUnits)
+ || "month".equalsIgnoreCase(timeUnits) || "year".equalsIgnoreCase(timeUnits))) {
+ throw new BuilderException("time Units is not in proper format.");
+ }
+ timeWindow.put("value", yamlParams.get("timeWindow"));
+ timeWindow.put("units", yamlParams.get("timeUnits"));
+ cons = new Constraint(Integer.parseInt(yamlParams.get("limit")), timeWindow, activeTimeRange);
+ break;
}
builder = builder.addLimitConstraint(policy1.getId(), cons);
// Build the specification
@@ -352,25 +386,36 @@ public class DecisionPolicy extends Policy {
yamlSpecs.put(ONAPNAME, yamlParams.get(ONAPNAME));
yamlSpecs.put("actor", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getActor());
yamlSpecs.put("recipe", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getRecipe());
- yamlSpecs.put("clname", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getControlLoopName());
- if(yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getFreq_limit_per_target()!=null){
- yamlSpecs.put("limit", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getFreq_limit_per_target().toString());
+ yamlSpecs.put("clname",
+ yamlGuardObject.getGuards().getFirst().getMatch_parameters().getControlLoopName());
+ if (yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst()
+ .getFreq_limit_per_target() != null) {
+ yamlSpecs.put("limit", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst()
+ .getFreq_limit_per_target().toString());
}
- if(yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window()!=null){
- yamlSpecs.put("twValue", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window().get("value"));
- yamlSpecs.put("twUnits", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window().get("units"));
+ if (yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window() != null) {
+ yamlSpecs.put("twValue", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst()
+ .getTime_window().get("value"));
+ yamlSpecs.put("twUnits", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst()
+ .getTime_window().get("units"));
}
- yamlSpecs.put("guardActiveStart", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getActive_time_range().get("start"));
- yamlSpecs.put("guardActiveEnd", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getActive_time_range().get("end"));
- String xacmlPolicyContent = SafePolicyBuilder.generateXacmlGuard(xacmlTemplateContent,yamlSpecs, yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getBlacklist(), yamlGuardObject.getGuards().getFirst().getMatch_parameters().getTargets());
- // Convert the Policy into Stream input to Policy Adapter.
- Object policy = XACMLPolicyScanner.readPolicy(new ByteArrayInputStream(xacmlPolicyContent.getBytes(StandardCharsets.UTF_8)));
+ yamlSpecs.put("guardActiveStart", yamlGuardObject.getGuards().getFirst().getLimit_constraints()
+ .getFirst().getActive_time_range().get("start"));
+ yamlSpecs.put("guardActiveEnd", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst()
+ .getActive_time_range().get("end"));
+ String xacmlPolicyContent = SafePolicyBuilder.generateXacmlGuard(xacmlTemplateContent, yamlSpecs,
+ yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getBlacklist(),
+ yamlGuardObject.getGuards().getFirst().getMatch_parameters().getTargets());
+ // Convert the Policy into Stream input to Policy Adapter.
+ Object policy = XACMLPolicyScanner
+ .readPolicy(new ByteArrayInputStream(xacmlPolicyContent.getBytes(StandardCharsets.UTF_8)));
return (PolicyType) policy;
} catch (IOException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error while creating the policy " + e.getMessage() , e);
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error while creating the policy " + e.getMessage(),
+ e);
}
} catch (BuilderException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error while creating the policy " + e.getMessage() ,e);
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error while creating the policy " + e.getMessage(), e);
throw e;
}
return null;
@@ -431,7 +476,7 @@ public class DecisionPolicy extends Policy {
dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1();
dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2();
- if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals(AAFPROVIDER)){
+ if (policyAdapter.getRuleProvider() != null && policyAdapter.getRuleProvider().equals(AAFPROVIDER)) {
// Values for AAF Provider are here for XML Creation.
ConditionType condition = new ConditionType();
ApplyType decisionApply = new ApplyType();
@@ -470,7 +515,7 @@ public class DecisionPolicy extends Policy {
targetInRule.getAnyOf().add(anyOfInRule);
rule.setTarget(targetInRule);
- if(!permitRule){
+ if (!permitRule) {
AdviceExpressionsType adviceExpressions = new AdviceExpressionsType();
AdviceExpressionType adviceExpression = new AdviceExpressionType();
adviceExpression.setAdviceId(AAFPROVIDER);
@@ -491,7 +536,7 @@ public class DecisionPolicy extends Policy {
decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
policyAdapter.setPolicyData(decisionPolicy);
- }else if (dynamicLabelRuleAlgorithms != null && !dynamicLabelRuleAlgorithms.isEmpty()) {
+ } else if (dynamicLabelRuleAlgorithms != null && !dynamicLabelRuleAlgorithms.isEmpty()) {
boolean isCompound = false;
ConditionType condition = new ConditionType();
int index = dynamicFieldOneRuleAlgorithms.size() - 1;
@@ -513,7 +558,8 @@ public class DecisionPolicy extends Policy {
// if rule algorithm not a compound
if (!isCompound) {
- condition.setExpression(new ObjectFactory().createApply(getInnerDecisionApply(dynamicLabelRuleAlgorithms.get(index))));
+ condition.setExpression(new ObjectFactory()
+ .createApply(getInnerDecisionApply(dynamicLabelRuleAlgorithms.get(index))));
}
}
if (!permitRule) {
@@ -537,7 +583,8 @@ public class DecisionPolicy extends Policy {
policyAdapter.setPolicyData(decisionPolicy);
} else {
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object."+ policyAdapter.getData().getClass().getCanonicalName());
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object."
+ + policyAdapter.getData().getClass().getCanonicalName());
}
}
@@ -647,17 +694,17 @@ public class DecisionPolicy extends Policy {
// if two text field are rule attributes.
if ((value1.contains(RULE_VARIABLE)) && (value2.contains(RULE_VARIABLE))) {
ApplyType innerDecisionApply1 = new ApplyType();
- ApplyType innerDecisionApply2 = new ApplyType();
- AttributeDesignatorType attributeDesignator1 = new AttributeDesignatorType();
- AttributeDesignatorType attributeDesignator2 = new AttributeDesignatorType();
- //If selected function is Integer function set integer functionID
- if(functionKey.toLowerCase().contains("integer")){
- innerDecisionApply1.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY );
+ ApplyType innerDecisionApply2 = new ApplyType();
+ AttributeDesignatorType attributeDesignator1 = new AttributeDesignatorType();
+ AttributeDesignatorType attributeDesignator2 = new AttributeDesignatorType();
+ // If selected function is Integer function set integer functionID
+ if (functionKey.toLowerCase().contains("integer")) {
+ innerDecisionApply1.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
innerDecisionApply2.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
attributeDesignator1.setDataType(INTEGER_DATATYPE);
attributeDesignator2.setDataType(INTEGER_DATATYPE);
- } else{
- //If selected function is not a Integer function set String functionID
+ } else {
+ // If selected function is not a Integer function set String functionID
innerDecisionApply1.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
innerDecisionApply2.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
attributeDesignator1.setDataType(STRING_DATATYPE);
@@ -665,11 +712,15 @@ public class DecisionPolicy extends Policy {
}
attributeDesignator1.setCategory(CATEGORY_RESOURCE);
attributeDesignator2.setCategory(CATEGORY_RESOURCE);
- //Here set actual field values
- attributeDesignator1.setAttributeId(value1. contains("resource:")?value1.substring( 9):value1.substring(8));
- attributeDesignator2.setAttributeId(value1. contains("resource:")?value1.substring( 9):value1.substring(8));
- innerDecisionApply1.getExpression().add(new ObjectFactory().createAttributeDesignator( attributeDesignator1));
- innerDecisionApply2.getExpression().add(new ObjectFactory().createAttributeDesignator( attributeDesignator2));
+ // Here set actual field values
+ attributeDesignator1
+ .setAttributeId(value1.contains("resource:") ? value1.substring(9) : value1.substring(8));
+ attributeDesignator2
+ .setAttributeId(value1.contains("resource:") ? value1.substring(9) : value1.substring(8));
+ innerDecisionApply1.getExpression()
+ .add(new ObjectFactory().createAttributeDesignator(attributeDesignator1));
+ innerDecisionApply2.getExpression()
+ .add(new ObjectFactory().createAttributeDesignator(attributeDesignator2));
decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply1));
decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply2));
} else {
@@ -702,8 +753,10 @@ public class DecisionPolicy extends Policy {
attributeDesignator.setAttributeId(attributeId);
}
decisionConditionAttributeValue.getContent().add(attributeValue);
- innerDecisionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator));
- decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(decisionConditionAttributeValue));
+ innerDecisionApply.getExpression()
+ .add(new ObjectFactory().createAttributeDesignator(attributeDesignator));
+ decisionApply.getExpression()
+ .add(new ObjectFactory().createAttributeValue(decisionConditionAttributeValue));
decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply));
} else {
value1 = value1.substring(2, value1.length());
@@ -715,8 +768,10 @@ public class DecisionPolicy extends Policy {
AttributeValueType decisionConditionAttributeValue = new AttributeValueType();
decisionConditionAttributeValue.setDataType(dataType);
decisionConditionAttributeValue.getContent().add(value2);
- decisionApply.getExpression().add(new ObjectFactory().createVariableReference(variableReferenceType));
- decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(decisionConditionAttributeValue));
+ decisionApply.getExpression()
+ .add(new ObjectFactory().createVariableReference(variableReferenceType));
+ decisionApply.getExpression()
+ .add(new ObjectFactory().createAttributeValue(decisionConditionAttributeValue));
}
}
}
@@ -753,12 +808,13 @@ public class DecisionPolicy extends Policy {
private void populateDataTypeList(String value1) {
String dataType = null;
- if(value1.contains("S_")) {
+ if (value1.contains("S_")) {
value1 = value1.substring(2, value1.length());
DecisionSettings decisionSettings = findDecisionSettingsBySettingId(value1.substring(2, value1.length()));
if (decisionSettings != null && "string".equals(decisionSettings.getDatatypeBean().getShortName())) {
dataType = STRING_DATATYPE;
- } else if (decisionSettings != null && "boolean".equals(decisionSettings.getDatatypeBean().getShortName())) {
+ } else if (decisionSettings != null
+ && "boolean".equals(decisionSettings.getDatatypeBean().getShortName())) {
dataType = BOOLEAN_DATATYPE;
} else {
dataType = INTEGER_DATATYPE;
@@ -792,9 +848,10 @@ public class DecisionPolicy extends Policy {
return policyAdapter.getData();
}
- public String getFunctionDefinitionId(String key){
- FunctionDefinition object = (FunctionDefinition) commonClassDao.getDataById(FunctionDefinition.class, "shortname", key);
- if(object != null){
+ public String getFunctionDefinitionId(String key) {
+ FunctionDefinition object =
+ (FunctionDefinition) commonClassDao.getDataById(FunctionDefinition.class, "shortname", key);
+ if (object != null) {
return object.getXacmlid();
}
return null;
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/Policy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/Policy.java
index 1be27ae71..549d26b28 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/Policy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/Policy.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,7 +30,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
-
import org.apache.commons.io.FilenameUtils;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
@@ -39,22 +38,20 @@ import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.rest.XACMLRestProperties;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
import org.onap.policy.xacml.util.XACMLPolicyWriter;
-
import com.att.research.xacml.api.pap.PAPException;
import com.att.research.xacml.std.IdentifierImpl;
import com.att.research.xacml.util.XACMLProperties;
import com.att.research.xacmlatt.pdp.policy.PolicyDef;
import com.att.research.xacmlatt.pdp.policy.dom.DOMPolicyDef;
-
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
public abstract class Policy {
- private static final Logger LOGGER = FlexLogger.getLogger(Policy.class);
-
+ private static final Logger LOGGER = FlexLogger.getLogger(Policy.class);
/**
* Common Fields
@@ -89,20 +86,26 @@ public abstract class Policy {
}
// Constants Used in XML Creation
- public static final String CATEGORY_RECIPIENT_SUBJECT = "urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject";
+ public static final String CATEGORY_RECIPIENT_SUBJECT =
+ "urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject";
public static final String CATEGORY_RESOURCE = "urn:oasis:names:tc:xacml:3.0:attribute-category:resource";
public static final String CATEGORY_ACTION = "urn:oasis:names:tc:xacml:3.0:attribute-category:action";
public static final String CATEGORY_ACCESS_SUBJECT = "urn:oasis:names:tc:xacml:1.0:subject-category:access-subject";
public static final String ACTION_ID = "urn:oasis:names:tc:xacml:1.0:action:action-id";
public static final String SUBJECT_ID = "urn:oasis:names:tc:xacml:1.0:subject:subject-id";
public static final String RESOURCE_ID = "urn:oasis:names:tc:xacml:1.0:resource:resource-id";
- public static final String FUNTION_INTEGER_ONE_AND_ONLY = "urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only";
- public static final String FUNCTION_STRING_ONE_AND_ONLY = "urn:oasis:names:tc:xacml:1.0:function:string-one-and-only";
- public static final String FUNCTION_BOOLEAN_ONE_AND_ONLY = "urn:oasis:names:tc:xacml:1.0:function:boolean-one-and-only";
+ public static final String FUNTION_INTEGER_ONE_AND_ONLY =
+ "urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only";
+ public static final String FUNCTION_STRING_ONE_AND_ONLY =
+ "urn:oasis:names:tc:xacml:1.0:function:string-one-and-only";
+ public static final String FUNCTION_BOOLEAN_ONE_AND_ONLY =
+ "urn:oasis:names:tc:xacml:1.0:function:boolean-one-and-only";
public static final String FUNCTION_STRING_EQUAL = "urn:oasis:names:tc:xacml:1.0:function:string-equal";
public static final String FUNCTION_STRING_REGEX_MATCH = "org.onap.function.regex-match";
- public static final String FUNCTION_STRING_REGEXP_MATCH = "urn:oasis:names:tc:xacml:1.0:function:string-regexp-match";
- public static final String FUNCTION_STRING_EQUAL_IGNORE = "urn:oasis:names:tc:xacml:3.0:function:string-equal-ignore-case";
+ public static final String FUNCTION_STRING_REGEXP_MATCH =
+ "urn:oasis:names:tc:xacml:1.0:function:string-regexp-match";
+ public static final String FUNCTION_STRING_EQUAL_IGNORE =
+ "urn:oasis:names:tc:xacml:3.0:function:string-equal-ignore-case";
public static final String INTEGER_DATATYPE = "http://www.w3.org/2001/XMLSchema#integer";
public static final String BOOLEAN_DATATYPE = "http://www.w3.org/2001/XMLSchema#boolean";
public static final String STRING_DATATYPE = "http://www.w3.org/2001/XMLSchema#string";
@@ -130,21 +133,26 @@ public abstract class Policy {
performer.put("PEP", "PEPAction");
}
- //Each policy type seems to either use policyData or data field policy adapter when
- //getting the xml to save the policy. Instead of keep this hardcoded in the save method,
- //this method makes it usable outside.
+ // Each policy type seems to either use policyData or data field policy
+ // adapter when
+ // getting the xml to save the policy. Instead of keep this hardcoded in the
+ // save method,
+ // this method makes it usable outside.
/**
- * Return the data field of the PolicyAdapter that will be used when saving this policy
- * with the savePolicies method.
+ * Return the data field of the PolicyAdapter that will be used when saving this policy with the savePolicies
+ * method.
+ *
* @return Either the PolicyAdapter.getData() or PolicyAdapter.getPolicyData()
*/
public abstract Object getCorrectPolicyDataObject();
- public abstract Map<String, String> savePolicies() throws PAPException;
- //This is the method for preparing the policy for saving. We have broken it out
- //separately because the fully configured policy is used for multiple things
- public abstract boolean prepareToSave() throws PAPException;
+ public abstract Map<String, String> savePolicies() throws PAPException;
+ // This is the method for preparing the policy for saving. We have broken it
+ // out
+ // separately because the fully configured policy is used for multiple
+ // things
+ public abstract boolean prepareToSave() throws PAPException;
// create match for onap and config name
protected MatchType createMatch(String key, String value) {
@@ -157,9 +165,9 @@ public abstract class Policy {
AttributeDesignatorType attributeDesignator = new AttributeDesignatorType();
URI uri = null;
try {
- uri = new URI(key);
+ uri = new URI(key.replaceAll("\\s+", ""));
} catch (URISyntaxException e) {
- LOGGER.error("Exception Occured"+e);
+ LOGGER.error("Exception Occured" + e);
}
attributeDesignator.setCategory(CATEGORY_ACCESS_SUBJECT);
attributeDesignator.setDataType(STRING_DATATYPE);
@@ -183,9 +191,9 @@ public abstract class Policy {
URI dynamicURI = null;
try {
- dynamicURI = new URI(key);
+ dynamicURI = new URI(key.replaceAll("\\s+", ""));
} catch (URISyntaxException e) {
- LOGGER.error("Exception Occured"+e);// log msg
+ LOGGER.error("Exception Occured" + e);// log msg
}
dynamicAttributeDesignator.setCategory(CATEGORY_RESOURCE);
dynamicAttributeDesignator.setDataType(dataType);
@@ -196,8 +204,7 @@ public abstract class Policy {
return dynamicMatch;
}
- // the Policy Name as Unique One throws error
- @SuppressWarnings("static-access")
+ // the Policy Name as Unique One throws error
protected Path getNextFilename(Path parent, String policyType, String polcyFileName, Integer version) {
policyType = FilenameUtils.removeExtension(policyType);
polcyFileName = FilenameUtils.removeExtension(polcyFileName);
@@ -223,7 +230,8 @@ public abstract class Policy {
return null;
}
- protected Path getNextLoopFilename(Path parentPath, String policyType, String policyConfigType, String policyFileName, Integer version) {
+ protected Path getNextLoopFilename(Path parentPath, String policyType, String policyConfigType,
+ String policyFileName, Integer version) {
policyType = FilenameUtils.removeExtension(policyType);
policyConfigType = FilenameUtils.removeExtension(policyConfigType);
policyFileName = FilenameUtils.removeExtension(policyFileName);
@@ -239,14 +247,18 @@ public abstract class Policy {
String fileName = "default";
if (!policyDir.equals(EMPTY_STRING)) {
- if("ClosedLoop_PM".equals(policyConfigType)){
- fileName = policyType + "_" + "PM" + "_" +java.lang.String.format(policyFileName) + "." +version +".xml";
- }else if("ClosedLoop_Fault".equals(policyConfigType)){
- fileName = policyType + "_" + "Fault" + "_" +java.lang.String.format(policyFileName) + "." + version + ".xml";
- }else if("Micro Service".equals(policyConfigType)){
- fileName = policyType + "_" + "MS" + "_" + java.lang.String.format(policyFileName) + "." + version + ".xml";
- }else if("Optimization".equals(policyConfigType)) {
- fileName = policyType + "_" + "OOF" + "_" + java.lang.String.format(policyFileName) + "." + version + ".xml";
+ if ("ClosedLoop_PM".equals(policyConfigType)) {
+ fileName = policyType + "_" + "PM" + "_" + java.lang.String.format(policyFileName) + "." + version
+ + ".xml";
+ } else if ("ClosedLoop_Fault".equals(policyConfigType)) {
+ fileName = policyType + "_" + "Fault" + "_" + java.lang.String.format(policyFileName) + "." + version
+ + ".xml";
+ } else if ("Micro Service".equals(policyConfigType)) {
+ fileName = policyType + "_" + "MS" + "_" + java.lang.String.format(policyFileName) + "." + version
+ + ".xml";
+ } else if ("Optimization".equals(policyConfigType)) {
+ fileName = policyType + "_" + "OOF" + "_" + java.lang.String.format(policyFileName) + "." + version
+ + ".xml";
}
}
@@ -258,30 +270,29 @@ public abstract class Policy {
return null;
}
-
- //create policy once all the validations are completed
+ // create policy once all the validations are completed
protected Map<String, String> createPolicy(final Path policyPath, final Object policyData) {
Map<String, String> success = new HashMap<>();
//
// Is the root a PolicySet or Policy?
//
- if (policyData instanceof PolicyType) {
+ if (policyData instanceof PolicyType || policyData instanceof PolicySetType) {
//
// Write it out
//
- //Does not need to be XACMLPolicyWriterWithPapNotify since it is already in the PAP
- //and this transaction is intercepted up stream.
-
- try(InputStream inputStream = XACMLPolicyWriter.getXmlAsInputStream((PolicyType) policyData)) {
+ // Does not need to be XACMLPolicyWriterWithPapNotify since it is
+ // already in the PAP
+ // and this transaction is intercepted up stream.
+ try (InputStream inputStream = XACMLPolicyWriter.getXmlAsInputStream(policyData)) {
PolicyDef policyDef = DOMPolicyDef.load(inputStream);
if (policyDef == null) {
success.put("validation", "PolicyDef Validation Failed");
- }else{
+ } else {
success.put("success", "success");
}
} catch (Exception e) {
- LOGGER.error("PolicyDef Validation failed"+e);
+ LOGGER.error("PolicyDef Validation failed" + e);
success.put("error", "Validation Failed");
}
} else {
@@ -291,7 +302,7 @@ public abstract class Policy {
return success;
}
- public static String getConfigHome(){
+ public static String getConfigHome() {
try {
loadWebapps();
} catch (Exception e) {
@@ -301,7 +312,7 @@ public abstract class Policy {
return configHome;
}
- public static String getActionHome(){
+ public static String getActionHome() {
try {
loadWebapps();
} catch (Exception e) {
@@ -311,35 +322,38 @@ public abstract class Policy {
return actionHome;
}
- private static void loadWebapps() throws PAPException{
- if(actionHome == null || configHome == null){
+ private static void loadWebapps() throws PAPException {
+ if (actionHome == null || configHome == null) {
Path webappsPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS));
- //Sanity Check
+ // Sanity Check
if (webappsPath == null) {
PolicyLogger.error("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS);
- throw new PAPException("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS);
+ throw new PAPException(
+ "Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS);
}
Path webappsPathConfig;
Path webappsPathAction;
- if(webappsPath.toString().contains("\\")){
- webappsPathConfig = Paths.get(webappsPath.toString()+"\\Config");
- webappsPathAction = Paths.get(webappsPath.toString()+"\\Action");
- }else{
- webappsPathConfig = Paths.get(webappsPath.toString()+"/Config");
- webappsPathAction = Paths.get(webappsPath.toString()+"/Action");
+ if (webappsPath.toString().contains("\\")) {
+ webappsPathConfig = Paths.get(webappsPath.toString() + "\\Config");
+ webappsPathAction = Paths.get(webappsPath.toString() + "\\Action");
+ } else {
+ webappsPathConfig = Paths.get(webappsPath.toString() + "/Config");
+ webappsPathAction = Paths.get(webappsPath.toString() + "/Action");
}
- if(!webappsPathConfig.toFile().exists()){
+ if (!webappsPathConfig.toFile().exists()) {
try {
Files.createDirectories(webappsPathConfig);
} catch (IOException e) {
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Policy", "Failed to create config directory");
+ PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Policy",
+ "Failed to create config directory");
}
}
- if(!webappsPathAction.toFile().exists()){
+ if (!webappsPathAction.toFile().exists()) {
try {
Files.createDirectories(webappsPathAction);
} catch (IOException e) {
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Policy", "Failed to create config directory");
+ PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Policy",
+ "Failed to create config directory");
}
}
actionHome = webappsPathAction.toString();
@@ -373,5 +387,4 @@ public abstract class Policy {
this.policyExists = policyExists;
}
-
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
index cedefb04e..ff4525ffb 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
@@ -49,7 +49,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
-
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.LockModeType;
@@ -60,7 +59,6 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
-
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.onap.policy.common.logging.eelf.MessageCodes;
@@ -87,8 +85,8 @@ import org.onap.policy.xacml.std.pap.StdPDPPolicy;
import org.onap.policy.xacml.util.XACMLPolicyWriter;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
-
import com.att.research.xacml.api.pap.PAPException;
import com.att.research.xacml.api.pap.PDP;
import com.att.research.xacml.api.pap.PDPPolicy;
@@ -106,7 +104,7 @@ public class PolicyDBDao {
private static final String PROPERTIES_CONFIG = "PROPERTIES";
private static final String OTHER_CONFIG = "OTHER";
- //Declared to static variables which were repeating multiple times across the PolicyDBDao
+ // Declared to static variables which were repeating multiple times across the PolicyDBDao
public static final String config = "Config";
public static final String action = "Action";
private static final String groupIdVar = "groupId";
@@ -135,13 +133,13 @@ public class PolicyDBDao {
}
/**
- * Get an instance of a PolicyDBDao. It creates one if it does not exist.
- * Only one instance is allowed to be created per server.
+ * Get an instance of a PolicyDBDao. It creates one if it does not exist. Only one instance is allowed to be created
+ * per server.
*
* @param emf The EntityFactoryManager to be used for database connections
* @return The new instance of PolicyDBDao or throw exception if the given emf is null.
- * @throws IllegalStateException if a PolicyDBDao has already been constructed. Call getPolicyDBDaoInstance() to
- * get this.
+ * @throws IllegalStateException if a PolicyDBDao has already been constructed. Call getPolicyDBDaoInstance() to get
+ * this.
*/
public static PolicyDBDao getPolicyDBDaoInstance(EntityManagerFactory emf) {
logger.debug("getPolicyDBDaoInstance(EntityManagerFactory emf) as getPolicyDBDaoInstance(" + emf + ") called");
@@ -160,7 +158,7 @@ public class PolicyDBDao {
*
* @return The instance of PolicyDBDao or throws exception if the given instance is null.
* @throws IllegalStateException if a PolicyDBDao instance is null. Call createPolicyDBDaoInstance
- * (EntityManagerFactory emf) to get this.
+ * (EntityManagerFactory emf) to get this.
*/
public static PolicyDBDao getPolicyDBDaoInstance() {
logger.debug("getPolicyDBDaoInstance() as getPolicyDBDaoInstance() called");
@@ -179,7 +177,7 @@ public class PolicyDBDao {
logger.debug("PolicyDBDao(EntityManagerFactory emf) as PolicyDBDao(" + emf + ") called");
this.emf = emf;
- //not needed in this release
+ // not needed in this release
if (!register()) {
PolicyLogger
.error("This server's PolicyDBDao instance could not be registered and may not reveive updates");
@@ -194,8 +192,8 @@ public class PolicyDBDao {
}
}
- //not static because we are going to be using the instance's emf
- //waitTime in ms to wait for lock, or -1 to wait forever (no)
+ // not static because we are going to be using the instance's emf
+ // waitTime in ms to wait for lock, or -1 to wait forever (no)
private void startTransactionSynced(EntityManager entityMgr, int waitTime) {
logger.debug("\n\nstartTransactionSynced(EntityManager entityMgr,int waitTime) as "
+ "\n startTransactionSynced(" + entityMgr + "," + waitTime + ") called\n\n");
@@ -206,21 +204,16 @@ public class PolicyDBDao {
if (logger.isDebugEnabled()) {
Map<String, Object> properties = entityMgr.getProperties();
- logger.debug("\n\nstartTransactionSynced():"
- + "\n entityManager.getProperties() = " + properties
- + "\n\n");
+ logger.debug(
+ "\n\nstartTransactionSynced():" + "\n entityManager.getProperties() = " + properties + "\n\n");
}
try {
if (logger.isDebugEnabled()) {
- logger.debug("\n\nstartTransactionSynced():"
- + "\n ATTEMPT to get the DB lock"
- + "\n\n");
+ logger.debug("\n\nstartTransactionSynced():" + "\n ATTEMPT to get the DB lock" + "\n\n");
}
lock = entityMgr.find(DatabaseLockEntity.class, 1, LockModeType.PESSIMISTIC_WRITE);
if (logger.isDebugEnabled()) {
- logger.debug("\n\nstartTransactionSynced():"
- + "\n GOT the DB lock"
- + "\n\n");
+ logger.debug("\n\nstartTransactionSynced():" + "\n GOT the DB lock" + "\n\n");
}
} catch (Exception e) {
System.out.println("Could not get lock entity");
@@ -272,16 +265,15 @@ public class PolicyDBDao {
}
/*
- * Because the normal transactions are not used in audits, we can use the same transaction
- * mechanism to get a transaction and obtain the emlock and the DB lock. We just need to
- * provide different transaction timeout values in ms because the audit will run longer
- * than normal transactions.
+ * Because the normal transactions are not used in audits, we can use the same transaction mechanism to get a
+ * transaction and obtain the emlock and the DB lock. We just need to provide different transaction timeout values
+ * in ms because the audit will run longer than normal transactions.
*/
public PolicyDBDaoTransaction getNewAuditTransaction() {
logger.debug("getNewAuditTransaction() as getNewAuditTransaction() called");
- //Use the standard transaction wait time in ms
+ // Use the standard transaction wait time in ms
int auditWaitMs = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_WAIT));
- //Use the (extended) audit timeout time in ms
+ // Use the (extended) audit timeout time in ms
int auditTimeoutMs = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_AUDIT_TIMEOUT));
return new PolicyDBDaoTransactionInstance(auditTimeoutMs, auditWaitMs);
}
@@ -338,7 +330,7 @@ public class PolicyDBDao {
urlUserPass[2] = passwordPropertyValue;
}
}
- //if there is no comma, for some reason there is no username and password, so don't try to cut them off
+ // if there is no comma, for some reason there is no username and password, so don't try to cut them off
return urlUserPass;
}
@@ -350,7 +342,7 @@ public class PolicyDBDao {
private boolean register() {
logger.debug("register() as register() called");
String[] url = getPapUrlUserPass();
- //--- check URL length
+ // --- check URL length
if (url == null || url.length < 3) {
return false;
}
@@ -417,7 +409,7 @@ public class PolicyDBDao {
}
}
} else {
- //just want to update in order to change modified date
+ // just want to update in order to change modified date
if (url[1] != null && !stringEquals(url[1], foundPolicyDBDaoEntity.getUsername())) {
foundPolicyDBDaoEntity.setUsername(url[1]);
}
@@ -458,7 +450,7 @@ public class PolicyDBDao {
@Override
public void run() {
- //naming of 'o' is for backwards compatibility with the rest of the function
+ // naming of 'o' is for backwards compatibility with the rest of the function
PolicyDBDaoEntity dbdEntity = (PolicyDBDaoEntity) obj;
String o = dbdEntity.getPolicyDBDaoUrl();
String username = dbdEntity.getUsername();
@@ -467,7 +459,7 @@ public class PolicyDBDao {
txt = new String(CryptoUtils.decryptTxt(dbdEntity.getPassword()), StandardCharsets.UTF_8);
} catch (Exception e) {
logger.debug(e);
- //if we can't decrypt, might as well try it anyway
+ // if we can't decrypt, might as well try it anyway
txt = dbdEntity.getPassword();
}
Base64.Encoder encoder = Base64.getEncoder();
@@ -484,7 +476,7 @@ public class PolicyDBDao {
papUrl = papUrlUserPass[0];
}
logger.debug("We are going to try to notify " + o);
- //is this our own url?
+ // is this our own url?
String ourUrl = o;
try {
ourUrl = splitPapUrlUserPass((String) o)[0];
@@ -499,11 +491,11 @@ public class PolicyDBDao {
return;
}
if (newGroupId == null) {
- url = new URL(o + "?policydbdaourl=" + papUrl + "&entityid=" + entityId + "&entitytype=" +
- entityType);
+ url = new URL(
+ o + "?policydbdaourl=" + papUrl + "&entityid=" + entityId + "&entitytype=" + entityType);
} else {
- url = new URL(o + "?policydbdaourl=" + papUrl + "&entityid=" + entityId + "&entitytype=" +
- entityType + "&extradata=" + newGroupId);
+ url = new URL(o + "?policydbdaourl=" + papUrl + "&entityid=" + entityId + "&entitytype="
+ + entityType + "&extradata=" + newGroupId);
}
} catch (MalformedURLException e) {
logger.warn("Caught MalformedURLException on: new URL()", e);
@@ -526,7 +518,7 @@ public class PolicyDBDao {
try {
connection.setRequestMethod("PUT");
} catch (ProtocolException e) {
- //why would this error ever occur?
+ // why would this error ever occur?
logger.warn("Caught ProtocolException on connection.setRequestMethod(\"PUT\");", e);
return;
}
@@ -565,8 +557,8 @@ public class PolicyDBDao {
if (connection.getResponseCode() == 200) {
logger.info("PolicyDBDao: NotifyOtherThread received response 200 from pap server on notify");
} else {
- logger.warn("PolicyDBDao: NotifyOtherThread connection response code not 200, received: " +
- connection.getResponseCode());
+ logger.warn("PolicyDBDao: NotifyOtherThread connection response code not 200, received: "
+ + connection.getResponseCode());
}
} catch (Exception e) {
logger.warn("Caught Exception on: connection.getResponseCode() ", e);
@@ -600,19 +592,19 @@ public class PolicyDBDao {
private static final String GROUP_NOTIFICATION = "group";
public void handleIncomingHttpNotification(String url, String entityId, String entityType, String extraData,
- XACMLPapServlet xacmlPapServlet) {
+ XACMLPapServlet xacmlPapServlet) {
logger.info("DBDao url: " + url + " has reported an update on " + entityType + " entity " + entityId);
PolicyDBDaoTransaction transaction = this.getNewTransaction();
- //although its named retries, this is the total number of tries
+ // although its named retries, this is the total number of tries
int retries;
try {
- retries = Integer.parseInt(
- XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_INCOMINGNOTIFICATION_TRIES));
+ retries = Integer
+ .parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_INCOMINGNOTIFICATION_TRIES));
} catch (Exception e) {
logger.error("xacml.rest.pap.incomingnotification.tries property not set, using a default of 3." + e);
retries = 3;
}
- //if someone sets it to some dumb value, we need to make sure it will try at least once
+ // if someone sets it to some dumb value, we need to make sure it will try at least once
if (retries < 1) {
retries = 1;
}
@@ -627,8 +619,8 @@ public class PolicyDBDao {
} catch (Exception e) {
logger.debug(e);
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught exception on handleIncomingPolicyChange(" + url + ", " + entityId + ", " +
- extraData + ")");
+ "Caught exception on handleIncomingPolicyChange(" + url + ", " + entityId + ", "
+ + extraData + ")");
}
try {
Thread.sleep(pauseBetweenRetries);
@@ -646,8 +638,8 @@ public class PolicyDBDao {
} catch (Exception e) {
logger.debug(e);
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught exception on handleIncomingPdpChange(" + url + ", " + entityId + ", " +
- transaction + ")");
+ "Caught exception on handleIncomingPdpChange(" + url + ", " + entityId + ", "
+ + transaction + ")");
}
try {
Thread.sleep(pauseBetweenRetries);
@@ -665,8 +657,8 @@ public class PolicyDBDao {
} catch (Exception e) {
logger.debug(e);
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught exception on handleIncomingGroupChange(" + url + ", " + entityId + ", " +
- extraData + ", " + transaction + ", " + xacmlPapServlet + ")");
+ "Caught exception on handleIncomingGroupChange(" + url + ", " + entityId + ", "
+ + extraData + ", " + transaction + ", " + xacmlPapServlet + ")");
}
try {
Thread.sleep(pauseBetweenRetries);
@@ -677,7 +669,7 @@ public class PolicyDBDao {
}
break;
}
- //no changes should be being made in this function, we still need to close
+ // no changes should be being made in this function, we still need to close
transaction.rollbackTransaction();
}
@@ -700,8 +692,8 @@ public class PolicyDBDao {
if (groupRecord == null) {
throw new PersistenceException("The group record returned is null");
}
- //compare to local fs
- //does group folder exist
+ // compare to local fs
+ // does group folder exist
OnapPDPGroup localGroup = null;
try {
localGroup = papEngine.getGroup(groupRecord.getGroupId());
@@ -710,7 +702,7 @@ public class PolicyDBDao {
e);
}
if (localGroup == null && extraData != null) {
- //here we can try to load an old group id from the extraData
+ // here we can try to load an old group id from the extraData
try {
localGroup = papEngine.getGroup(extraData);
} catch (Exception e) {
@@ -726,37 +718,37 @@ public class PolicyDBDao {
newLocalGroup = papEngine.getGroup(extraData);
} catch (PAPException e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught PAPException trying to get new pdp group with papEngine.getGroup(" + extraData +
- ");");
+ "Caught PAPException trying to get new pdp group with papEngine.getGroup(" + extraData
+ + ");");
}
}
try {
papEngine.removeGroup(localGroup, newLocalGroup);
} catch (NullPointerException | PAPException e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught PAPException trying to get remove pdp group with papEngine.removeGroup(" + localGroup +
- ", " + newLocalGroup + ");");
+ "Caught PAPException trying to get remove pdp group with papEngine.removeGroup(" + localGroup
+ + ", " + newLocalGroup + ");");
throw new PAPException("Could not remove group " + groupId);
}
} else if (localGroup == null) {
- //creating a new group
+ // creating a new group
try {
papEngine.newGroup(groupRecord.getgroupName(), groupRecord.getDescription());
} catch (NullPointerException | PAPException e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught PAPException trying to create pdp group with papEngine.newGroup(groupRecord" +
- ".getgroupName(), groupRecord.getDescription());");
+ "Caught PAPException trying to create pdp group with papEngine.newGroup(groupRecord"
+ + ".getgroupName(), groupRecord.getDescription());");
throw new PAPException("Could not create group " + groupRecord);
}
try {
localGroup = papEngine.getGroup(groupRecord.getGroupId());
} catch (PAPException e1) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, policyDBDaoVar,
- "Caught PAPException trying to get pdp group we just created with papEngine.getGroup" +
- "(groupRecord.getGroupId());\nAny PDPs or policies in the new group may not have been added");
+ "Caught PAPException trying to get pdp group we just created with papEngine.getGroup"
+ + "(groupRecord.getGroupId());\nAny PDPs or policies in the new group may not have been added");
return;
}
- //add possible pdps to group
+ // add possible pdps to group
List<?> pdpsInGroup = transaction.getPdpsInGroup(Long.parseLong(groupRecord.getGroupId()));
for (Object pdpO : pdpsInGroup) {
PdpEntity pdp = (PdpEntity) pdpO;
@@ -765,34 +757,33 @@ public class PolicyDBDao {
pdp.getJmxPort());
} catch (NullPointerException | PAPException e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught PAPException trying to get create pdp with papEngine.newPDP(pdp.getPdpId(), " +
- "localGroup, pdp.getPdpName(), pdp.getDescription(), pdp.getJmxPort());");
+ "Caught PAPException trying to get create pdp with papEngine.newPDP(pdp.getPdpId(), "
+ + "localGroup, pdp.getPdpName(), pdp.getDescription(), pdp.getJmxPort());");
throw new PAPException("Could not create pdp " + pdp);
}
}
- //add possible policies to group (filesystem only, apparently)
+ // add possible policies to group (filesystem only, apparently)
} else {
if (!(localGroup instanceof StdPDPGroup)) {
throw new PAPException("group is not a StdPDPGroup");
}
- //clone the object
- //because it will be comparing the new group to its own version
- StdPDPGroup localGroupClone =
- new StdPDPGroup(localGroup.getId(), localGroup.isDefaultGroup(), localGroup.getName(),
- localGroup.getDescription(), ((StdPDPGroup) localGroup).getDirectory());
+ // clone the object
+ // because it will be comparing the new group to its own version
+ StdPDPGroup localGroupClone = new StdPDPGroup(localGroup.getId(), localGroup.isDefaultGroup(),
+ localGroup.getName(), localGroup.getDescription(), ((StdPDPGroup) localGroup).getDirectory());
localGroupClone.setOnapPdps(localGroup.getOnapPdps());
localGroupClone.setPipConfigs(localGroup.getPipConfigs());
localGroupClone.setStatus(localGroup.getStatus());
- //we are updating a group or adding a policy or changing default
- //set default if it should be
+ // we are updating a group or adding a policy or changing default
+ // set default if it should be
if (!localGroupClone.isDefaultGroup() && groupRecord.isDefaultGroup()) {
try {
papEngine.setDefaultGroup(localGroup);
return;
} catch (PAPException e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught PAPException trying to set default group with papEngine.SetDefaultGroup(" +
- localGroupClone + ");");
+ "Caught PAPException trying to set default group with papEngine.SetDefaultGroup("
+ + localGroupClone + ");");
throw new PAPException("Could not set default group to " + localGroupClone);
}
}
@@ -800,10 +791,10 @@ public class PolicyDBDao {
if (updateGroupPoliciesInFileSystem(localGroupClone, localGroup, groupRecord, transaction)) {
needToUpdate = true;
}
- if (!stringEquals(localGroupClone.getId(), groupRecord.getGroupId()) ||
- !stringEquals(localGroupClone.getName(), groupRecord.getgroupName())) {
- //changing ids
- //we do not want to change the id, the papEngine will do this for us, it needs to know the old id
+ if (!stringEquals(localGroupClone.getId(), groupRecord.getGroupId())
+ || !stringEquals(localGroupClone.getName(), groupRecord.getgroupName())) {
+ // changing ids
+ // we do not want to change the id, the papEngine will do this for us, it needs to know the old id
localGroupClone.setName(groupRecord.getgroupName());
needToUpdate = true;
}
@@ -816,24 +807,23 @@ public class PolicyDBDao {
papEngine.updateGroup(localGroupClone);
} catch (PAPException e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught PAPException trying to update group with papEngine.updateGroup(" + localGroupClone +
- ");");
+ "Caught PAPException trying to update group with papEngine.updateGroup(" + localGroupClone
+ + ");");
throw new PAPException("Could not update group " + localGroupClone);
}
}
}
}
- //this will also handle removes, since incoming pdpGroup has no policies internally, we are just going to add
+ // this will also handle removes, since incoming pdpGroup has no policies internally, we are just going to add
// them all in from the db
private boolean updateGroupPoliciesInFileSystem(OnapPDPGroup pdpGroup, OnapPDPGroup oldPdpGroup,
- GroupEntity groupRecord, PolicyDBDaoTransaction transaction)
- throws PAPException, PolicyDBException {
+ GroupEntity groupRecord, PolicyDBDaoTransaction transaction) throws PAPException, PolicyDBException {
if (!(pdpGroup instanceof StdPDPGroup)) {
throw new PAPException("group is not a StdPDPGroup");
}
StdPDPGroup group = (StdPDPGroup) pdpGroup;
- //this must always be true since we don't explicitly know when a delete is occuring
+ // this must always be true since we don't explicitly know when a delete is occuring
boolean didUpdate = true;
HashMap<String, PDPPolicy> currentPolicySet = new HashMap<>(oldPdpGroup.getPolicies().size());
HashSet<PDPPolicy> newPolicySet = new HashSet<>();
@@ -871,8 +861,8 @@ public class PolicyDBDao {
}
/*
- * This method is called during all pushPolicy transactions and makes sure the file system
- * group is in sync with the database groupentity
+ * This method is called during all pushPolicy transactions and makes sure the file system group is in sync with the
+ * database groupentity
*/
private StdPDPGroup synchronizeGroupPoliciesInFileSystem(StdPDPGroup pdpGroup, GroupEntity groupentity)
throws PAPException, PolicyDBException {
@@ -892,7 +882,7 @@ public class PolicyDBDao {
if (currentPolicyMap.containsKey(pdpPolicyId)) {
newPolicySet.add(currentPolicyMap.get(pdpPolicyId));
} else {
- //convert PolicyEntity object to PDPPolicy
+ // convert PolicyEntity object to PDPPolicy
String name = pdpPolicyId.replace(".xml", "");
name = name.substring(0, name.lastIndexOf('.'));
InputStream policyStream = new ByteArrayInputStream(policy.getPolicyData().getBytes());
@@ -900,15 +890,14 @@ public class PolicyDBDao {
URI location = Paths.get(pdpGroup.getDirectory().toAbsolutePath().toString(), pdpPolicyId).toUri();
StdPDPPolicy newPolicy = null;
try {
- newPolicy =
- new StdPDPPolicy(pdpPolicyId, true, removeExtensionAndVersionFromPolicyName(pdpPolicyId),
- location);
+ newPolicy = new StdPDPPolicy(pdpPolicyId, true,
+ removeExtensionAndVersionFromPolicyName(pdpPolicyId), location);
newPolicySet.add(newPolicy);
} catch (Exception e) {
logger.debug(e);
PolicyLogger
- .error("PolicyDBDao: Exception occurred while creating the StdPDPPolicy newPolicy object " +
- e.getMessage());
+ .error("PolicyDBDao: Exception occurred while creating the StdPDPPolicy newPolicy object "
+ + e.getMessage());
}
}
}
@@ -920,9 +909,8 @@ public class PolicyDBDao {
} catch (Exception e) {
logger.debug(e);
PolicyLogger
- .error("PolicyDBDao: Exception occurred while attempting to delete the old version of the" +
- " policy file from the group. " +
- e.getMessage());
+ .error("PolicyDBDao: Exception occurred while attempting to delete the old version of the"
+ + " policy file from the group. " + e.getMessage());
}
}
}
@@ -969,7 +957,7 @@ public class PolicyDBDao {
}
private void handleIncomingPdpChange(String pdpId, PolicyDBDaoTransaction transaction) throws PAPException {
- //get pdp
+ // get pdp
long pdpIdLong = -1;
try {
pdpIdLong = Long.parseLong(pdpId);
@@ -1002,15 +990,15 @@ public class PolicyDBDao {
throw new PAPException("Could not remove pdp " + pdpId);
}
} else if (localPdp == null) {
- //add new pdp
- //get group
+ // add new pdp
+ // get group
OnapPDPGroup localGroup = null;
try {
localGroup = papEngine.getGroup(pdpRecord.getGroup().getGroupId());
} catch (PAPException e1) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, policyDBDaoVar,
- "Caught PAPException trying to get local group to add pdp to with papEngine.getGroup" +
- "(pdpRecord.getGroup().getGroupId());");
+ "Caught PAPException trying to get local group to add pdp to with papEngine.getGroup"
+ + "(pdpRecord.getGroup().getGroupId());");
throw new PAPException("Could not get local group");
}
try {
@@ -1018,16 +1006,16 @@ public class PolicyDBDao {
pdpRecord.getJmxPort());
} catch (NullPointerException | PAPException e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught PAPException trying to create pdp with papEngine.newPDP(" + pdpRecord.getPdpId() +
- ", " + localGroup + ", " + pdpRecord.getPdpName() + ", " + pdpRecord.getDescription() +
- ", " + pdpRecord.getJmxPort() + ");");
+ "Caught PAPException trying to create pdp with papEngine.newPDP(" + pdpRecord.getPdpId() + ", "
+ + localGroup + ", " + pdpRecord.getPdpName() + ", " + pdpRecord.getDescription() + ", "
+ + pdpRecord.getJmxPort() + ");");
throw new PAPException("Could not create pdp " + pdpRecord);
}
} else {
boolean needToUpdate = false;
- if (!stringEquals(localPdp.getId(), pdpRecord.getPdpId()) ||
- !stringEquals(localPdp.getName(), pdpRecord.getPdpName())) {
- //again, we don't want to change the id, the papEngine will do this
+ if (!stringEquals(localPdp.getId(), pdpRecord.getPdpId())
+ || !stringEquals(localPdp.getName(), pdpRecord.getPdpName())) {
+ // again, we don't want to change the id, the papEngine will do this
localPdp.setName(pdpRecord.getPdpName());
needToUpdate = true;
}
@@ -1039,21 +1027,19 @@ public class PolicyDBDao {
try {
localPdpGroupId = papEngine.getPDPGroup((OnapPDP) localPdp).getId();
} catch (PAPException e) {
- //could be null or something, just warn at this point
- logger.warn(
- "Caught PAPException trying to get id of local group that pdp is in with localPdpGroupId = " +
- "papEngine.getPDPGroup(localPdp).getId();",
- e);
+ // could be null or something, just warn at this point
+ logger.warn("Caught PAPException trying to get id of local group that pdp is in with localPdpGroupId = "
+ + "papEngine.getPDPGroup(localPdp).getId();", e);
}
if (!stringEquals(localPdpGroupId, pdpRecord.getGroup().getGroupId())) {
OnapPDPGroup newPdpGroup = null;
try {
newPdpGroup = papEngine.getGroup(pdpRecord.getGroup().getGroupId());
} catch (PAPException e) {
- //ok, now we have an issue. Time to stop things
+ // ok, now we have an issue. Time to stop things
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught PAPException trying to get id of local group to move pdp to with papEngine" +
- ".getGroup(pdpRecord.getGroup().getGroupId());");
+ "Caught PAPException trying to get id of local group to move pdp to with papEngine"
+ + ".getGroup(pdpRecord.getGroup().getGroupId());");
throw new PAPException("Could not get local group");
}
try {
@@ -1078,8 +1064,8 @@ public class PolicyDBDao {
}
}
}
- //compare to local situation
- //call command to update
+ // compare to local situation
+ // call command to update
}
private void handleIncomingPolicyChange(String policyId) {
@@ -1160,8 +1146,8 @@ public class PolicyDBDao {
}
private boolean writePolicySubFile(PolicyEntity policy, String policyType) {
- logger.info("writePolicySubFile with policyName[" + policy.getPolicyName() + "] and policyType[" + policyType +
- "]");
+ logger.info("writePolicySubFile with policyName[" + policy.getPolicyName() + "] and policyType[" + policyType
+ + "]");
String type = null;
String subTypeName = null;
String subTypeBody = null;
@@ -1361,14 +1347,13 @@ public class PolicyDBDao {
return getConfigFile(filename, policy.getConfigType());
}
- //copied from ConfigPolicy.java and modified
+ // copied from ConfigPolicy.java and modified
// Here we are adding the extension for the configurations file based on the
// config type selection for saving.
private String getConfigFile(String inputFilename, String configType) {
String filename = inputFilename;
- logger.debug(
- "getConfigFile(String filename, String scope, String configType) as getConfigFile(" + filename + ", " +
- configType + ") called");
+ logger.debug("getConfigFile(String filename, String scope, String configType) as getConfigFile(" + filename
+ + ", " + configType + ") called");
filename = FilenameUtils.removeExtension(filename);
String id = configType;
@@ -1396,12 +1381,12 @@ public class PolicyDBDao {
}
String policyName = splitByDots[splitByDots.length - 3];
String version = splitByDots[splitByDots.length - 2];
- //policy names now include version
+ // policy names now include version
String scope = "";
for (int i = 0; i < splitByDots.length - 3; i++) {
scope += ".".concat(splitByDots[i]);
}
- //remove the first dot
+ // remove the first dot
if (scope.length() > 0) {
scope = scope.substring(1);
}
@@ -1460,18 +1445,18 @@ public class PolicyDBDao {
private final Thread transactionTimer;
private PolicyDBDaoTransactionInstance() {
- //call the constructor with arguments
+ // call the constructor with arguments
this(Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT)),
Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_WAIT)));
}
- //timeout is how long the transaction can sit before rolling back
- //wait time is how long to wait for the transaction to start before throwing an exception
+ // timeout is how long the transaction can sit before rolling back
+ // wait time is how long to wait for the transaction to start before throwing an exception
private PolicyDBDaoTransactionInstance(int transactionTimeout, int transactionWaitTime) {
if (logger.isDebugEnabled()) {
logger.debug("\n\nPolicyDBDaoTransactionInstance() as PolicyDBDaoTransactionInstance() called:"
- + "\n transactionTimeout = " + transactionTimeout
- + "\n transactionWaitTime = " + transactionWaitTime + "\n\n");
+ + "\n transactionTimeout = " + transactionTimeout + "\n transactionWaitTime = "
+ + transactionWaitTime + "\n\n");
}
this.em = emf.createEntityManager();
policyId = -1;
@@ -1499,29 +1484,25 @@ public class PolicyDBDao {
public void run() {
if (logger.isDebugEnabled()) {
Date date = new java.util.Date();
- logger.debug("\n\nTransactionTimer.run() - SLEEPING: "
- + "\n sleepTime (ms) = " + sleepTime
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
+ logger.debug("\n\nTransactionTimer.run() - SLEEPING: " + "\n sleepTime (ms) = " + sleepTime
+ + "\n TimeStamp = " + date.getTime() + "\n\n");
}
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
- //probably, the transaction was completed, the last thing we want to do is roll back
+ // probably, the transaction was completed, the last thing we want to do is roll back
if (logger.isDebugEnabled()) {
Date date = new java.util.Date();
- logger.debug("\n\nTransactionTimer.run() - WAKE Interrupt: "
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
+ logger.debug("\n\nTransactionTimer.run() - WAKE Interrupt: " + "\n TimeStamp = "
+ + date.getTime() + "\n\n");
}
Thread.currentThread().interrupt();
return;
}
if (logger.isDebugEnabled()) {
Date date = new java.util.Date();
- logger.debug("\n\nTransactionTimer.run() - WAKE Timeout: "
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
+ logger.debug("\n\nTransactionTimer.run() - WAKE Timeout: " + "\n TimeStamp = "
+ + date.getTime() + "\n\n");
}
rollbackTransaction();
}
@@ -1544,9 +1525,8 @@ public class PolicyDBDao {
throw new IllegalStateException("There is no transaction currently open");
}
if (operationRun && !justCheckOpen) {
- PolicyLogger
- .error("An operation has already been performed and the current transaction should be " +
- "committed");
+ PolicyLogger.error(
+ "An operation has already been performed and the current transaction should be " + "committed");
throw new IllegalStateException(
"An operation has already been performed and the current transaction should be committed");
}
@@ -1581,8 +1561,8 @@ public class PolicyDBDao {
notifyOthers(policyId, POLICY_NOTIFICATION, newGroupId);
} catch (Exception e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught Exception on notifyOthers(" + policyId + "," + POLICY_NOTIFICATION + "," +
- newGroupId + ")");
+ "Caught Exception on notifyOthers(" + policyId + "," + POLICY_NOTIFICATION + ","
+ + newGroupId + ")");
}
} else {
try {
@@ -1594,14 +1574,14 @@ public class PolicyDBDao {
}
}
if (groupId >= 0) {
- //we don't want commit to fail just because this does
+ // we don't want commit to fail just because this does
if (newGroupId != null) {
try {
notifyOthers(groupId, GROUP_NOTIFICATION, newGroupId);
} catch (Exception e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught Exception on notifyOthers(" + groupId + "," + GROUP_NOTIFICATION + "," +
- newGroupId + ")");
+ "Caught Exception on notifyOthers(" + groupId + "," + GROUP_NOTIFICATION + ","
+ + newGroupId + ")");
}
} else {
try {
@@ -1613,7 +1593,7 @@ public class PolicyDBDao {
}
}
if (pdpId >= 0) {
- //we don't want commit to fail just because this does
+ // we don't want commit to fail just because this does
try {
notifyOthers(pdpId, PDP_NOTIFICATION);
} catch (Exception e) {
@@ -1661,13 +1641,12 @@ public class PolicyDBDao {
}
private void createPolicy(PolicyRestAdapter policy, String username, String policyScope, String inputPolicyName,
- String policyDataString) {
+ String policyDataString) {
String policyName = inputPolicyName;
logger.debug(
- "createPolicy(PolicyRestAdapter policy, String username, String policyScope, String policyName, " +
- "String policyDataString) as createPolicy(" +
- policy + ", " + username + ", " + policyScope + ", " + policyName + ", " +
- policyDataString + ") called");
+ "createPolicy(PolicyRestAdapter policy, String username, String policyScope, String policyName, "
+ + "String policyDataString) as createPolicy(" + policy + ", " + username + ", "
+ + policyScope + ", " + policyName + ", " + policyDataString + ") called");
synchronized (emLock) {
checkBeforeOperationRun();
String configName = policyName;
@@ -1679,8 +1658,8 @@ public class PolicyDBDao {
policyName = policyName.replace(".Decision_", ":Decision_");
}
policyName = policyName.split(":")[1];
- Query createPolicyQuery = em.createQuery(
- "SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:policyName");
+ Query createPolicyQuery = em
+ .createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:policyName");
createPolicyQuery.setParameter(scope, policyScope);
createPolicyQuery.setParameter("policyName", policyName);
List<?> createPolicyQueryList = createPolicyQuery.getResultList();
@@ -1691,11 +1670,11 @@ public class PolicyDBDao {
update = false;
} else if (createPolicyQueryList.size() > 1) {
PolicyLogger
- .error("Somehow, more than one policy with the same scope, name, and deleted status were " +
- "found in the database");
+ .error("Somehow, more than one policy with the same scope, name, and deleted status were "
+ + "found in the database");
throw new PersistenceException(
- "Somehow, more than one policy with the same scope, name, and deleted status were found " +
- "in the database");
+ "Somehow, more than one policy with the same scope, name, and deleted status were found "
+ + "in the database");
} else {
newPolicyEntity = (PolicyEntity) createPolicyQueryList.get(0);
update = true;
@@ -1716,12 +1695,12 @@ public class PolicyDBDao {
if (!abupdate) {
em.persist(newActionBodyEntity);
}
- //build the file path
- //trim the .xml off the end
+ // build the file path
+ // trim the .xml off the end
String policyNameClean = FilenameUtils.removeExtension(configName);
String actionBodyName = policyNameClean + ".json";
- //get the action body
+ // get the action body
String actionBodyString = policy.getActionBody();
if (actionBodyString == null) {
actionBodyString = "{}";
@@ -1734,30 +1713,26 @@ public class PolicyDBDao {
newActionBodyEntity.setCreatedBy("PolicyDBDao.createPolicy()");
}
if (logger.isDebugEnabled()) {
- logger.debug("\nPolicyDBDao.createPolicy"
- + "\n newActionBodyEntity.getActionBody() = " +
- newActionBodyEntity.getActionBody()
- + "\n newActionBodyEntity.getActionBodyName() = " +
- newActionBodyEntity.getActionBodyName()
- + "\n newActionBodyEntity.getModifiedBy() = " +
- newActionBodyEntity.getModifiedBy()
- + "\n newActionBodyEntity.getCreatedBy() = " + newActionBodyEntity.getCreatedBy()
- + "\n newActionBodyEntity.isDeleted() = " + newActionBodyEntity.isDeleted()
- + "\n FLUSHING to DB");
+ logger.debug("\nPolicyDBDao.createPolicy" + "\n newActionBodyEntity.getActionBody() = "
+ + newActionBodyEntity.getActionBody()
+ + "\n newActionBodyEntity.getActionBodyName() = "
+ + newActionBodyEntity.getActionBodyName()
+ + "\n newActionBodyEntity.getModifiedBy() = "
+ + newActionBodyEntity.getModifiedBy() + "\n newActionBodyEntity.getCreatedBy() = "
+ + newActionBodyEntity.getCreatedBy() + "\n newActionBodyEntity.isDeleted() = "
+ + newActionBodyEntity.isDeleted() + "\n FLUSHING to DB");
}
- //push the actionBodyEntity to the DB
+ // push the actionBodyEntity to the DB
em.flush();
} else {
- //newActionBodyEntity == null
- //We have a actionBody in the policy but we found no actionBody in the DB
+ // newActionBodyEntity == null
+ // We have a actionBody in the policy but we found no actionBody in the DB
String msg = "\n\nPolicyDBDao.createPolicy - Incoming Action policy had an "
- + "actionBody, but it could not be found in the DB for update."
- + "\n policyScope = " + policyScope
- + "\n policyName = " + policyName + "\n\n";
+ + "actionBody, but it could not be found in the DB for update." + "\n policyScope = "
+ + policyScope + "\n policyName = " + policyName + "\n\n";
PolicyLogger
- .error("PolicyDBDao.createPolicy - Incoming Action policy had an actionBody, but it " +
- "could not be found in the DB for update: policyName = " +
- policyName);
+ .error("PolicyDBDao.createPolicy - Incoming Action policy had an actionBody, but it "
+ + "could not be found in the DB for update: policyName = " + policyName);
throw new IllegalArgumentException(msg);
}
}
@@ -1782,25 +1757,25 @@ public class PolicyDBDao {
getConfigFile(configName, policy))) {
newConfigurationDataEntity.setConfigurationName(getConfigFile(configName, policy));
}
- if (newConfigurationDataEntity.getConfigType() == null ||
- !newConfigurationDataEntity.getConfigType().equals(policy.getConfigType())) {
+ if (newConfigurationDataEntity.getConfigType() == null
+ || !newConfigurationDataEntity.getConfigType().equals(policy.getConfigType())) {
newConfigurationDataEntity.setConfigType(policy.getConfigType());
}
if (!configUpdate) {
newConfigurationDataEntity.setCreatedBy(username);
}
- if (newConfigurationDataEntity.getModifiedBy() == null ||
- !newConfigurationDataEntity.getModifiedBy().equals(username)) {
+ if (newConfigurationDataEntity.getModifiedBy() == null
+ || !newConfigurationDataEntity.getModifiedBy().equals(username)) {
newConfigurationDataEntity.setModifiedBy(username);
}
- if (newConfigurationDataEntity.getDescription() == null ||
- !newConfigurationDataEntity.getDescription().equals("")) {
+ if (newConfigurationDataEntity.getDescription() == null
+ || !newConfigurationDataEntity.getDescription().equals("")) {
newConfigurationDataEntity.setDescription("");
}
- if (newConfigurationDataEntity.getConfigBody() == null ||
- newConfigurationDataEntity.getConfigBody().isEmpty() ||
- (!newConfigurationDataEntity.getConfigBody().equals(policy.getConfigBodyData()))) {
- //hopefully one of these won't be null
+ if (newConfigurationDataEntity.getConfigBody() == null
+ || newConfigurationDataEntity.getConfigBody().isEmpty()
+ || (!newConfigurationDataEntity.getConfigBody().equals(policy.getConfigBodyData()))) {
+ // hopefully one of these won't be null
if (policy.getConfigBodyData() == null || policy.getConfigBodyData().isEmpty()) {
newConfigurationDataEntity.setConfigBody(policy.getJsonBody());
} else {
@@ -1813,16 +1788,13 @@ public class PolicyDBDao {
em.flush();
} else {
- //We have a configurationData body in the policy but we found no configurationData body in
+ // We have a configurationData body in the policy but we found no configurationData body in
// the DB
String msg = "\n\nPolicyDBDao.createPolicy - Incoming Config policy had a "
+ "configurationData body, but it could not be found in the DB for update."
- + "\n policyScope = " + policyScope
- + "\n policyName = " + policyName + "\n\n";
- PolicyLogger
- .error("PolicyDBDao.createPolicy - Incoming Config policy had a configurationData " +
- "body, but it could not be found in the DB for update: policyName = " +
- policyName);
+ + "\n policyScope = " + policyScope + "\n policyName = " + policyName + "\n\n";
+ PolicyLogger.error("PolicyDBDao.createPolicy - Incoming Config policy had a configurationData "
+ + "body, but it could not be found in the DB for update: policyName = " + policyName);
throw new IllegalArgumentException(msg);
}
@@ -1874,8 +1846,8 @@ public class PolicyDBDao {
}
private PolicyEntity getPolicy(int policyID, String policyName, String scope) {
- logger.debug("getPolicy(int policyId, String policyName) as getPolicy(" + policyID + "," + policyName +
- ") called");
+ logger.debug("getPolicy(int policyId, String policyName) as getPolicy(" + policyID + "," + policyName
+ + ") called");
if (policyID < 0 && isNullOrEmpty(policyName, scope)) {
throw new IllegalArgumentException(
"policyID must be at least 0 or policyName must be not null or blank");
@@ -1883,7 +1855,7 @@ public class PolicyDBDao {
synchronized (emLock) {
checkBeforeOperationRun(true);
- //check if group exists
+ // check if group exists
String policyId;
Query policyQuery;
if (!isNullOrEmpty(policyName, scope)) {
@@ -1924,7 +1896,7 @@ public class PolicyDBDao {
}
synchronized (emLock) {
checkBeforeOperationRun(true);
- //check if group exists
+ // check if group exists
Query groupQuery = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupKey=:groupKey");
groupQuery.setParameter("groupKey", groupKey);
List<?> groupQueryList;
@@ -1955,7 +1927,7 @@ public class PolicyDBDao {
}
synchronized (emLock) {
checkBeforeOperationRun(true);
- //check if group exists
+ // check if group exists
Query groupQuery = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId");
groupQuery.setParameter(groupIdVar, groupId);
List<?> groupQueryList;
@@ -1999,7 +1971,7 @@ public class PolicyDBDao {
}
synchronized (emLock) {
checkBeforeOperationRun(true);
- //check if group exists
+ // check if group exists
Query pdpQuery = em.createQuery("SELECT p FROM PdpEntity p WHERE p.pdpKey=:pdpKey");
pdpQuery.setParameter("pdpKey", pdpKey);
List<?> pdpQueryList;
@@ -2037,7 +2009,7 @@ public class PolicyDBDao {
throw new IllegalArgumentException("Webapps property does not exist");
}
configPath = configPath.replace("$URL", webappsPath);
- //make sure the correct slashes are in
+ // make sure the correct slashes are in
try {
configPath = Paths.get(configPath).toString();
} catch (InvalidPathException e) {
@@ -2068,37 +2040,37 @@ public class PolicyDBDao {
public void createPolicy(Policy policy, String username) {
try {
- logger.debug("createPolicy(PolicyRestAdapter policy, String username) as createPolicy(" + policy + "," +
- username + ") called");
+ logger.debug("createPolicy(PolicyRestAdapter policy, String username) as createPolicy(" + policy + ","
+ + username + ") called");
String policyScope = policy.policyAdapter.getDomainDir().replace(File.separator, ".");
- //Does not need to be XACMLPolicyWriterWithPapNotify since it is already in the PAP
- //and this transaction is intercepted up stream.
+ // Does not need to be XACMLPolicyWriterWithPapNotify since it is already in the PAP
+ // and this transaction is intercepted up stream.
- String policyDataString = getPolicyDataString((PolicyType) policy.getCorrectPolicyDataObject());
+ String policyDataString = getPolicyDataString(policy);
if (isJunit) {
- //Using parentPath object to set policy data.
+ // Using parentPath object to set policy data.
policyDataString = policy.policyAdapter.getParentPath();
}
String configPath = "";
if (policy.policyAdapter.getPolicyType().equalsIgnoreCase(config)) {
configPath = evaluateXPath(
- "/Policy/Rule/AdviceExpressions/AdviceExpression[contains(@AdviceId,'ID')" +
- "]/AttributeAssignmentExpression[@AttributeId='URLID']/AttributeValue/text()",
+ "/Policy/Rule/AdviceExpressions/AdviceExpression[contains(@AdviceId,'ID')"
+ + "]/AttributeAssignmentExpression[@AttributeId='URLID']/AttributeValue/text()",
policyDataString);
} else if (policy.policyAdapter.getPolicyType().equalsIgnoreCase(action)) {
configPath = evaluateXPath(
- "/Policy/Rule/ObligationExpressions/ObligationExpression[contains(@ObligationId, " +
- policy.policyAdapter.getActionAttribute() +
- ")]/AttributeAssignmentExpression[@AttributeId='body']/AttributeValue/text()",
+ "/Policy/Rule/ObligationExpressions/ObligationExpression[contains(@ObligationId, "
+ + policy.policyAdapter.getActionAttribute()
+ + ")]/AttributeAssignmentExpression[@AttributeId='body']/AttributeValue/text()",
policyDataString);
}
String prefix = null;
if (policy.policyAdapter.getPolicyType().equalsIgnoreCase(config)) {
- prefix = configPath
- .substring(configPath.indexOf(policyScope + ".") + policyScope.concat(".").length(),
- configPath.lastIndexOf(policy.policyAdapter.getPolicyName()));
+ prefix = configPath.substring(
+ configPath.indexOf(policyScope + ".") + policyScope.concat(".").length(),
+ configPath.lastIndexOf(policy.policyAdapter.getPolicyName()));
if (isNullOrEmpty(policy.policyAdapter.getConfigBodyData())) {
policy.policyAdapter.setConfigBodyData(getConfigData(configPath));
}
@@ -2108,18 +2080,19 @@ public class PolicyDBDao {
prefix = "Decision_";
}
- if (!(policy.policyAdapter.getData() instanceof PolicyType)) {
- PolicyLogger.error("The data field is not an instance of PolicyType");
- throw new IllegalArgumentException("The data field is not an instance of PolicyType");
+ if (!(policy.policyAdapter.getData() instanceof PolicyType)
+ && !(policy.policyAdapter.getData() instanceof PolicySetType)) {
+ PolicyLogger.error("The data field is not an instance of PolicyType or PolicySetType");
+ throw new IllegalArgumentException(
+ "The data field is not an instance of PolicyType or PolicySetType");
}
- String finalName = policyScope + "." + prefix + policy.policyAdapter.getPolicyName() + "." +
- ((PolicyType) policy.policyAdapter.getData()).getVersion() + ".xml";
+ String finalName = policyScope + "." + prefix + policy.policyAdapter.getPolicyName() + "."
+ + policy.policyAdapter.getHighestVersion() + ".xml";
if (policy.policyAdapter.getConfigType() == null || "".equals(policy.policyAdapter.getConfigType())) {
- //get the config file extension
+ // get the config file extension
String ext = "";
if (configPath != null && !"".equalsIgnoreCase(configPath)) {
- ext = configPath.substring(configPath.lastIndexOf('.'), configPath.length());
- ;
+ ext = configPath.substring(configPath.lastIndexOf('.'), configPath.length());;
}
if (ext.contains("txt")) {
@@ -2163,13 +2136,19 @@ public class PolicyDBDao {
return "";
}
- private String getPolicyDataString(PolicyType policyType) {
- try (InputStream policyXmlStream = XACMLPolicyWriter.getXmlAsInputStream(policyType)) {
- return IOUtils.toString(policyXmlStream, StandardCharsets.UTF_8);
+
+ /**
+ * @param policy input policy Object.
+ * @return read the stream and return policy xml data.
+ */
+ private String getPolicyDataString(Policy policy) {
+ try (InputStream policyXmlStream =
+ XACMLPolicyWriter.getXmlAsInputStream(policy.getCorrectPolicyDataObject())) {
+ return IOUtils.toString(policyXmlStream);
} catch (IOException e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught IOException on IOUtils.toString(policyXmlStream)");
- throw new IllegalArgumentException("Cannot parse the policy xml from the PolicyRestAdapter.", e);
+ "Caught IOException on reading Policy Data.");
+ throw new IllegalArgumentException("Cannot parse the policy xml from the PolicyRestAdapter.");
}
}
@@ -2191,8 +2170,8 @@ public class PolicyDBDao {
@Override
public void createGroup(String groupId, String groupName, String inputGroupDescription, String username) {
String groupDescription = inputGroupDescription;
- logger.debug("deletePolicy(String policyToDeletes) as createGroup(" + groupId + ", " + groupName + ", " +
- groupDescription + ") called");
+ logger.debug("deletePolicy(String policyToDeletes) as createGroup(" + groupId + ", " + groupName + ", "
+ + groupDescription + ") called");
if (isNullOrEmpty(groupId, groupName, username)) {
throw new IllegalArgumentException("groupId, groupName, and username must not be null or empty");
}
@@ -2265,11 +2244,11 @@ public class PolicyDBDao {
if (!stringEquals(groupToUpdateInDB.getModifiedBy(), username)) {
groupToUpdateInDB.setModifiedBy(username);
}
- if (group.getDescription() != null &&
- !stringEquals(group.getDescription(), groupToUpdateInDB.getDescription())) {
+ if (group.getDescription() != null
+ && !stringEquals(group.getDescription(), groupToUpdateInDB.getDescription())) {
groupToUpdateInDB.setDescription(group.getDescription());
}
- //let's find out what policies have been deleted
+ // let's find out what policies have been deleted
StdPDPGroup oldGroup = null;
try {
oldGroup = (StdPDPGroup) papEngine.getGroup(group.getId());
@@ -2281,12 +2260,12 @@ public class PolicyDBDao {
PolicyLogger.error("We cannot get the group from the papEngine to delete policies");
} else {
Set<String> newPolicySet = new HashSet<>(group.getPolicies().size());
- //a multiple of n runtime is faster than n^2, so I am using a hashset to do the comparison
+ // a multiple of n runtime is faster than n^2, so I am using a hashset to do the comparison
for (PDPPolicy pol : group.getPolicies()) {
newPolicySet.add(pol.getId());
}
for (PDPPolicy pol : oldGroup.getPolicies()) {
- //should be fast since getPolicies uses a HashSet in StdPDPGroup
+ // should be fast since getPolicies uses a HashSet in StdPDPGroup
if (!newPolicySet.contains(pol.getId())) {
String[] scopeAndName = getNameScopeAndVersionFromPdpPolicy(pol.getId());
deletePolicyInScope(username, groupToUpdateInDB, pol, scopeAndName);
@@ -2295,7 +2274,7 @@ public class PolicyDBDao {
}
if (group.getName() != null && !stringEquals(group.getName(), groupToUpdateInDB.getgroupName())) {
- //we need to check if the new id exists in the database
+ // we need to check if the new id exists in the database
String newGroupId = createNewPDPGroupId(group.getName());
Query checkGroupQuery = em.createQuery(groupEntitySelectQuery);
checkGroupQuery.setParameter(groupIdVar, newGroupId);
@@ -2322,7 +2301,7 @@ public class PolicyDBDao {
}
private void deletePolicyInScope(String username, GroupEntity groupToUpdateInDB, PDPPolicy pol,
- String[] scopeAndName) {
+ String[] scopeAndName) {
PolicyEntity policyToDelete;
if (scopeAndName == null) {
return;
@@ -2344,35 +2323,33 @@ public class PolicyDBDao {
}
private void deletePolicyFromGroupEntity(GroupEntity groupToUpdateInDB, PolicyEntity policyToDelete,
- Iterator<PolicyEntity> dbPolicyIt, String policyName) {
+ Iterator<PolicyEntity> dbPolicyIt, String policyName) {
try {
while (dbPolicyIt.hasNext()) {
PolicyEntity dbpolicy = dbPolicyIt.next();
- if (policyToDelete.getScope().equals(dbpolicy.getScope()) &&
- getPolicyNameAndVersionFromPolicyFileName(dbpolicy.getPolicyName())[0].equals(policyName)) {
+ if (policyToDelete.getScope().equals(dbpolicy.getScope())
+ && getPolicyNameAndVersionFromPolicyFileName(dbpolicy.getPolicyName())[0]
+ .equals(policyName)) {
dbPolicyIt.remove();
- logger.info("PolicyDBDao: deleting policy from the existing group:\n "
- + "policyName is " + policyToDelete.getScope() + "." + policyToDelete.getPolicyName() +
- "\n"
- + "group is " + groupToUpdateInDB.getGroupId());
+ logger.info("PolicyDBDao: deleting policy from the existing group:\n " + "policyName is "
+ + policyToDelete.getScope() + "." + policyToDelete.getPolicyName() + "\n" + "group is "
+ + groupToUpdateInDB.getGroupId());
}
}
} catch (Exception e) {
logger.debug(e);
- PolicyLogger.error("Could not delete policy with name: " + policyToDelete.getScope() + "." +
- policyToDelete.getPolicyName() + "\n ID: " + policyToDelete.getPolicyId());
+ PolicyLogger.error("Could not delete policy with name: " + policyToDelete.getScope() + "."
+ + policyToDelete.getPolicyName() + "\n ID: " + policyToDelete.getPolicyId());
}
}
@Override
public void addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int pdpJmxPort,
- String username) {
- logger.debug(
- "addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int " +
- "pdpJmxPort, String username) as addPdpToGroup(" +
- pdpID + ", " + groupID + ", " + pdpName + ", " + pdpDescription + ", " + pdpJmxPort + ", " +
- username + ") called");
+ String username) {
+ logger.debug("addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int "
+ + "pdpJmxPort, String username) as addPdpToGroup(" + pdpID + ", " + groupID + ", " + pdpName + ", "
+ + pdpDescription + ", " + pdpJmxPort + ", " + username + ") called");
if (isNullOrEmpty(pdpID, groupID, pdpName, username)) {
throw new IllegalArgumentException("pdpID, groupID, pdpName, and username must not be null or empty");
}
@@ -2401,8 +2378,8 @@ public class PolicyDBDao {
checkDuplicateList = checkDuplicateQuery.getResultList();
} catch (Exception e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught Exception trying to check for duplicate PDP " + pdpID +
- " on checkDuplicateQuery.getResultList()");
+ "Caught Exception trying to check for duplicate PDP " + pdpID
+ + " on checkDuplicateQuery.getResultList()");
throw new PersistenceException("Query failed trying to check for duplicate PDP " + pdpID);
}
PdpEntity newPdp;
@@ -2480,8 +2457,8 @@ public class PolicyDBDao {
@Override
public void movePdp(OnapPDP pdp, OnapPDPGroup group, String username) {
- logger.debug("movePdp(PDP pdp, PDPGroup group, String username) as movePdp(" + pdp + "," + group + "," +
- username + ") called");
+ logger.debug("movePdp(PDP pdp, PDPGroup group, String username) as movePdp(" + pdp + "," + group + ","
+ + username + ") called");
if (pdp == null || group == null) {
throw new IllegalArgumentException("PDP pdp and PDPGroup group must not be null");
}
@@ -2492,7 +2469,7 @@ public class PolicyDBDao {
synchronized (emLock) {
checkBeforeOperationRun();
- //check if pdp exists
+ // check if pdp exists
Query getPdpQuery = em.createQuery(pdpEntitySelectQuery);
getPdpQuery.setParameter(pdpIdVariable, pdp.getId());
getPdpQuery.setParameter(deletedVar, false);
@@ -2512,7 +2489,7 @@ public class PolicyDBDao {
throw new PersistenceException(moreThanOnePDP + pdp.getId() + deletedStatusFound);
}
- //check if new group exists
+ // check if new group exists
Query checkGroupQuery = em.createQuery(groupEntitySelectQuery);
checkGroupQuery.setParameter(groupIdVar, group.getId());
checkGroupQuery.setParameter(deletedVar, false);
@@ -2542,8 +2519,8 @@ public class PolicyDBDao {
@Override
public void changeDefaultGroup(OnapPDPGroup group, String username) {
- logger.debug("changeDefaultGroup(PDPGroup group, String username) as changeDefaultGroup(" + group + "," +
- username + ") called");
+ logger.debug("changeDefaultGroup(PDPGroup group, String username) as changeDefaultGroup(" + group + ","
+ + username + ") called");
if (group == null) {
throw new IllegalArgumentException("PDPGroup group must not be null");
}
@@ -2580,9 +2557,9 @@ public class PolicyDBDao {
em.flush();
this.groupId = newDefaultGroup.getGroupKey();
Query setAllGroupsNotDefault = em.createQuery(
- "UPDATE GroupEntity g SET g.defaultGroup=:defaultGroup WHERE g.deleted=:deleted AND g" +
- ".groupKey<>:groupKey");
- //not going to set modified by for all groups
+ "UPDATE GroupEntity g SET g.defaultGroup=:defaultGroup WHERE g.deleted=:deleted AND g"
+ + ".groupKey<>:groupKey");
+ // not going to set modified by for all groups
setAllGroupsNotDefault.setParameter("defaultGroup", false);
setAllGroupsNotDefault.setParameter(deletedVar, false);
setAllGroupsNotDefault.setParameter("groupKey", newDefaultGroup.getGroupKey());
@@ -2601,8 +2578,8 @@ public class PolicyDBDao {
@Override
public void deleteGroup(OnapPDPGroup group, OnapPDPGroup moveToGroup, String username)
throws PolicyDBException {
- logger.debug("deleteGroup(PDPGroup group, PDPGroup moveToGroup, String username) as deleteGroup(" + group +
- ", " + moveToGroup + "," + username + ") called");
+ logger.debug("deleteGroup(PDPGroup group, PDPGroup moveToGroup, String username) as deleteGroup(" + group
+ + ", " + moveToGroup + "," + username + ") called");
if (group == null) {
throw new IllegalArgumentException("PDPGroup group cannot be null");
}
@@ -2659,8 +2636,8 @@ public class PolicyDBDao {
checkMoveToGroupList = checkMoveToGroupQuery.getResultList();
} catch (Exception e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught Exception trying to check if group exists checkMoveToGroupQuery" +
- ".getResultList()");
+ "Caught Exception trying to check if group exists checkMoveToGroupQuery"
+ + ".getResultList()");
throw new PersistenceException("Query failed trying to check if group exists");
}
if (checkMoveToGroupList.isEmpty()) {
@@ -2683,20 +2660,20 @@ public class PolicyDBDao {
this.newGroupId = newGroup.getGroupId();
} catch (PersistenceException e) {
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
- "Caught PersistenceException trying to set pdp group to null on em.flush" +
- "()");
+ "Caught PersistenceException trying to set pdp group to null on em.flush"
+ + "()");
throw new PersistenceException("Query failed trying to set pdp group to ");
}
}
}
} else {
- PolicyLogger.error("Group " + group.getId() +
- " is trying to be delted with PDPs. No group was provided to move them to");
+ PolicyLogger.error("Group " + group.getId()
+ + " is trying to be delted with PDPs. No group was provided to move them to");
throw new PolicyDBException("Group has PDPs. Must provide a group for them to move to");
}
}
- //delete group here
+ // delete group here
GroupEntity groupToDelete = (GroupEntity) deleteGroupQueryList.get(0);
groupToDelete.setDeleted(true);
if (!stringEquals(groupToDelete.getModifiedBy(), username)) {
@@ -2709,16 +2686,14 @@ public class PolicyDBDao {
@Override
public StdPDPGroup addPolicyToGroup(String groupID, String policyID, String username) throws PolicyDBException {
- logger.info(
- "PolicyDBDao: addPolicyToGroup(String groupID, String policyID, String username) as " +
- "addPolicyToGroup(" +
- groupID + ", " + policyID + "," + username + ") called");
+ logger.info("PolicyDBDao: addPolicyToGroup(String groupID, String policyID, String username) as "
+ + "addPolicyToGroup(" + groupID + ", " + policyID + "," + username + ") called");
if (isNullOrEmpty(groupID, policyID, username)) {
throw new IllegalArgumentException("groupID, policyID, and username must not be null or empty");
}
synchronized (emLock) {
checkBeforeOperationRun();
- //check if group exists
+ // check if group exists
Query groupQuery = em.createQuery(groupEntitySelectQuery);
groupQuery.setParameter(groupIdVar, groupID);
groupQuery.setParameter(deletedVar, false);
@@ -2738,15 +2713,15 @@ public class PolicyDBDao {
throw new PersistenceException(duplicateGroupId + groupID + foundInDBNotDeleted);
}
- //we need to convert the form of the policy id that is used groups into the form that is used
- //for the database. (com.Config_mypol.1.xml) to (Config_mypol.xml)
+ // we need to convert the form of the policy id that is used groups into the form that is used
+ // for the database. (com.Config_mypol.1.xml) to (Config_mypol.xml)
String[] policyNameScopeAndVersion = getNameScopeAndVersionFromPdpPolicy(policyID);
if (policyNameScopeAndVersion == null) {
throw new IllegalArgumentException("Invalid input - policyID must contain name, scope and version");
}
Query policyQuery = em.createQuery(
- "SELECT p FROM PolicyEntity p WHERE p.policyName=:policyName AND p.scope=:scope AND p" +
- ".deleted=:deleted");
+ "SELECT p FROM PolicyEntity p WHERE p.policyName=:policyName AND p.scope=:scope AND p"
+ + ".deleted=:deleted");
policyQuery.setParameter("policyName", policyNameScopeAndVersion[0]);
policyQuery.setParameter(scope, policyNameScopeAndVersion[1]);
policyQuery.setParameter(deletedVar, false);
@@ -2761,10 +2736,10 @@ public class PolicyDBDao {
"Query failed trying to check if policy " + policyNameScopeAndVersion[0] + " exists");
}
if (policyQueryList.isEmpty()) {
- PolicyLogger.error("Policy being added to the group does not exist with policy id " +
- policyNameScopeAndVersion[0]);
- throw new PersistenceException("Policy being added to the group does not exist with policy id " +
- policyNameScopeAndVersion[0]);
+ PolicyLogger.error("Policy being added to the group does not exist with policy id "
+ + policyNameScopeAndVersion[0]);
+ throw new PersistenceException("Policy being added to the group does not exist with policy id "
+ + policyNameScopeAndVersion[0]);
} else if (policyQueryList.size() > 1) {
PolicyLogger.error(duplicatePolicyId + policyNameScopeAndVersion[0] + foundInDBNotDeleted);
throw new PersistenceException(
@@ -2780,38 +2755,40 @@ public class PolicyDBDao {
try {
while (policyIt.hasNext()) {
PolicyEntity pol = policyIt.next();
- if (policy.getScope().equals(pol.getScope()) &&
- getPolicyNameAndVersionFromPolicyFileName(pol.getPolicyName())[0].equals(policyName)) {
+ if (policy.getScope().equals(pol.getScope())
+ && getPolicyNameAndVersionFromPolicyFileName(pol.getPolicyName())[0]
+ .equals(policyName)) {
policyIt.remove();
}
}
} catch (Exception e) {
logger.debug(e);
- PolicyLogger.error("Could not delete old versions for policy " + policy.getPolicyName() + ", ID: " +
- policy.getPolicyId());
+ PolicyLogger.error("Could not delete old versions for policy " + policy.getPolicyName() + ", ID: "
+ + policy.getPolicyId());
}
group.addPolicyToGroup(policy);
em.flush();
- // After adding policy to the db group we need to make sure the filesytem group is in sync with the db group
+ // After adding policy to the db group we need to make sure the filesytem group is in sync with the db
+ // group
try {
StdPDPGroup pdpGroup = (StdPDPGroup) papEngine.getGroup(group.getGroupId());
return synchronizeGroupPoliciesInFileSystem(pdpGroup, group);
} catch (PAPException e) {
logger.debug(e);
PolicyLogger
- .error("PolicyDBDao: Could not synchronize the filesystem group with the database group. " +
- e.getMessage());
+ .error("PolicyDBDao: Could not synchronize the filesystem group with the database group. "
+ + e.getMessage());
}
return null;
}
}
- //this means delete pdp not just remove from group
+ // this means delete pdp not just remove from group
@Override
public void removePdpFromGroup(String pdpID, String username) {
- logger.debug("removePdpFromGroup(String pdpID, String username) as removePdpFromGroup(" + pdpID + "," +
- username + ") called");
+ logger.debug("removePdpFromGroup(String pdpID, String username) as removePdpFromGroup(" + pdpID + ","
+ + username + ") called");
if (isNullOrEmpty(pdpID, username)) {
throw new IllegalArgumentException("pdpID and username must not be null or empty");
}
@@ -2853,17 +2830,18 @@ public class PolicyDBDao {
}
private void notifyOthers(long entityId, String entityType, String newGroupId) {
- logger.debug("notifyOthers(long entityId, String entityType, long newGroupId) as notifyOthers(" + entityId +
- "," + entityType + "," + newGroupId + ") called");
+ logger.debug("notifyOthers(long entityId, String entityType, long newGroupId) as notifyOthers(" + entityId
+ + "," + entityType + "," + newGroupId + ") called");
LinkedList<Thread> notifyThreads = new LinkedList<>();
- //we're going to run notifications in parallel threads to speed things up
+ // we're going to run notifications in parallel threads to speed things up
for (Object obj : otherServers) {
Thread newNotifyThread = new Thread(new NotifyOtherThread(obj, entityId, entityType, newGroupId));
newNotifyThread.start();
notifyThreads.add(newNotifyThread);
}
- //we want to wait for all notifications to complete or timeout before we unlock the interface and allow more changes
+ // we want to wait for all notifications to complete or timeout before we unlock the interface and allow
+ // more changes
for (Thread t : notifyThreads) {
try {
t.join();
@@ -2875,7 +2853,7 @@ public class PolicyDBDao {
}
private PolicyDBDao() {
- //empty constructor
+ // empty constructor
}
public static PolicyDBDaoTestClass getPolicyDBDaoTestClass() {
@@ -2892,4 +2870,4 @@ public class PolicyDBDao {
}
}
-} \ No newline at end of file
+}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java
index 335434fd4..2da84d754 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java
@@ -138,7 +138,8 @@ public class SavePolicyHandler {
policyAdapter.setRuleProvider(policy.getProviderComboBox());
policyAdapter.setDomainDir(policyAdapter.getPolicyScope());
policyAdapter.setRainydayMap(policy.getTreatments());
-
+ policyAdapter.setRawXacmlPolicy(policy.getRawXacmlPolicy());
+
return policyAdapter;
}