* ============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.
* 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;
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());
}
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(","));
}
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;
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
// 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)) {
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();
}
} 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;
}
}
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 {
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) {
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;
+ "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) {
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.";