X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=ONAP-XACML%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fxacml%2Futil%2FXACMLPolicyScanner.java;h=228354c4f489233e219aeeebf7ff14ab9e036138;hp=b8b19ec9327e55d1bc8a982ff2efe23ecb3d87e7;hb=d089848fdb0beef8446bdcf60cdb14e4655a93e5;hpb=4d503f398d2f309cc077b55b5f1cce4c4bd773e6
diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyScanner.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyScanner.java
index b8b19ec93..228354c4f 100644
--- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyScanner.java
+++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyScanner.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP-XACML
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 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,8 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.xacml.util;
+import com.att.research.xacml.api.AttributeAssignment;
+import com.att.research.xacml.std.IdentifierImpl;
+import com.att.research.xacml.std.StdAttribute;
+import com.att.research.xacml.std.StdAttributeAssignment;
+import com.att.research.xacml.std.StdAttributeValue;
+import com.att.research.xacml.std.StdMutableAdvice;
+import com.att.research.xacml.std.StdMutableObligation;
+import com.att.research.xacml.util.XACMLPolicyScanner.Callback;
+import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult;
+
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
@@ -33,26 +44,6 @@ import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import org.onap.policy.common.logging.eelf.MessageCodes;
-import org.onap.policy.common.logging.eelf.PolicyLogger;
-
-import com.att.research.xacml.api.AttributeAssignment;
-import com.att.research.xacml.std.IdentifierImpl;
-import com.att.research.xacml.std.StdAttribute;
-import com.att.research.xacml.std.StdAttributeAssignment;
-import com.att.research.xacml.std.StdAttributeValue;
-import com.att.research.xacml.std.StdMutableAdvice;
-import com.att.research.xacml.std.StdMutableObligation;
-import com.att.research.xacml.util.XACMLPolicyScanner.Callback;
-import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult;
-
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
@@ -62,7 +53,6 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeSelectorType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.IdReferenceType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType;
@@ -72,650 +62,603 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableDefinitionType;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.onap.policy.common.logging.eelf.MessageCodes;
+import org.onap.policy.common.logging.eelf.PolicyLogger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
/**
- * class XACMLPolicyScanner
- *
- * This class traverses the hierarchy of a XACML 3.0 policy. You can optionally pass a Callback class
- * and override any desired methods to retrieve information from a policy.
- *
+ * class XACMLPolicyScanner.
+ *
+ *
This class traverses the hierarchy of a XACML 3.0 policy. You can optionally pass a Callback class
+ * and override any desired methods to retrieve information from a policy.
+ *
*
*/
public class XACMLPolicyScanner {
-
- private static final Log logger = LogFactory.getLog(XACMLPolicyScanner.class);
- private Object policyObject = null;
- private Callback callback = null;
-
- public XACMLPolicyScanner(Path filename, Callback callback) {
- try (InputStream is = Files.newInputStream(filename)) {
- this.policyObject = XACMLPolicyScanner.readPolicy(is);
- } catch (IOException e) {
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyScanner", "Failed to read policy");
- }
- this.callback = callback;
- }
-
- public XACMLPolicyScanner(InputStream filename, Callback callback) {
- try (InputStream is = filename) {
- this.policyObject = XACMLPolicyScanner.readPolicy(is);
- } catch (IOException e) {
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyScanner", "Failed to read policy");
- }
- this.callback = callback;
- }
-
- public XACMLPolicyScanner(PolicySetType policySet, Callback callback) {
- this.policyObject = policySet;
- this.callback = callback;
- }
-
- public XACMLPolicyScanner(PolicySetType policySet) {
- this(policySet, null);
- }
-
- public XACMLPolicyScanner(PolicyType policy, Callback callback) {
- this.policyObject = policy;
- this.callback = callback;
- }
-
- public XACMLPolicyScanner(PolicyType policy) {
- this(policy, null);
- }
-
- /**
- * Sets the callback interface to be used.
- *
- * @param cb
- */
- public void setCallback(Callback cb) {
- this.callback = cb;
- }
-
- /**
- * Saves the given callback object then calls the scan() method.
- *
- * @param cb
- * @return
- */
- public Object scan(Callback cb) {
- this.callback = cb;
- return this.scan();
- }
-
- /**
- *
- * This begins the scanning of the contained object.
- *
- * @return - The PolicySet/Policy that was scanned.
- */
- public Object scan() {
- if (this.policyObject == null) {
- return null;
- }
- if (this.callback != null) {
- if (this.callback.onBeginScan(this.policyObject) == CallbackResult.STOP) {
- return this.policyObject;
- }
- }
- if (this.policyObject instanceof PolicyType) {
- this.scanPolicy(null, (PolicyType) this.policyObject);
- } else if (this.policyObject instanceof PolicySetType) {
- this.scanPolicySet(null, (PolicySetType) this.policyObject);
- } else {
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + "Unknown class type: " + this.policyObject.getClass().getCanonicalName());
- }
- if (this.callback != null) {
- this.callback.onFinishScan(this.policyObject);
- }
- return this.policyObject;
- }
-
- /**
- * This performs the scan of a PolicySet
- *
- * @param parent - Its parent PolicySet. Can be null if this is the root.
- * @param policySet - The PolicySet object.
- * @return CallbackResult - CONTINUE to continue, STOP to terminate scanning.
- */
- /**
- * @param parent
- * @param policySet
- * @return
- */
- protected CallbackResult scanPolicySet(PolicySetType parent, PolicySetType policySet) {
- if (logger.isTraceEnabled()) {
- logger.trace("scanning policy set: " + policySet.getPolicySetId() + " " + policySet.getDescription());
- }
- if (this.callback != null) {
- if (this.callback.onPreVisitPolicySet(parent, policySet) == CallbackResult.STOP) {
- return CallbackResult.STOP;
- }
- }
- //
- // Scan its info
- //
- if (this.scanTarget(policySet, policySet.getTarget()) == CallbackResult.STOP) {
- return CallbackResult.STOP;
- }
- if (this.scanObligations(policySet, policySet.getObligationExpressions()) == CallbackResult.STOP) {
- return CallbackResult.STOP;
- }
- if (this.scanAdvice(policySet, policySet.getAdviceExpressions()) == CallbackResult.STOP) {
- return CallbackResult.STOP;
- }
- //
- // Iterate the policy sets and/or policies
- //
- List> list = policySet.getPolicySetOrPolicyOrPolicySetIdReference();
- for (JAXBElement> element: list) {
- if ("PolicySet".equals(element.getName().getLocalPart())) {
- if (this.scanPolicySet(policySet, (PolicySetType)element.getValue()) == CallbackResult.STOP) {
- return CallbackResult.STOP;
- }
- } else if ("Policy".equals(element.getName().getLocalPart())) {
- if (this.scanPolicy(policySet, (PolicyType)element.getValue()) == CallbackResult.STOP) {
- return CallbackResult.STOP;
- }
- } else if (element.getValue() instanceof IdReferenceType) {
- if ("PolicySetIdReference".equals(element.getName().getLocalPart())) {
-
- } else if ("PolicyIdReference".equals(element.getName().getLocalPart())) {
-
- }
- } else {
- logger.warn("generating policy sets found unsupported element: " + element.getName().getNamespaceURI());
- }
- }
- if (this.callback != null) {
- if (this.callback.onPostVisitPolicySet(parent, policySet) == CallbackResult.STOP) {
- return CallbackResult.STOP;
- }
- }
- return CallbackResult.CONTINUE;
- }
-
- /**
- *
- * This performs scanning of the Policy object.
- *
- * @param parent - The parent PolicySet of the policy. This can be null if this is a root Policy.
- * @param policy - The policy being scanned.
- * @return CallbackResult - CONTINUE to continue, STOP to terminate scanning.
- */
- protected CallbackResult scanPolicy(PolicySetType parent, PolicyType policy) {
- if (logger.isTraceEnabled()) {
- logger.trace("scanning policy: " + policy.getPolicyId() + " " + policy.getDescription());
- }
- if (this.callback != null) {
- if (this.callback.onPreVisitPolicy(parent, policy) == CallbackResult.STOP) {
- return CallbackResult.STOP;
- }
- }
- //
- // Scan its info
- //
- if (this.scanTarget(policy, policy.getTarget()) == CallbackResult.STOP) {
- return CallbackResult.STOP;
- }
- if (this.scanVariables(policy, policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()) == CallbackResult.STOP) {
- return CallbackResult.STOP;
- }
- if (this.scanObligations(policy, policy.getObligationExpressions()) == CallbackResult.STOP) {
- return CallbackResult.STOP;
- }
- if (this.scanAdvice(policy, policy.getAdviceExpressions()) == CallbackResult.STOP) {
- return CallbackResult.STOP;
- }
- //
- // Iterate the rules
- //
- List