summaryrefslogtreecommitdiffstats
path: root/ECOMP-PDP/src/main/java/org/openecomp
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2017-02-14 19:41:00 -0500
committerPamela Dragosh <pdragosh@research.att.com>2017-02-14 19:41:32 -0500
commit91d04c64771832a0b8815ffbe1f0f9920320d94d (patch)
treefb02d5e1c84a3d91def9a7ee95bc87f9c046cc96 /ECOMP-PDP/src/main/java/org/openecomp
parentb9d4caa40ef8e3566ac475968bce17b9b64b6939 (diff)
Initial OpenECOMP policy/engine commit
Change-Id: I7dbff37733b661643dd4d1caefa3d7dccc361b6e Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'ECOMP-PDP/src/main/java/org/openecomp')
-rw-r--r--ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/FindAction.java377
-rw-r--r--ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/package-info.java30
-rw-r--r--ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/custom/EcompFunctionDefinitionFactory.java85
-rw-r--r--ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngine.java64
-rw-r--r--ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngineFactory.java54
-rw-r--r--ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java123
-rw-r--r--ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/PolicyList.java60
7 files changed, 793 insertions, 0 deletions
diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/FindAction.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/FindAction.java
new file mode 100644
index 000000000..2c06f646c
--- /dev/null
+++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/FindAction.java
@@ -0,0 +1,377 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-PDP
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+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.ArrayList;
+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.Json;
+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.rest.XACMLRestProperties;
+
+import com.att.research.xacml.api.Advice;
+import com.att.research.xacml.api.Attribute;
+import com.att.research.xacml.api.AttributeAssignment;
+import com.att.research.xacml.api.AttributeValue;
+import com.att.research.xacml.api.Identifier;
+import com.att.research.xacml.api.Obligation;
+import com.att.research.xacml.api.Request;
+import com.att.research.xacml.api.RequestAttributes;
+import com.att.research.xacml.api.Result;
+import com.att.research.xacml.std.IdentifierImpl;
+import com.att.research.xacml.std.StdAdvice;
+import com.att.research.xacml.std.StdAttributeAssignment;
+import com.att.research.xacml.std.StdAttributeValue;
+import com.att.research.xacml.std.StdMutableResponse;
+import com.att.research.xacml.std.StdMutableResult;
+import com.att.research.xacml.std.StdObligation;
+import com.att.research.xacml.util.XACMLProperties;
+
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+
+public class FindAction {
+ private Logger logger = (Logger) FlexLogger.getLogger(this.getClass());
+ private Boolean changeIt = false;
+ private String configURL = null;
+ private StdMutableResponse newResponse = new StdMutableResponse();
+ private StdMutableResult addResult = new StdMutableResult();
+
+ public StdMutableResponse run(StdMutableResponse stdResponse, Request pepRequest) {
+ int count = 0;
+ boolean config = false;
+ boolean decide = false;
+ Collection<RequestAttributes> requestAttributes = pepRequest.getRequestAttributes();
+ for(RequestAttributes requestAttribute : requestAttributes){
+ Collection<Attribute> attributes = requestAttribute.getAttributes();
+ for(Attribute attribute : attributes){
+ if(attribute.getAttributeId().stringValue().equals("urn:oasis:names:tc:xacml:1.0:action:action-id")){
+ for(AttributeValue<?> attributeValue : attribute.getValues()){
+ if(attributeValue.getValue().toString().equalsIgnoreCase("ACCESS")){
+ count++;
+ }
+ if(attributeValue.getValue().toString().equalsIgnoreCase("DECIDE")){
+ decide = true;
+ }
+ }
+ }
+ if(attribute.getAttributeId().stringValue().equals("urn:oasis:names:tc:xacml:1.0:resource:resource-id")){
+ for(AttributeValue<?> attributeValue : attribute.getValues()){
+ if(attributeValue.getValue().toString().equalsIgnoreCase("Config")){
+ count++;
+ }
+ }
+ }
+ }
+ }
+ if(count==2){
+ config = true;
+ }
+ if(!config){
+ search(stdResponse);
+ }
+ addResults(stdResponse, config , decide);
+ 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 boolean header = false;
+
+ private void search(StdMutableResponse stdResponse) {
+ for (Result result : stdResponse.getResults()) {
+ if (!result.getObligations().isEmpty()) {
+ System.out.println("Obligation Received");
+ // Is there any action that PDP needs to take
+ for (Obligation obligation : result.getObligations()) {
+ int count = 0, uri = 0, PEP = 0;
+ header = false;
+ changeIt = false;
+ Collection<AttributeAssignment> afterRemoveAssignments = new ArrayList<AttributeAssignment>();
+ Identifier oblId = new IdentifierImpl(obligation.getId().stringValue());
+ StdAttributeAssignment attributeURI = null;
+ for (AttributeAssignment attribute : obligation.getAttributeAssignments()) {
+ matchValues.put(attribute.getAttributeId().stringValue(), attribute.getAttributeValue().getValue().toString());
+ if (attribute.getAttributeId().stringValue().equalsIgnoreCase("performer")) {
+ if (attribute.getAttributeValue().getValue().toString().equalsIgnoreCase("PEPACTION")) {
+ PEP++;
+ } else if (attribute.getAttributeValue().getValue().toString().equalsIgnoreCase("PDPACTION")) {
+ count++;
+ }
+ } else if (attribute.getAttributeId().stringValue().equalsIgnoreCase("URL")) {
+ uri++;
+ if (uri == 1) {
+ configURL = attribute.getAttributeValue().getValue().toString();
+ attributeURI = new StdAttributeAssignment(attribute);
+ }
+ } else if (attribute.getAttributeId().stringValue().startsWith("headers")) {
+ logger.info("Headers are : "+ attribute.getAttributeValue().getValue().toString());
+ header = true;
+ headers.put(attribute.getAttributeId().stringValue().replaceFirst("(headers).", ""),
+ attribute.getAttributeValue().getValue().toString());
+ afterRemoveAssignments.add(attribute);
+ } else if (attribute.getAttributeId().stringValue().equalsIgnoreCase("body")) {
+ 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 {
+ 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);
+ } else if (PEP == 1 && count == 0) {
+ // Strip the PEPACTION if available
+ if (uri == 1) {
+ afterRemoveAssignments.add(attributeURI);
+ }
+ Obligation afterRemoveObligation = new StdObligation(
+ oblId, afterRemoveAssignments);
+ obligations.add(afterRemoveObligation);
+ } else {
+ obligations.add(obligation);
+ }
+ }
+ }
+ }
+ }
+
+ private void TakeAction(StdMutableResponse stdResponse, Identifier advId,
+ Collection<AttributeAssignment> afterRemoveAssignments) {
+ if (changeIt) {
+ 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");
+ Identifier statId = new IdentifierImpl(
+ "com:att:labs: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");
+ 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>(
+ strId, status + response);
+ AttributeValue<String> attributeResourceValue = new StdAttributeValue<String>(
+ urlId, configURL);
+ StdAttributeAssignment attributeStatus = new StdAttributeAssignment(
+ statCategory, statId, "PDP", attributeStatusValue);
+ StdAttributeAssignment attributeResouce = new StdAttributeAssignment(
+ resCategory, resId, "PDP", attributeResourceValue);
+ afterRemoveAssignments.add(attributeStatus);
+ afterRemoveAssignments.add(attributeResouce);
+ Advice advice = new StdAdvice(id, afterRemoveAssignments);
+ addResult.addAdvice(advice);
+ }
+ }
+
+ private void addResults(StdMutableResponse stdResponse, boolean config, boolean decide) {
+ if(decide){
+ newResponse = stdResponse;
+ return;
+ }
+ for (Result result : stdResponse.getResults()) {
+ if(config){
+ addResult.addAdvice(result.getAssociatedAdvice());
+ }
+ addResult.addAttributeCategories(result.getAttributes());
+ addResult.addPolicyIdentifiers(result.getPolicyIdentifiers());
+ addResult.addPolicySetIdentifiers(result.getPolicySetIdentifiers());
+ addResult.setStatus(result.getStatus());
+ addResult.setDecision(result.getDecision());
+ if(!config){
+ addResult.addObligations(obligations);
+ }
+ }
+ newResponse.add(addResult);
+ }
+
+ private int status;
+ private String response;
+
+ private void callRest() {
+ // Finding the Macros in the URL..
+ Pattern pattern = Pattern.compile("\\$([a-zA-Z0-9.:]*)");
+ Matcher match = pattern.matcher(configURL);
+ StringBuffer sb = new StringBuffer();
+ while (match.find()) {
+ logger.info("Found Macro : " + match.group(1));
+ String replaceValue = matchValues.get(match.group(1));
+ logger.info("Replacing with :" + replaceValue);
+ match.appendReplacement(sb, replaceValue);
+ }
+ match.appendTail(sb);
+ logger.info("URL is : " + sb.toString());
+ configURL = sb.toString();
+ // Calling the Requested service.
+ if (matchValues.get("method").equalsIgnoreCase("GET")) {
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+ try {
+ HttpGet getRequest = new HttpGet(configURL);
+ // Adding Headers here
+ if (header) {
+ for (String key : headers.keySet()) {
+ getRequest.addHeader(key, headers.get(key));
+ }
+ }
+ HttpResponse result = httpClient.execute(getRequest);
+ status = result.getStatusLine().getStatusCode();
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ (result.getEntity().getContent())));
+ String output = " ";
+ String out;
+ while ((out = br.readLine()) != null) {
+ output = output + out;
+ }
+ response = output;
+ } catch (ClientProtocolException e) {
+ response = e.getMessage();
+ } catch (IOException e) {
+ response = e.getMessage();
+ } finally {
+ httpClient.getConnectionManager().shutdown();
+ }
+ } else if(matchValues.get("method").equalsIgnoreCase("POST")) {
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+ try {
+ HttpPost postRequest = new HttpPost(configURL);
+ // Adding Headers here
+ if (header) {
+ for (String key : headers.keySet()) {
+ postRequest.addHeader(key, headers.get(key));
+ }
+ }
+ // Adding the Body.
+ URL configURL = new URL(matchValues.get("body"));
+ URLConnection connection = null;
+ connection = configURL.openConnection();
+ // InputStream in = connection.getInputStrem();
+ // 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());
+ status = result.getStatusLine().getStatusCode();
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ (result.getEntity().getContent())));
+ String output = " ";
+ String out;
+ while ((out = br.readLine()) != null) {
+ output = output + out;
+ }
+ response = output;
+ } catch (ClientProtocolException e) {
+ response = e.getMessage();
+ } catch (IOException e) {
+ response = e.getMessage();
+ } finally {
+ httpClient.getConnectionManager().shutdown();
+ }
+ } else if(matchValues.get("method").equalsIgnoreCase("PUT")) {
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+ try {
+ HttpPut putRequest = new HttpPut(configURL);
+ // Adding Headers here
+ if (header) {
+ for (String key : headers.keySet()) {
+ putRequest.addHeader(key, headers.get(key));
+ }
+ }
+ // Adding the Body.
+ URL configURL = new URL(matchValues.get("body"));
+ URLConnection connection = null;
+ connection = configURL.openConnection();
+ //InputStream in = connection.getInputStream();
+ //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");
+ putRequest.setEntity(input);
+ // Executing the Request.
+ HttpResponse result = httpClient.execute(putRequest);
+ status = result.getStatusLine().getStatusCode();
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ (result.getEntity().getContent())));
+ String output = " ";
+ String out;
+ while ((out = br.readLine()) != null) {
+ output = output + out;
+ }
+ response = output;
+ } catch (ClientProtocolException e) {
+ response = e.getMessage();
+ } catch (IOException e) {
+ response = e.getMessage();
+ } finally {
+ httpClient.getConnectionManager().shutdown();
+ }
+ }
+ }
+}
diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/package-info.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/package-info.java
new file mode 100644
index 000000000..88ecc78c2
--- /dev/null
+++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/package-info.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-PDP
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.xacml.action;
+
+/**
+ * org.openecomp.policy.xacml.action contains the implementation of the PDP Actions.
+ * Changes:
+ * Now PDP supports actions based on PUT, GET, POST methods
+ *
+ * @version 0.2
+ *
+ */
diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/custom/EcompFunctionDefinitionFactory.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/custom/EcompFunctionDefinitionFactory.java
new file mode 100644
index 000000000..d6d664ab6
--- /dev/null
+++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/custom/EcompFunctionDefinitionFactory.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-PDP
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.policy.xacml.custom;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.openecomp.policy.xacml.pdp.std.functions.FunctionDefinitionCustomRegexpMatch;
+
+import com.att.research.xacml.api.Identifier;
+import com.att.research.xacml.std.IdentifierImpl;
+import com.att.research.xacml.std.datatypes.DataTypes;
+import com.att.research.xacmlatt.pdp.policy.FunctionDefinition;
+import com.att.research.xacmlatt.pdp.policy.FunctionDefinitionFactory;
+import com.att.research.xacmlatt.pdp.std.StdFunctions;
+
+public class EcompFunctionDefinitionFactory extends FunctionDefinitionFactory {
+ private static Map<Identifier,FunctionDefinition> mapFunctionDefinitions = new HashMap<Identifier,FunctionDefinition>();
+ private static boolean needMapInit = true;
+
+ public static final Identifier ID_FUNCTION_CUSTOM_REGEXP_MATCH = new IdentifierImpl("org.openecomp.function.regex-match");
+
+ private static final FunctionDefinition FD_CUSTOM_REGEXP_MATCH = new FunctionDefinitionCustomRegexpMatch<String>(ID_FUNCTION_CUSTOM_REGEXP_MATCH, DataTypes.DT_STRING);
+
+ private static void register(FunctionDefinition functionDefinition) {
+ mapFunctionDefinitions.put(functionDefinition.getId(), functionDefinition);
+ }
+
+ private static void initMap() {
+ if (needMapInit) {
+ synchronized(mapFunctionDefinitions) {
+ if (needMapInit) {
+ needMapInit = false;
+ Field[] declaredFields = StdFunctions.class.getDeclaredFields();
+ for (Field field : declaredFields) {
+ if (Modifier.isStatic(field.getModifiers()) &&
+ field.getName().startsWith(StdFunctions.FD_PREFIX) &&
+ FunctionDefinition.class.isAssignableFrom(field.getType()) &&
+ Modifier.isPublic(field.getModifiers())
+ ) {
+ try {
+ register((FunctionDefinition)(field.get(null)));
+ } catch (IllegalAccessException ex) {
+
+ }
+ }
+ }
+ //
+ // Our custom function
+ //
+ //register(FunctionDefinitionCustomRegexpMatch);
+ register(FD_CUSTOM_REGEXP_MATCH);
+ }
+ }
+ }
+ }
+
+ public EcompFunctionDefinitionFactory() {
+ initMap();
+ }
+
+ @Override
+ public FunctionDefinition getFunctionDefinition(Identifier functionId) {
+ return mapFunctionDefinitions.get(functionId);
+ }
+}
diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngine.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngine.java
new file mode 100644
index 000000000..d1d6ebc90
--- /dev/null
+++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngine.java
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-PDP
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.policy.xacml.pdp;
+
+import java.util.Properties;
+
+import org.openecomp.policy.xacml.action.FindAction;
+
+import com.att.research.xacml.api.Decision;
+import com.att.research.xacml.api.Request;
+import com.att.research.xacml.api.Response;
+import com.att.research.xacml.api.pdp.PDPException;
+import com.att.research.xacml.api.pdp.ScopeResolver;
+import com.att.research.xacml.std.StdMutableResponse;
+import com.att.research.xacmlatt.pdp.ATTPDPEngine;
+import com.att.research.xacmlatt.pdp.eval.EvaluationContextFactory;
+
+public class ECOMPPDPEngine extends ATTPDPEngine {
+
+ public ECOMPPDPEngine(EvaluationContextFactory evaluationContextFactoryIn, Decision defaultDecisionIn,
+ ScopeResolver scopeResolverIn, Properties properties) {
+ super(evaluationContextFactoryIn, defaultDecisionIn, scopeResolverIn, properties);
+ // TODO Auto-generated constructor stub
+ }
+
+ public ECOMPPDPEngine(EvaluationContextFactory evaluationContextFactoryIn, Decision defaultDecisionIn,
+ ScopeResolver scopeResolverIn) {
+ super(evaluationContextFactoryIn, defaultDecisionIn, scopeResolverIn);
+ // TODO Auto-generated constructor stub
+ }
+
+ public ECOMPPDPEngine(EvaluationContextFactory evaluationContextFactoryIn, ScopeResolver scopeResolverIn) {
+ super(evaluationContextFactoryIn, scopeResolverIn);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public Response decide(Request pepRequest) throws PDPException {
+ // TODO Auto-generated method stub
+ Response response = super.decide(pepRequest);
+
+ FindAction findAction = new FindAction();
+ return findAction.run((StdMutableResponse) response, pepRequest);
+ }
+
+
+}
diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngineFactory.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngineFactory.java
new file mode 100644
index 000000000..437eb69b5
--- /dev/null
+++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngineFactory.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-PDP
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.policy.xacml.pdp;
+
+import java.util.Properties;
+
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.Logger;
+import com.att.research.xacml.api.pdp.PDPEngine;
+import com.att.research.xacml.api.pdp.PDPEngineFactory;
+import com.att.research.xacml.util.FactoryException;
+import com.att.research.xacmlatt.pdp.eval.EvaluationContextFactory;
+
+public class ECOMPPDPEngineFactory extends PDPEngineFactory {
+ private Logger logger = FlexLogger.getLogger(this.getClass());
+
+ @Override
+ public PDPEngine newEngine() throws FactoryException {
+ EvaluationContextFactory evaluationContextFactory = EvaluationContextFactory.newInstance();
+ if (evaluationContextFactory == null) {
+ this.logger.error("Null EvaluationContextFactory");
+ throw new FactoryException("Null EvaluationContextFactory");
+ }
+ return new ECOMPPDPEngine(evaluationContextFactory, this.getDefaultBehavior(), this.getScopeResolver());
+ }
+
+ @Override
+ public PDPEngine newEngine(Properties properties) throws FactoryException {
+ EvaluationContextFactory evaluationContextFactory = EvaluationContextFactory.newInstance(properties);
+ if (evaluationContextFactory == null) {
+ this.logger.error("Null EvaluationContextFactory");
+ throw new FactoryException("Null EvaluationContextFactory");
+ }
+ return new ECOMPPDPEngine(evaluationContextFactory, this.getDefaultBehavior(), this.getScopeResolver(), properties);
+ }
+
+}
diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java
new file mode 100644
index 000000000..9e63052a4
--- /dev/null
+++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java
@@ -0,0 +1,123 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-PDP
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.policy.xacml.pdp.std.functions;
+
+
+import java.util.List;
+
+import com.att.research.xacml.api.DataType;
+import com.att.research.xacml.api.DataTypeException;
+import com.att.research.xacml.api.Identifier;
+import com.att.research.xacml.std.StdStatus;
+import com.att.research.xacml.std.StdStatusCode;
+import com.att.research.xacml.std.datatypes.DataTypes;
+import com.att.research.xacmlatt.pdp.eval.EvaluationContext;
+import com.att.research.xacmlatt.pdp.policy.ExpressionResult;
+import com.att.research.xacmlatt.pdp.policy.FunctionArgument;
+import com.att.research.xacmlatt.pdp.std.functions.ConvertedArgument;
+import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBase;
+
+/**
+ * FunctionDefinitionCustomRegexMatch implements {@link com.att.research.xacmlatt.pdp.policy.FunctionDefinition} to
+ * implement the custom 'type'-regex-match predicates as functions taking two arguments, the first of <code>String</code>,
+ * and the second of the type for that specific predicate as a regular expression,
+ * and returning a <code>Boolean</code> for whether the regular expression matches the string representation of the first argument.
+ *
+ *
+ * @version $Revision: 0.1 $
+ *
+ * @param <I> the java class for the data type of the function Input arguments
+ */
+public class FunctionDefinitionCustomRegexpMatch<I> extends FunctionDefinitionBase<Boolean, I> {
+
+
+ /**
+ * Constructor - need dataTypeArgs input because of java Generic type-erasure during compilation.
+ *
+ * @param idIn
+ * @param dataTypeArgsIn
+ */
+ public FunctionDefinitionCustomRegexpMatch(Identifier idIn, DataType<I> dataTypeArgsIn) {
+ super(idIn, DataTypes.DT_BOOLEAN, dataTypeArgsIn, false);
+ }
+
+
+ @Override
+ public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) {
+
+ if (arguments == null || arguments.size() != 2) {
+ return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " +
+ ((arguments == null) ? "null" : arguments.size()) ));
+ }
+
+ // get the regular expression
+ FunctionArgument regexpArgument = arguments.get(0);
+
+ ConvertedArgument<String> convertedArgument = new ConvertedArgument<String>(regexpArgument, DataTypes.DT_STRING, false);
+ if ( ! convertedArgument.isOk()) {
+ return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus()));
+ }
+
+ // String regexpValue = (String)regexpArgument.getValue().getValue();
+ String regexpValue = convertedArgument.getValue();
+
+
+ // now get the element to match
+ FunctionArgument elementArgument = arguments.get(1);
+
+ ConvertedArgument<I> convertedElement = new ConvertedArgument<I>(elementArgument, this.getDataTypeArgs(), false);
+ if ( ! convertedElement.isOk()) {
+ return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus()));
+ }
+
+ I elementValueObject = convertedElement.getValue();
+
+ String elementValueString;
+ try {
+ elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject);
+ } catch (DataTypeException e) {
+ String message = e.getMessage();
+ if (e.getCause() != null) {
+ message = e.getCause().getMessage();
+ }
+ return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message));
+ }
+
+ // ConvertedArgument checks for null value, so do not need to do again here
+
+ // Adding this code will Change the Functionality which allows to retrieve Multiple-policy using single request.
+ elementValueString = elementValueString + regexpValue ;
+ regexpValue = elementValueString.substring(0,(elementValueString.length()- regexpValue.length()));
+ elementValueString = elementValueString.substring(regexpValue.length(),(elementValueString.length()));
+ //
+
+ if (elementValueString.matches(regexpValue)) {
+ return ER_TRUE;
+ } else {
+ return ER_FALSE;
+ }
+
+ }
+
+
+
+
+
+}
diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/PolicyList.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/PolicyList.java
new file mode 100644
index 000000000..24ef2f72e
--- /dev/null
+++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/PolicyList.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-PDP
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.policy.xacml.pdp.std.functions;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.Logger;
+/**
+ * Creates a list of policy ids.
+ *
+ * @version $Revision: 1.3 $
+ */
+public class PolicyList {
+
+// private static Map<String, Integer> policyMap = new HashMap<>();
+ private static List<String> policyList = new ArrayList<String>();
+ private Logger logger = FlexLogger.getLogger(this.getClass());
+
+
+ public static List<String> getpolicyList(){
+ return policyList;
+ }
+
+ public static void addPolicyID(String policyID){
+ if (!policyList.contains(policyID)){
+ policyList.add(policyID);
+ }
+ // policyMap.put(policyID, count);
+ }
+
+ public static void clearPolicyList(){
+ // policyMap.clear();
+ if (!policyList.isEmpty()){
+ policyList.clear();
+ }
+ }
+}