* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
- * 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.
import org.apache.commons.io.IOUtils;
import org.onap.policy.rest.XACMLRestProperties;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
+import org.onap.policy.utils.CryptoUtils;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.onap.policy.xacml.api.pap.OnapPDP;
import org.onap.policy.xacml.api.pap.OnapPDPGroup;
import org.onap.policy.xacml.std.pap.StdPDPItemSetChangeNotifier;
import org.onap.policy.xacml.std.pap.StdPDPPolicy;
import org.onap.policy.xacml.std.pap.StdPDPStatus;
+
import com.att.research.xacml.api.pap.PAPException;
import com.att.research.xacml.api.pap.PDPPolicy;
import com.att.research.xacml.api.pap.PDPStatus;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
+
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
* Set up link with PAP Servlet and get our initial set of Groups
* @throws Exception
*/
- public RESTfulPAPEngine (String myURLString) throws PAPException, IOException {
+ public RESTfulPAPEngine (String myURLString) throws PAPException {
//
// Get our URL to the PAP servlet
//
}
@Override
- public void SetDefaultGroup(OnapPDPGroup group) throws PAPException {
+ public void setDefaultGroup(OnapPDPGroup group) throws PAPException {
sendToPAP("POST", null, null, null, groupID + group.getId(), "default=true");
}
@Override
public void newGroup(String name, String description)
- throws PAPException, NullPointerException {
+ throws PAPException {
String escapedName = null;
String escapedDescription = null;
try {
* @return
* @throws PAPException
*/
+ @Override
public void updateGroup(OnapPDPGroup group) throws PAPException {
try {
@Override
public void removeGroup(OnapPDPGroup group, OnapPDPGroup newGroup)
- throws PAPException, NullPointerException {
+ throws PAPException {
String moveToGroupString = null;
if (newGroup != null) {
moveToGroupString = "movePDPsToGroupId=" + newGroup.getId();
}
@Override
- public void newPDP(String id, OnapPDPGroup group, String name, String description, int jmxport) throws PAPException,
- NullPointerException {
+ public void newPDP(String id, OnapPDPGroup group, String name, String description, int jmxport) throws PAPException {
StdPDP newPDP = new StdPDP(id, name, description, jmxport);
sendToPAP("PUT", newPDP, null, null, groupID + group.getId(), "pdpId=" + id);
return;
//Validate the Policy Data
public boolean validatePolicyRequest(PolicyRestAdapter policyAdapter, String policyType) throws PAPException {
- Boolean isValidData = false;
StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyAdapter.getPolicyName(), policyAdapter.getConfigBodyData(), policyAdapter.getConfigType(), "Base");
//send JSON object to PAP
- isValidData = (Boolean) sendToPAP("PUT", newPAPPolicy, null, null, "operation=validate", "apiflag=admin", "policyType=" + policyType);
- return isValidData;
+ return (Boolean) sendToPAP("PUT", newPAPPolicy, null, null, "operation=validate", "apiflag=admin", "policyType=" + policyType);
}
* @return
* @throws PAPException
*/
-
+ @Override
public PDPStatus getStatus(OnapPDP pdp) throws PAPException {
return (StdPDPStatus)sendToPAP("GET", pdp, null, StdPDPStatus.class);
}
HttpURLConnection connection = null;
String papID = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID);
LOGGER.info("User Id is " + papID);
- String papPass = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS);
+ String papPass = CryptoUtils.decryptTxtNoExStr(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS));
Base64.Encoder encoder = Base64.getEncoder();
String encoding = encoder.encodeToString((papID+":"+papPass).getBytes(StandardCharsets.UTF_8));
+ Object contentObj = content;
LOGGER.info("Encoding for the PAP is: " + encoding);
try {
String fullURL = papServletURLString;
if (parameters != null && parameters.length > 0) {
- String queryString = "";
+ StringBuilder queryString = new StringBuilder();
for (String p : parameters) {
- queryString += "&" + p;
+ queryString.append("&" + p);
}
fullURL += "?" + queryString.substring(1);
}
// special case - Status (actually the detailed status) comes from the PDP directly, not the PAP
- if (method.equals("GET") && (content instanceof OnapPDP) && responseContentClass == StdPDPStatus.class) {
+ if ("GET".equals(method) && (contentObj instanceof OnapPDP) && responseContentClass == StdPDPStatus.class) {
// Adjust the url and properties appropriately
- String pdpID =((OnapPDP)content).getId();
+ String pdpID =((OnapPDP)contentObj).getId();
fullURL = pdpID + "?type=Status";
- content = null;
+ contentObj = null;
if(CheckPDP.validateID(pdpID)){
encoding = CheckPDP.getEncoding(pdpID);
}
connection.setDoOutput(true);
connection.setDoInput(true);
- if (content != null) {
- if (content instanceof InputStream) {
+ if (contentObj != null) {
+ if (contentObj instanceof InputStream) {
try {
//
// Send our current policy configuration
//
try (OutputStream os = connection.getOutputStream()) {
- int count = IOUtils.copy((InputStream)content, os);
+ int count = IOUtils.copy((InputStream)contentObj, os);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("copied to output, bytes="+count);
}
LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to write content in '" + method + "'", e);
}
} else {
- // The content is an object to be encoded in JSON
+ // The contentObj is an object to be encoded in JSON
ObjectMapper mapper = new ObjectMapper();
- mapper.writeValue(connection.getOutputStream(), content);
+ mapper.writeValue(connection.getOutputStream(), contentObj);
}
}
//
String isValidData = connection.getHeaderField("isValidData");
String isSuccess = connection.getHeaderField("successMapKey");
Map<String, String> successMap = new HashMap<>();
- if (isValidData != null && isValidData.equalsIgnoreCase("true")){
+ if (isValidData != null && "true".equalsIgnoreCase(isValidData)){
LOGGER.info("Policy Data is valid.");
return true;
- } else if (isValidData != null && isValidData.equalsIgnoreCase("false")) {
+ } else if (isValidData != null && "false".equalsIgnoreCase(isValidData)) {
LOGGER.info("Policy Data is invalid.");
return false;
- } else if (isSuccess != null && isSuccess.equalsIgnoreCase("success")) {
+ } else if (isSuccess != null && "success".equalsIgnoreCase(isSuccess)) {
LOGGER.info("Policy Created Successfully!" );
String finalPolicyPath = connection.getHeaderField("finalPolicyPath");
successMap.put("success", finalPolicyPath);
return successMap;
- } else if (isSuccess != null && isSuccess.equalsIgnoreCase("error")) {
+ } else if (isSuccess != null && "error".equalsIgnoreCase(isSuccess)) {
LOGGER.info("There was an error while creating the policy!");
successMap.put("error", "error");
return successMap;
final CollectionType javaType =
mapper.getTypeFactory().constructCollectionType(collectionTypeClass, responseContentClass);
- Object objectFromJSON = mapper.readValue(json, javaType);
- return objectFromJSON;
+ return mapper.readValue(json, javaType);
} else {
// single value object expected
- Object objectFromJSON = mapper.readValue(json, responseContentClass);
- return objectFromJSON;
+ return mapper.readValue(json, responseContentClass);
}
}
LOGGER.error("No Location header to redirect to when response code="+connection.getResponseCode());
throw new IOException("No redirect Location header when response code="+connection.getResponseCode());
}
- int qIndex = newURL.indexOf("?");
+ int qIndex = newURL.indexOf('?');
if (qIndex > 0) {
newURL = newURL.substring(0, qIndex);
}