X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcontroller%2FPushPolicyController.java;h=107983562da46c13ec640f71a56460ce2cd18b53;hb=5ba143338d6fbc2b4d1e36c0efcbbabe15c65301;hp=885a6117fb262e63a284d27e017402ec5cfc8d60;hpb=6fdf2fd8d754e59977bf107d60725b8394771f69;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java index 885a6117f..107983562 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.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. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,10 +62,17 @@ public class PushPolicyController { private static String errorMsg = "error"; private static String operation = "operation"; private static String messageContent = "message"; + + private static final String REGEX = "[0-9a-zA-Z._ ]*"; + @Autowired public PushPolicyController(CommonClassDao commonClassDao){ PushPolicyController.commonClassDao = commonClassDao; } + + public void setCommonClassDao(CommonClassDao commonClassDao){ + PushPolicyController.commonClassDao = commonClassDao; + } /* * This is an empty constructor */ @@ -86,7 +93,7 @@ public class PushPolicyController { requestID = UUID.randomUUID().toString(); LOGGER.info("No request ID provided, sending generated ID: " + requestID); } - LOGGER.info("Push policy Request : " + root.asText()); + LOGGER.info("Push policy Request to get the selectedPolicy : " + root.asText()); String policyVersionName = policyScope.replace(".", File.separator) + File.separator + filePrefix + policyName; List policyVersionObject = commonClassDao.getDataById(PolicyVersion.class, policyNames, policyVersionName); @@ -116,7 +123,7 @@ public class PushPolicyController { private void addPolicyToGroup(String policyScope, String policyID, String policyName, String pdpGroup, HttpServletResponse response) { StdPDPGroup selectedPDPGroup = null; StdPDPPolicy selectedPolicy = null; - //Get the current policies from the Group and Add the new one + //Get the selected PDP Group to push the policy try { selectedPDPGroup = (StdPDPGroup) XACMLPapServlet.getPAPEngine().getGroup(pdpGroup); } catch (PAPException e1) { @@ -124,6 +131,9 @@ public class PushPolicyController { } if(selectedPDPGroup==null){ String message = "Unknown groupId '" + selectedPDPGroup + "'"; + if(!message.matches(REGEX) ){ + message = "Unknown groupId"; + } PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); response.addHeader(errorMsg, "unknownGroupId"); response.addHeader(operation, "push"); @@ -159,7 +169,7 @@ public class PushPolicyController { // Create the policy Object selectedPolicy = new StdPDPPolicy(policyName, true, policyID, selectedURI); } catch (IOException e) { - LOGGER.error("Unable to create policy '" + policyName + "': "+ e.getMessage(),e); + LOGGER.error("Unable to get policy '" + policyName + "': "+ e.getMessage(),e); } try { new ObjectOutputStream(response.getOutputStream()).writeObject(selectedPolicy);