X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PDP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpdp%2Frest%2Fapi%2Fservices%2FPAPServices.java;h=59194841f9b59ef92aaa7ee0d18bc09933d9d1e3;hb=5ba143338d6fbc2b4d1e36c0efcbbabe15c65301;hp=72d8fdeec73fcc4b7b5dcda999853a03b2423c76;hpb=775f45908025e46a40c9c147fca2066af5c8c5b8;p=policy%2Fengine.git diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java index 72d8fdeec..59194841f 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PDP-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. @@ -40,6 +40,7 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.pdp.rest.config.PDPApiAuth; import org.onap.policy.rest.XACMLRestProperties; +import org.onap.policy.utils.CryptoUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pap.StdPDPPolicy; @@ -53,9 +54,9 @@ public class PAPServices { private int responseCode = 0; private static String environment = "DEVL"; - private static Boolean junit = false; + public static Boolean junit = false; private static List paps = null; - private static final Object papResourceLock = new Object(); + private static final Object papResourceLock = new Object(); private String operation = null; private String requestMethod = null; private String encoding = null; @@ -76,7 +77,7 @@ public class PAPServices { private String getPAPEncoding(){ if(encoding == null){ String userID = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID); - String pass = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS); + String pass =CryptoUtils.decryptTxtNoExStr(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS)); Base64.Encoder encoder = Base64.getEncoder(); encoding = encoder.encodeToString((userID+":"+pass).getBytes(StandardCharsets.UTF_8)); } @@ -96,6 +97,10 @@ public class PAPServices { } return result; } + + public static void setPaps(List paps) { + PAPServices.paps = paps; + } public int getResponseCode() { return responseCode; @@ -111,7 +116,7 @@ public class PAPServices { // This makes it Real-Time to change the list depending on their // availability. if (paps == null || paps.isEmpty()) { - String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty."; + String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAPs List is Empty."; LOGGER.error(message); throw new PolicyException(message); } @@ -215,7 +220,7 @@ public class PAPServices { } return response; } else { - response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Unable to get valid response from PAP(s) " + paps; return response; } @@ -415,10 +420,10 @@ public class PAPServices { + ". PEP is not Authorized for making this Request!! \n Contact Administrator for this Scope. "; LOGGER.error(response); } else if (connection.getResponseCode() == 404 && connection.getHeaderField("error") != null) { - if ("unknownGroupId".equals(connection.getHeaderField("error"))) { + if ("UnknownGroup".equals(connection.getHeaderField("error"))) { response = XACMLErrorConstants.ERROR_DATA_ISSUE + connection.getHeaderField("message") - + " Please check the pdpGroup you are requesting to move the policy to."; + + " Please check the pdpGroup you are requesting to push the policy to."; LOGGER.error(response); } else if ("policyNotAvailableForEdit".equals(connection.getHeaderField("error"))) { response = XACMLErrorConstants.ERROR_DATA_ISSUE @@ -490,13 +495,16 @@ public class PAPServices { response = XACMLErrorConstants.ERROR_UNKNOWN + "Could not create or update the policy for and unknown reason"; }else{ - response = XACMLErrorConstants.ERROR_DATA_ISSUE - + "BAD REQUEST: Error occured while attempting perform this operation.. the request may be incorrect. " + connection.getHeaderField("error"); + response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "Error occured while attempting perform this operation.. " + + "the request may be incorrect or the PAP is unreachable. " + + connection.getHeaderField("error"); } LOGGER.error(response); } else { - response = XACMLErrorConstants.ERROR_DATA_ISSUE - + "BAD REQUEST: Error occured while attempting perform this operation.. the request may be incorrect."; + response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "Error occured while attempting perform this operation.. " + + "the request may be incorrect or the PAP is unreachable."; LOGGER.error(response); } return response; @@ -544,11 +552,11 @@ public class PAPServices { + "\"policyName\": \""+policyName+"\"," + "\"clientScope\": \""+clientScope+"\"," + "\"pdpGroup\": \""+pdpGroup+"\"}"; - //String response = null; - HttpURLConnection connection = null; + + HttpURLConnection connection = null; responseCode = 0; if (paps == null || paps.isEmpty()) { - String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty."; + String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAPs List is Empty."; LOGGER.error(message); throw new PolicyException(message); }