diff options
Diffstat (limited to 'ONAP-PAP-REST/src/main/java')
7 files changed, 39 insertions, 34 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java index 4f65e26a0..d6c298731 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java @@ -1419,12 +1419,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList //If the selected policy is in the group we must remove the old version of it LOGGER.info("Removing old version of the policy"); for(PDPPolicy existingPolicy : currentPoliciesInGroup) { - if (existingPolicy.getName().equals(policy.getName())){ - if (!existingPolicy.getId().equals(policy.getId())) { - group.removePolicy(existingPolicy); - LOGGER.info("Removing policy: " + existingPolicy); - break; - } + if (existingPolicy.getName().equals(policy.getName()) && !existingPolicy.getId().equals(policy.getId())){ + group.removePolicy(existingPolicy); + LOGGER.info("Removing policy: " + existingPolicy); + break; } } @@ -1618,12 +1616,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList */ if(apiflag != null){ - // get the request content into a String - String json = null; // read the inputStream into a buffer java.util.Scanner scanner = new java.util.Scanner(request.getInputStream()); scanner.useDelimiter("\\A"); - json = scanner.hasNext() ? scanner.next() : ""; + String json = scanner.hasNext() ? scanner.next() : ""; scanner.close(); LOGGER.info("PushPolicy API request: " + json); @@ -1671,7 +1667,9 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList } //delete temporary policy file from the bin directory - Files.deleteIfExists(Paths.get(policy.getId())); + if(policy != null) { + Files.deleteIfExists(Paths.get(policy.getId())); + } } } catch (Exception e) { @@ -2622,10 +2620,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList public UpdatePDPThread(OnapPDP pdp, ONAPLoggingContext loggingContext) { this.pdp = pdp; - if (!(loggingContext == null)) { - if (!(loggingContext.getRequestID() == null) || (loggingContext.getRequestID() == "")) { + if ((loggingContext != null) && (loggingContext.getRequestID() != null || loggingContext.getRequestID() == "")) { this.requestId = loggingContext.getRequestID(); - } } this.loggingContext = loggingContext; } @@ -2635,7 +2631,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList HttpURLConnection connection = null; // get a new logging context for the thread try { - if (this.loggingContext.equals(null)) { + if (this.loggingContext == null) { loggingContext = new ONAPLoggingContext(baseLoggingContext); } } catch (Exception e) { diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java index ee6fd0568..430f9cd65 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java @@ -177,13 +177,10 @@ public class ElasticSearchPolicyUpdate { while(configResult.next()){ String configBody = configResult.getString("configbody"); String configType = configResult.getString("configtype"); - if("JSON".equalsIgnoreCase(configType)){ - policyDataString.append("\"jsonBodyData\":"+configBody+",\"configType\":\""+configType+"\","); - }else if("OTHER".equalsIgnoreCase(configType)){ - if(configBody!=null){ - configBody= configBody.replaceAll("\"", ""); - policyDataString.append("\"jsonBodyData\":\""+configBody+"\",\"configType\":\""+configType+"\","); - } + if(configBody!=null){ + configBody = configBody.replace("null", "\"\""); + configBody= configBody.replace("\"", "\\\""); + policyDataString.append("\"jsonBodyData\":\""+configBody+"\",\"configType\":\""+configType+"\","); } } configResult.close(); @@ -197,7 +194,9 @@ public class ElasticSearchPolicyUpdate { ResultSet actionResult = pstmt.executeQuery(); while(actionResult.next()){ String actionBody = actionResult.getString("actionbody"); - policyDataString.append("\"jsonBodyData\":"+actionBody+","); + actionBody = actionBody.replace("null", "\"\""); + actionBody = actionBody.replace("\"", "\\\""); + policyDataString.append("\"jsonBodyData\":\""+actionBody+"\","); } actionResult.close(); } @@ -205,13 +204,11 @@ public class ElasticSearchPolicyUpdate { String _id = policyWithScopeName; - policyDataString.append(constructPolicyData(policyData, policyDataString)); - - String dataString = policyDataString.toString(); + String dataString = constructPolicyData(policyData, policyDataString); dataString = dataString.substring(0, dataString.length()-1); dataString = dataString.trim().replace(System.getProperty("line.separator"), "") + "}"; dataString = dataString.replace("null", "\"\""); - dataString = dataString.replaceAll(" ", "").replaceAll("\n", ""); + dataString = dataString.replaceAll("\n", ""); try{ Gson gson = new Gson(); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java index 88f9e2c87..9091d79ed 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java @@ -101,6 +101,9 @@ public class ElkConnectorImpl implements ElkConnector{ throw e; } } + private boolean isAlphaNumeric(String query){ + return query.matches("[a-zA-Z_0-9]+"); + } @Override public JestResult search(PolicyIndexType type, String text) throws IllegalStateException, IllegalArgumentException { @@ -112,6 +115,10 @@ public class ElkConnectorImpl implements ElkConnector{ throw new IllegalArgumentException("No search string provided"); } + if(!isAlphaNumeric(text)){ + throw new IllegalArgumentException("Search must be alpha numeric"); + } + QueryStringQueryBuilder mQ = QueryBuilders.queryStringQuery("*"+text+"*"); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(mQ); @@ -198,6 +205,10 @@ public class ElkConnectorImpl implements ElkConnector{ return search(type, text); } + if(!isAlphaNumeric(text)){ + throw new IllegalArgumentException("Search must be alpha numeric"); + } + String matches_s = ""; matches_s = "{\n" + " \"size\" : "+ ElkConnectorImpl.QUERY_MAXRECORDS + ",\n" + diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java index 3e065ff05..b624f3bf0 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java @@ -113,7 +113,7 @@ public class PolicyElasticData { private YAMLParams yamlparams; public PolicyElasticData(PolicyRestAdapter policyData) { - this.scope = policyData.getDomain(); + this.scope = policyData.getDomainDir(); this.policyType = policyData.getPolicyType(); this.configPolicyType = policyData.getConfigPolicyType(); this.configBodyData = policyData.getConfigBodyData(); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java index 78da2a572..77e45e30d 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java @@ -231,7 +231,7 @@ public class PolicyElasticSearchController{ if(searchData.getPolicyType() != null && "closedLoop".equals(searchData.getPolicyType())){ searchKeyValue.put("jsonBodyData", "*" +entry[1] +"*"); }else{ - searchKeyValue.put(entry[0], entry[1]); + searchText = entry[1]; } } } @@ -265,13 +265,13 @@ public class PolicyElasticSearchController{ searchKeyValue.put("jsonBodyData."+d2Service+"", "true"); } if(searchData.getVnfType() != null){ - searchKeyValue.put("jsonBodyData", "*" +searchData.getVnfType() +"*"); + searchKeyValue.put("jsonBodyData", "*"+searchData.getVnfType()+"*"); } if(searchData.getPolicyStatus() != null){ - searchKeyValue.put("jsonBodyData", "*" +searchData.getPolicyStatus()+"*"); + searchKeyValue.put("jsonBodyData", "*"+searchData.getPolicyStatus()+"*"); } if(searchData.getVproAction() != null){ - searchKeyValue.put("jsonBodyData", "*" +searchData.getVproAction()+"*"); + searchKeyValue.put("jsonBodyData", "*"+searchData.getVproAction()+"*"); } if(searchData.getServiceType() != null){ searchKeyValue.put("serviceType", searchData.getServiceType()); @@ -288,8 +288,10 @@ public class PolicyElasticSearchController{ type = ElkConnector.PolicyIndexType.decision; }else if(policyType.equalsIgnoreCase("config")){ type = ElkConnector.PolicyIndexType.config; - }else { + }else if(policyType.equalsIgnoreCase("closedloop")){ type = ElkConnector.PolicyIndexType.closedloop; + }else{ + type = ElkConnector.PolicyIndexType.all; } }else{ type = ElkConnector.PolicyIndexType.all; 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 e7680c3e2..9be4b0342 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 @@ -130,7 +130,6 @@ public class SavePolicyHandler { policyAdapter.setDynamicSettingsMap(policy.getDynamicSettingsMap()); policyAdapter.setRuleProvider(policy.getProviderComboBox()); policyAdapter.setDomainDir(policyAdapter.getPolicyScope()); - policyAdapter.setDomain(policyAdapter.getPolicyScope()); policyAdapter.setRainydayMap(policy.getTreatments()); return policyAdapter; diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java index 2af8a6ee1..76fe4ae5d 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java @@ -200,7 +200,7 @@ public class PolicyCreation extends AbstractPolicyCreation{ response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.addHeader("error", body); response.addHeader("message", policyData.getPolicyName() + " does not exist on the PAP and cannot be updated."); - return new ResponseEntity<String>(body, status); + return new ResponseEntity<>(body, status); } version = 1; if(userId == null){ |