aboutsummaryrefslogtreecommitdiffstats
path: root/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp
diff options
context:
space:
mode:
Diffstat (limited to 'ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp')
-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
4 files changed, 301 insertions, 0 deletions
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();
+ }
+ }
+}