* ============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.
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;
private int responseCode = 0;
private static String environment = "DEVL";
- private static Boolean junit = false;
+ private static Boolean isJunit = false;
private static List<String> 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;
+ private String encoding = null;
+
+ public static void setJunit(boolean isJunit) {
+ PAPServices.isJunit = isJunit;
+ }
public PAPServices() {
environment = PDPApiAuth.getEnvironment();
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));
}
}
return result;
}
+
+ public static void setPaps(List<String> paps) {
+ PAPServices.paps = paps;
+ }
public int getResponseCode() {
return responseCode;
// 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);
}
} else if(content != null){
// the content is an object to be encoded in JSON
ObjectMapper mapper = new ObjectMapper();
- if (!junit) {
+ if (!isJunit) {
mapper.writeValue(connection.getOutputStream(),
content);
}
responseCode = connection.getResponseCode();
// If Connected to PAP then break from the loop and continue
// with the Request
- if (connection.getResponseCode() > 0 || junit) {
+ if (connection.getResponseCode() > 0 || isJunit) {
connected = true;
break;
} else {
}
} catch (Exception e) {
// This means that the PAP is not working
- if (junit) {
+ if (isJunit) {
connected = true;
break;
}
XACMLErrorConstants.ERROR_SYSTEM_ERROR
+ "Decoding the result ", e);
}
- if (junit) {
+ if (isJunit) {
response = SUCCESS;
}
}else{
}
return response;
} else {
- response = XACMLErrorConstants.ERROR_SYSTEM_ERROR
+ response = XACMLErrorConstants.ERROR_DATA_ISSUE
+ "Unable to get valid response from PAP(s) " + paps;
return response;
}
private String checkResponse(HttpURLConnection connection, UUID requestID) throws IOException {
String response = null;
- if (responseCode == 200 || junit) {
+ if (responseCode == 200 || isJunit) {
// Check for successful creation of policy
String isSuccess = null;
- if (!junit) { // is this a junit test?
+ if (!isJunit) { // is this a junit test?
isSuccess = connection.getHeaderField("successMapKey");
operation = connection.getHeaderField("operation");
} else {
+ ". 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
+ + connection.getHeaderField("message");
}
} else if (connection.getResponseCode() == 409 && connection.getHeaderField("error") != null) {
if ("modelExistsDB".equals(connection.getHeaderField("error"))) {
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;
+ "\"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);
}
responseCode = connection.getResponseCode();
// If Connected to PAP then break from the loop and continue
// with the Request
- if (connection.getResponseCode() > 0 || junit) {
+ if (connection.getResponseCode() > 0 || isJunit) {
connected = true;
break;
} else {
}
} catch (Exception e) {
// This means that the PAP is not working
- if (junit) {
+ if (isJunit) {
connected = true;
break;
}