package org.openecomp.policy.xacml.action;
import java.io.BufferedReader;
-import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.json.JsonReader;
import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.Logger;
import org.openecomp.policy.rest.XACMLRestProperties;
import com.att.research.xacml.api.Advice;
import com.att.research.xacml.std.StdObligation;
import com.att.research.xacml.util.XACMLProperties;
-import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
-
+@SuppressWarnings("deprecation")
public class FindAction {
- private Logger logger = (Logger) FlexLogger.getLogger(this.getClass());
+ private Logger LOGGER = FlexLogger.getLogger(this.getClass());
private Boolean changeIt = false;
private String configURL = null;
private StdMutableResponse newResponse = new StdMutableResponse();
search(stdResponse);
}
addResults(stdResponse, config , decide);
- logger.info("Original Result is " + stdResponse.toString());
- logger.info("Generated Result is " + addResult.toString());
+ LOGGER.info("Original Result is " + stdResponse.toString());
+ LOGGER.info("Generated Result is " + addResult.toString());
return newResponse;
}
- private Collection<Obligation> obligations = new ArrayList<Obligation>();
- private Map<String, String> matchValues = new HashMap<String, String>();
- private Map<String, String> headers = new HashMap<String, String>();
+ private Collection<Obligation> obligations = new ArrayList<>();
+ private Map<String, String> matchValues = new HashMap<>();
+ private Map<String, String> headers = new HashMap<>();
private boolean header = false;
private void search(StdMutableResponse stdResponse) {
int count = 0, uri = 0, PEP = 0;
header = false;
changeIt = false;
- Collection<AttributeAssignment> afterRemoveAssignments = new ArrayList<AttributeAssignment>();
+ Collection<AttributeAssignment> afterRemoveAssignments = new ArrayList<>();
Identifier oblId = new IdentifierImpl(obligation.getId().stringValue());
StdAttributeAssignment attributeURI = null;
for (AttributeAssignment attribute : obligation.getAttributeAssignments()) {
attributeURI = new StdAttributeAssignment(attribute);
}
} else if (attribute.getAttributeId().stringValue().startsWith("headers")) {
- logger.info("Headers are : "+ attribute.getAttributeValue().getValue().toString());
+ LOGGER.info("Headers are : "+ attribute.getAttributeValue().getValue().toString());
header = true;
headers.put(attribute.getAttributeId().stringValue().replaceFirst("(headers).", ""),
attribute.getAttributeValue().getValue().toString());
String papPath = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL);
papPath= papPath.replace("/pap", "");
matchValues.put("body",attribute.getAttributeValue().getValue().toString().replace("$URL", papPath));
- } /*
- * else if (attribute.getAttributeId().stringValue().
- * equalsIgnoreCase("type")){ requestAction.put("Type",
- * attribute.getAttributeValue().getValue().toString());
- * afterRemoveAssignments.add(attribute); } else
- * if(attribute
- * .getAttributeId().stringValue().equalsIgnoreCase
- * ("method")) { requestAction.put("Method",
- * attribute.getAttributeValue().getValue().toString());
- * afterRemoveAssignments.add(attribute); } else
- * if(attribute
- * .getAttributeId().stringValue().equalsIgnoreCase
- * ("body")) { requestAction.put("Body",
- * attribute.getAttributeValue().getValue().toString());
- * afterRemoveAssignments.add(attribute); }
- */else {
+ }else {
StdAttributeAssignment attributeObligation = new StdAttributeAssignment(attribute);
afterRemoveAssignments.add(attributeObligation);
}
if (count == 1 && uri == 1 && PEP == 0) {
// Remove Obligation and add Advice
changeIt = true;
- TakeAction(stdResponse, oblId, afterRemoveAssignments);
+ takeAction(stdResponse, oblId, afterRemoveAssignments);
} else if (PEP == 1 && count == 0) {
// Strip the PEPACTION if available
if (uri == 1) {
}
}
- private void TakeAction(StdMutableResponse stdResponse, Identifier advId,
+ private void takeAction(StdMutableResponse stdResponse, Identifier advId,
Collection<AttributeAssignment> afterRemoveAssignments) {
if (changeIt) {
- logger.info("the URL is :" + configURL);
+ LOGGER.info("the URL is :" + configURL);
// Calling Rest URL..
callRest();
// Including the Results in an Advice
Identifier id = new IdentifierImpl(
- "com:att:labs:ecomp:policy:pdp:reply");
+ "org:openecomp:policy:pdp:reply");
Identifier statId = new IdentifierImpl(
- "com:att:labs:ecomp:policy:pdp:reply:status");
+ "org:openecomp:ecomp:policy:pdp:reply:status");
Identifier statCategory = new IdentifierImpl(
"urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject");
Identifier strId = new IdentifierImpl(
"http://www.w3.org/2001/XMLSchema#string");
Identifier resId = new IdentifierImpl(
- "com:att:labs:ecomp:policy:pdp:reply:resource");
+ "org:openecomp:ecomp:policy:pdp:reply:resource");
Identifier resCategory = new IdentifierImpl(
"urn:oasis:names:tc:xacml:3.0:attribute-category:resource");
Identifier urlId = new IdentifierImpl(
"http://www.w3.org/2001/XMLSchema#anyURI");
- // Collection<AttributeAssignment> attributes = new
- // ArrayList<AttributeAssignment>();
- AttributeValue<String> attributeStatusValue = new StdAttributeValue<String>(
+ AttributeValue<String> attributeStatusValue = new StdAttributeValue<>(
strId, status + response);
- AttributeValue<String> attributeResourceValue = new StdAttributeValue<String>(
+ AttributeValue<String> attributeResourceValue = new StdAttributeValue<>(
urlId, configURL);
StdAttributeAssignment attributeStatus = new StdAttributeAssignment(
statCategory, statId, "PDP", attributeStatusValue);
private int status;
private String response;
+ private DefaultHttpClient httpClient;
private void callRest() {
// Finding the Macros in the URL..
Matcher match = pattern.matcher(configURL);
StringBuffer sb = new StringBuffer();
while (match.find()) {
- logger.info("Found Macro : " + match.group(1));
+ LOGGER.info("Found Macro : " + match.group(1));
String replaceValue = matchValues.get(match.group(1));
- logger.info("Replacing with :" + replaceValue);
+ LOGGER.info("Replacing with :" + replaceValue);
match.appendReplacement(sb, replaceValue);
}
match.appendTail(sb);
- logger.info("URL is : " + sb.toString());
+ LOGGER.info("URL is : " + sb.toString());
configURL = sb.toString();
// Calling the Requested service.
if (matchValues.get("method").equalsIgnoreCase("GET")) {
- DefaultHttpClient httpClient = new DefaultHttpClient();
+ httpClient = new DefaultHttpClient();
try {
HttpGet getRequest = new HttpGet(configURL);
// Adding Headers here
output = output + out;
}
response = output;
- } catch (ClientProtocolException e) {
- response = e.getMessage();
- } catch (IOException e) {
+ } catch (Exception e) {
+ LOGGER.error(e.getMessage()+e);
response = e.getMessage();
} finally {
httpClient.getConnectionManager().shutdown();
}
} else if(matchValues.get("method").equalsIgnoreCase("POST")) {
- DefaultHttpClient httpClient = new DefaultHttpClient();
+ httpClient = new DefaultHttpClient();
try {
HttpPost postRequest = new HttpPost(configURL);
// Adding Headers here
URLConnection connection = null;
connection = configURL.openConnection();
// InputStream in = connection.getInputStrem();
- // logger.info("The Body Content is : " + IOUtils.toString(in));
+ // LOGGER.info("The Body Content is : " + IOUtils.toString(in));
JsonReader jsonReader = Json.createReader(connection.getInputStream());
StringEntity input = new StringEntity(jsonReader.readObject().toString());
input.setContentType("application/json");
postRequest.setEntity(input);
// Executing the Request.
HttpResponse result = httpClient.execute(postRequest);
- logger.info("Result Headers are : " + result.getAllHeaders());
+ LOGGER.info("Result Headers are : " + result.getAllHeaders());
status = result.getStatusLine().getStatusCode();
BufferedReader br = new BufferedReader(new InputStreamReader(
(result.getEntity().getContent())));
output = output + out;
}
response = output;
- } catch (ClientProtocolException e) {
- response = e.getMessage();
- } catch (IOException e) {
+ }catch (Exception e) {
+ LOGGER.error(e.getMessage() +e);
response = e.getMessage();
} finally {
httpClient.getConnectionManager().shutdown();
}
} else if(matchValues.get("method").equalsIgnoreCase("PUT")) {
- DefaultHttpClient httpClient = new DefaultHttpClient();
+ httpClient = new DefaultHttpClient();
try {
HttpPut putRequest = new HttpPut(configURL);
// Adding Headers here
URLConnection connection = null;
connection = configURL.openConnection();
//InputStream in = connection.getInputStream();
- //logger.info("The Body Content is : " + IOUtils.toString(in));
+ //LOGGER.info("The Body Content is : " + IOUtils.toString(in));
JsonReader jsonReader = Json.createReader(connection.getInputStream());
StringEntity input = new StringEntity(jsonReader.readObject().toString());
input.setContentType("application/json");
output = output + out;
}
response = output;
- } catch (ClientProtocolException e) {
+ } catch (Exception e) {
+ LOGGER.error(e.getMessage() +e);
response = e.getMessage();
- } catch (IOException e) {
- response = e.getMessage();
- } finally {
+ }finally {
httpClient.getConnectionManager().shutdown();
}
}
}
-}
+}
\ No newline at end of file