aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp')
-rw-r--r--ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/ONAPPDPEngineFactory.java54
-rw-r--r--ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/OnapPdpEngine.java (renamed from ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/ONAPPDPEngine.java)62
-rw-r--r--ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/OnapPdpEngineFactory.java57
-rw-r--r--ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java191
-rw-r--r--ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/std/functions/PolicyList.java56
5 files changed, 220 insertions, 200 deletions
diff --git a/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/ONAPPDPEngineFactory.java b/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/ONAPPDPEngineFactory.java
deleted file mode 100644
index 2e796bf68..000000000
--- a/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/ONAPPDPEngineFactory.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP-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.onap.policy.xacml.pdp;
-
-import java.util.Properties;
-
-import org.onap.policy.common.logging.flexlogger.FlexLogger;
-import org.onap.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 ONAPPDPEngineFactory 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 ONAPPDPEngine(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 ONAPPDPEngine(evaluationContextFactory, this.getDefaultBehavior(), this.getScopeResolver(), properties);
- }
-
-}
diff --git a/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/ONAPPDPEngine.java b/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/OnapPdpEngine.java
index fb90d0a2e..42ab7e415 100644
--- a/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/ONAPPDPEngine.java
+++ b/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/OnapPdpEngine.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP-PDP
* ================================================================================
- * 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.
* 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.
@@ -17,11 +17,8 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.xacml.pdp;
-
-import java.util.Properties;
-import org.onap.policy.xacml.action.FindAction;
+package org.onap.policy.xacml.pdp;
import com.att.research.xacml.api.Decision;
import com.att.research.xacml.api.Request;
@@ -32,29 +29,34 @@ import com.att.research.xacml.std.StdMutableResponse;
import com.att.research.xacmlatt.pdp.ATTPDPEngine;
import com.att.research.xacmlatt.pdp.eval.EvaluationContextFactory;
-public class ONAPPDPEngine extends ATTPDPEngine {
-
- public ONAPPDPEngine(EvaluationContextFactory evaluationContextFactoryIn, Decision defaultDecisionIn,
- ScopeResolver scopeResolverIn, Properties properties) {
- super(evaluationContextFactoryIn, defaultDecisionIn, scopeResolverIn, properties);
- }
-
- public ONAPPDPEngine(EvaluationContextFactory evaluationContextFactoryIn, Decision defaultDecisionIn,
- ScopeResolver scopeResolverIn) {
- super(evaluationContextFactoryIn, defaultDecisionIn, scopeResolverIn);
- }
-
- public ONAPPDPEngine(EvaluationContextFactory evaluationContextFactoryIn, ScopeResolver scopeResolverIn) {
- super(evaluationContextFactoryIn, scopeResolverIn);
- }
-
- @Override
- public Response decide(Request pepRequest) throws PDPException {
- Response response = super.decide(pepRequest);
-
- FindAction findAction = new FindAction();
- return findAction.run((StdMutableResponse) response, pepRequest);
- }
+import java.util.Properties;
+
+import org.onap.policy.xacml.action.FindAction;
+
+public class OnapPdpEngine extends ATTPDPEngine {
+
+ public OnapPdpEngine(final EvaluationContextFactory evaluationContextFactoryIn, final Decision defaultDecisionIn,
+ final ScopeResolver scopeResolverIn, final Properties properties) {
+ super(evaluationContextFactoryIn, defaultDecisionIn, scopeResolverIn, properties);
+ }
+
+ public OnapPdpEngine(final EvaluationContextFactory evaluationContextFactoryIn, final Decision defaultDecisionIn,
+ final ScopeResolver scopeResolverIn) {
+ super(evaluationContextFactoryIn, defaultDecisionIn, scopeResolverIn);
+ }
+
+ public OnapPdpEngine(final EvaluationContextFactory evaluationContextFactoryIn,
+ final ScopeResolver scopeResolverIn) {
+ super(evaluationContextFactoryIn, scopeResolverIn);
+ }
+
+ @Override
+ public Response decide(final Request pepRequest) throws PDPException {
+ final Response response = super.decide(pepRequest);
+
+ final FindAction findAction = new FindAction();
+ return findAction.run((StdMutableResponse) response, pepRequest);
+ }
}
diff --git a/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/OnapPdpEngineFactory.java b/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/OnapPdpEngineFactory.java
new file mode 100644
index 000000000..c19c4012a
--- /dev/null
+++ b/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/OnapPdpEngineFactory.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PDP
+ * ================================================================================
+ * 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.
+ * 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.onap.policy.xacml.pdp;
+
+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;
+
+import java.util.Properties;
+
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+
+public class OnapPdpEngineFactory extends PDPEngineFactory {
+ private Logger logger = FlexLogger.getLogger(this.getClass());
+
+ @Override
+ public PDPEngine newEngine() throws FactoryException {
+ final EvaluationContextFactory evaluationContextFactory = EvaluationContextFactory.newInstance();
+ if (evaluationContextFactory == null) {
+ this.logger.error("Null EvaluationContextFactory");
+ throw new FactoryException("Null EvaluationContextFactory");
+ }
+ return new OnapPdpEngine(evaluationContextFactory, this.getDefaultBehavior(), this.getScopeResolver());
+ }
+
+ @Override
+ public PDPEngine newEngine(final Properties properties) throws FactoryException {
+ final EvaluationContextFactory evaluationContextFactory = EvaluationContextFactory.newInstance(properties);
+ if (evaluationContextFactory == null) {
+ this.logger.error("Null EvaluationContextFactory");
+ throw new FactoryException("Null EvaluationContextFactory");
+ }
+ return new OnapPdpEngine(evaluationContextFactory, this.getDefaultBehavior(), this.getScopeResolver(),
+ properties);
+ }
+
+}
diff --git a/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java b/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java
index 590d519cc..a8b0e9d15 100644
--- a/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java
+++ b/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP-PDP
* ================================================================================
- * 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.
* 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.
@@ -17,13 +17,8 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.xacml.pdp.std.functions;
-
-
-import java.util.List;
-import org.onap.policy.common.logging.flexlogger.FlexLogger;
-import org.onap.policy.common.logging.flexlogger.Logger;
+package org.onap.policy.xacml.pdp.std.functions;
import com.att.research.xacml.api.DataType;
import com.att.research.xacml.api.DataTypeException;
@@ -37,94 +32,104 @@ 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;
+import java.util.List;
+
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+
/**
* 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.
- *
- *
+ * 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.2 $
- *
+ *
* @param <I> the java class for the data type of the function Input arguments
*/
public class FunctionDefinitionCustomRegexpMatch<I> extends FunctionDefinitionBase<Boolean, I> {
- private static Logger logger = FlexLogger.getLogger(FunctionDefinitionCustomRegexpMatch.class);
-
- /**
- * 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<>(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<>(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) {
- logger.error(e.getMessage() +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()));
- //
- // Supporting multiple values in the element and be able to query them.
- if(elementValueString.contains(",")){
- String[] elements = elementValueString.split(",");
- for(int i=0; i<elements.length; i++){
- if(elements[i].trim().matches(regexpValue)) {
- return ER_TRUE;
- }
- }
- }
- if (elementValueString.matches(regexpValue)) {
- return ER_TRUE;
- } else {
- return ER_FALSE;
- }
-
- }
+ private static Logger logger = FlexLogger.getLogger(FunctionDefinitionCustomRegexpMatch.class);
+
+ /**
+ * Constructor - need dataTypeArgs input because of java Generic type-erasure during compilation.
+ *
+ * @param idIn the identifier
+ * @param dataTypeArgsIn the data type
+ */
+ public FunctionDefinitionCustomRegexpMatch(final Identifier idIn, final DataType<I> dataTypeArgsIn) {
+ super(idIn, DataTypes.DT_BOOLEAN, dataTypeArgsIn, false);
+ }
+
+
+ @Override
+ public ExpressionResult evaluate(final EvaluationContext evaluationContext,
+ final 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
+ final FunctionArgument regexpArgument = arguments.get(0);
+
+ final ConvertedArgument<String> convertedArgument =
+ new ConvertedArgument<>(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
+ final FunctionArgument elementArgument = arguments.get(1);
+
+ final ConvertedArgument<I> convertedElement =
+ new ConvertedArgument<>(elementArgument, this.getDataTypeArgs(), false);
+ if (!convertedElement.isOk()) {
+ return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus()));
+ }
+
+ final I elementValueObject = convertedElement.getValue();
+
+ String elementValueString;
+ try {
+ elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject);
+ } catch (final DataTypeException e) {
+ logger.error(e.getMessage() + 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()));
+ //
+ // Supporting multiple values in the element and be able to query them.
+ if (elementValueString.contains(",")) {
+ final String[] elements = elementValueString.split(",");
+ for (int i = 0; i < elements.length; i++) {
+ if (elements[i].trim().matches(regexpValue)) {
+ return ER_TRUE;
+ }
+ }
+ }
+ if (elementValueString.matches(regexpValue)) {
+ return ER_TRUE;
+ } else {
+ return ER_FALSE;
+ }
+
+ }
}
diff --git a/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/std/functions/PolicyList.java b/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/std/functions/PolicyList.java
index 794276f6a..13b517dd6 100644
--- a/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/std/functions/PolicyList.java
+++ b/ONAP-PDP/src/main/java/org/onap/policy/xacml/pdp/std/functions/PolicyList.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP-PDP
* ================================================================================
- * 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.
* 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.
@@ -17,33 +17,43 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.xacml.pdp.std.functions;
import java.util.ArrayList;
import java.util.List;
+
/**
* Creates a list of policy ids.
- *
+ *
* @version $Revision: 1.3 $
*/
public class PolicyList {
-
- private static List<String> policyList = new ArrayList<>();
-
-
- public static List<String> getpolicyList(){
- return policyList;
- }
-
- public static void addPolicyID(String policyID){
- if (!policyList.contains(policyID)){
- policyList.add(policyID);
- }
- }
-
- public static void clearPolicyList(){
- if (!policyList.isEmpty()){
- policyList.clear();
- }
- }
+
+ private static List<String> policyList = new ArrayList<>();
+
+
+ public static List<String> getpolicyList() {
+ return policyList;
+ }
+
+ /**
+ * Add policy id in the policy list.
+ *
+ * @param policyId the policy id
+ */
+ public static void addPolicyId(final String policyId) {
+ if (!policyList.contains(policyId)) {
+ policyList.add(policyId);
+ }
+ }
+
+ /**
+ * Clear policy list.
+ */
+ public static void clearPolicyList() {
+ if (!policyList.isEmpty()) {
+ policyList.clear();
+ }
+ }
}