X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=ONAP-PDP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpdp%2Frest%2Fapi%2Fservices%2FPAPServices.java;h=516d873d44bd3ce1c7f19e7b1caaa00534b5f51b;hp=425bcebf95a3669cd926f39f0fd275fa308a0717;hb=c2ca6ea5cb44103903e1409e8dd6db80167e61e8;hpb=3ffafe7276cf76c779c58dc8224f717eb086bfb5 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 425bcebf9..516d873d4 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,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-PDP-REST * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,8 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.pdp.rest.api.services; +import com.att.research.xacml.util.XACMLProperties; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -33,20 +36,16 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.UUID; - import org.apache.commons.io.IOUtils; import org.onap.policy.api.PolicyException; 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.pdp.rest.restauth.AuthenticationService; +import org.onap.policy.rest.XacmlRestProperties; +import org.onap.policy.utils.PeCryptoUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pap.StdPDPPolicy; -import com.att.research.xacml.util.XACMLProperties; -import com.fasterxml.jackson.databind.ObjectMapper; - public class PAPServices { private static final String SUCCESS = "success"; private static Logger LOGGER = FlexLogger.getLogger(PAPServices.class.getName()); @@ -65,12 +64,12 @@ public class PAPServices { } public PAPServices() { - environment = PDPApiAuth.getEnvironment(); + environment = AuthenticationService.getEnvironment(); if (paps == null) { synchronized (papResourceLock) { - String urlList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URLS); + String urlList = XACMLProperties.getProperty(XacmlRestProperties.PROP_PAP_URLS); if (urlList == null) { - urlList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL); + urlList = XACMLProperties.getProperty(XacmlRestProperties.PROP_PAP_URL); } paps = Arrays.asList(urlList.split(",")); } @@ -79,10 +78,9 @@ public class PAPServices { private String getPAPEncoding() { if (encoding == null) { - final String userID = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID); - final String pass = - CryptoUtils.decryptTxtNoExStr(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS)); - final Base64.Encoder encoder = Base64.getEncoder(); + String userID = XACMLProperties.getProperty(XacmlRestProperties.PROP_PAP_USERID); + String pass = PeCryptoUtils.decrypt(XACMLProperties.getProperty(XacmlRestProperties.PROP_PAP_PASS)); + Base64.Encoder encoder = Base64.getEncoder(); encoding = encoder.encodeToString((userID + ":" + pass).getBytes(StandardCharsets.UTF_8)); } return encoding; @@ -131,7 +129,7 @@ public class PAPServices { String fullURL = getPAP(); fullURL = checkParameter(parameters, fullURL); final URL url = new URL(fullURL); - LOGGER.debug("--- Sending Request to PAP : " + url.toString() + " ---"); + LOGGER.info("--- Sending Request to PAP : " + url.toString() + " ---" + " RequestId:" + requestID); // Open the connection connection = (HttpURLConnection) url.openConnection(); // Setting Content-Type @@ -149,9 +147,9 @@ public class PAPServices { // Adding RequestID if (requestID == null) { requestID = UUID.randomUUID(); - LOGGER.info("No request ID provided, sending generated ID: " + requestID.toString()); + LOGGER.debug("No request ID provided, sending generated ID: " + requestID.toString()); } else { - LOGGER.info("Using provided request ID: " + requestID.toString()); + LOGGER.debug("Using provided request ID: " + requestID.toString()); } connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); if (content != null && (content instanceof InputStream)) { @@ -168,6 +166,9 @@ public class PAPServices { if (!isJunit) { mapper.writeValue(connection.getOutputStream(), content); } + } else { + LOGGER.info(XACMLErrorConstants.ERROR_DATA_ISSUE + "content is null for calling: " + url.getHost() + + requestID.toString()); } // DO the connect connection.connect(); @@ -215,10 +216,12 @@ public class PAPServices { } } else { response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "connection is null"; + LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "connection is null - RequestId: " + requestID); } return response; } else { response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Unable to get valid response from PAP(s) " + paps; + LOGGER.error("For RequestId: " + requestID + ", " + response); return response; } } @@ -228,7 +231,7 @@ public class PAPServices { String version = null; HttpURLConnection connection = null; final String[] parameters = {"apiflag=version", "policyScope=" + policyScope, "filePrefix=" + filePrefix, - "policyName=" + policyName}; + "policyName=" + policyName}; if (paps == null || paps.isEmpty()) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty."); } else { @@ -311,7 +314,8 @@ public class PAPServices { version = "pe300"; } else { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE - + "BAD REQUEST: Error occured while getting the version from the PAP. The request may be incorrect. The response code of the URL is '" + + "BAD REQUEST: Error occured while getting the version from the PAP. " + + "The request may be incorrect. The response code of the URL is '" + connection.getResponseCode() + "'"); } } catch (final IOException e) { @@ -327,6 +331,7 @@ public class PAPServices { private String checkResponse(final HttpURLConnection connection, final UUID requestID) throws IOException { String response = null; + LOGGER.info("PAPServices:checkResponse - RequestId: " + requestID + ", ResponseCode: " + responseCode); if (responseCode == 200 || isJunit) { // Check for successful creation of policy String isSuccess = null; @@ -436,14 +441,16 @@ public class PAPServices { + "Please create a new Dictionary Item or use the update API to modify the existing one."; } else if ("duplicateGroup".equals(connection.getHeaderField("error"))) { response = XACMLErrorConstants.ERROR_DATA_ISSUE - + "Group Policy Scope List Exist Error: The Group Policy Scope List for this Dictionary Item already exist in the database. " + + "Group Policy Scope List Exist Error: " + + "The Group Policy Scope List for this Dictionary Item already exist in the database. " + "Duplicate Group Policy Scope Lists for multiple groupNames is not allowed. " - + "Please review the request and verify that the groupPolicyScopeListData1 is unique compared to existing groups."; + + "Please review the request and " + + "verify that the groupPolicyScopeListData1 is unique compared to existing groups."; } else if ("PolicyInPDP".equals(connection.getHeaderField("error"))) { response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy Exist Error: The Policy trying to be deleted is active in PDP. " + "Active PDP Polcies are not allowed to be deleted from PAP. " - + "Please First remove the policy from PDP in order to successfully delete the Policy from PAP."; + + "Please First remove the policy from PDP in order to successfully delete the Policy from PAP"; } LOGGER.error(response); } else if (connection.getResponseCode() == 500 && connection.getHeaderField("error") != null) { @@ -457,7 +464,8 @@ public class PAPServices { response = connection.getHeaderField("message"); } else if ("unknown".equals(connection.getHeaderField("error"))) { response = XACMLErrorConstants.ERROR_UNKNOWN - + "Failed to delete the policy for an unknown reason. Check the file system and other logs for further information."; + + "Failed to delete the policy for an unknown reason. " + + "Check the file system and other logs for further information."; } else if ("deleteConfig".equals(connection.getHeaderField("error"))) { response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot delete the configuration or action body file in specified location.";