Misc improvements
diff --git a/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdEvaluationContextFactory.java b/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdEvaluationContextFactory.java
index 92267ca..c2e0ec9 100644
--- a/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdEvaluationContextFactory.java
+++ b/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdEvaluationContextFactory.java
@@ -60,7 +60,7 @@
* yes, then we are assuming that the given properties were not just meant to configure the evaluation
* context, but all the other engines that get created. If no, then we are assuming the given properties
* were only meant for the evaluation context. But this implementation as of 7/14 does not even need the
- * properties for configuring itseof. The problem is, the caller does not have the ability to instantiate
+ * properties for configuring itself. The problem is, the caller does not have the ability to instantiate
* the PIPFinder and PolicyFinder engines. This is done internally by the evaluation context. So how can
* they have the ability to customize PIP/Policy factories with their own properties object if the
* properties file isn't passed on? Thus, this class will pass on the properties file if given in the
diff --git a/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdPolicyFinder.java b/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdPolicyFinder.java
index 6b16c0b..f16febe 100644
--- a/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdPolicyFinder.java
+++ b/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdPolicyFinder.java
@@ -177,32 +177,23 @@
}
private PolicyDef loadPolicyDefFromURI(URI uri) throws StdPolicyFinderException {
- PolicyDef policyDef = null;
- InputStream inputStream = null;
+ this.logger.info("Loading policy from URI " + uri.toString());
+ URL url = null;
try {
- this.logger.info("Loading policy from URI " + uri.toString());
- URL url = uri.toURL();
+ url = uri.toURL();
this.logger.debug("Loading policy from URL " + url.toString());
-
- inputStream = url.openStream();
- policyDef = DOMPolicyDef.load(inputStream);
} catch (MalformedURLException ex) {
this.logger.debug("Unknown protocol for URI " + uri.toString());
return null;
+ }
+
+ try (InputStream inputStream = url.openStream()) {
+ return DOMPolicyDef.load(inputStream);
} catch (Exception ex) {
this.logger.error("Exception loading policy definition", ex);
throw new StdPolicyFinderException("Exception loading policy def from \"" + uri.toString()
+ "\": " + ex.getMessage(), ex);
- } finally {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (Exception ex) { //NOPMD
- // TODO
- }
- }
}
- return policyDef;
}
/**
diff --git a/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdPolicyFinderFactory.java b/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdPolicyFinderFactory.java
index c76ce45..5809f2d 100644
--- a/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdPolicyFinderFactory.java
+++ b/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdPolicyFinderFactory.java
@@ -111,31 +111,28 @@
}
if ((propLocation = properties.getProperty(policyId + PROP_URL)) != null) {
- InputStream is = null;
+ URLConnection urlConnection = null;
try {
URL url = new URL(propLocation);
- URLConnection urlConnection = url.openConnection();
+ urlConnection = url.openConnection();
this.logger.info("Loading policy file " + url.toString());
- is = urlConnection.getInputStream();
- PolicyDef policyDef = DOMPolicyDef.load(is);
- if (policyDef != null) {
- return policyDef;
- }
} catch (MalformedURLException ex) {
this.logger.error("Invalid URL " + propLocation + ": " + ex.getMessage(), ex);
} catch (IOException ex) {
this.logger.error("IOException opening URL " + propLocation + ": " + ex.getMessage(), ex);
- } catch (DOMStructureException ex) {
- this.logger.error("Invalid Policy " + propLocation + ": " + ex.getMessage(), ex);
- return new Policy(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage());
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- this.logger.error("Exception closing InputStream for GET of url " + propLocation
- + " : " + e.getMessage() + " (May be memory leak)", e);
+ }
+
+ if (urlConnection != null) {
+ try (InputStream is = urlConnection.getInputStream()) {
+ PolicyDef policyDef = DOMPolicyDef.load(is);
+ if (policyDef != null) {
+ return policyDef;
}
+ } catch (IOException ex) {
+ this.logger.error("IOException opening URL " + propLocation + ": " + ex.getMessage(), ex);
+ } catch (DOMStructureException ex) {
+ this.logger.error("Invalid Policy " + propLocation + ": " + ex.getMessage(), ex);
+ return new Policy(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage());
}
}
}
diff --git a/openaz-xacml/src/main/java/org/apache/openaz/xacml/util/XACMLPolicyScanner.java b/openaz-xacml/src/main/java/org/apache/openaz/xacml/util/XACMLPolicyScanner.java
index a5e9694..0b5ab80 100644
--- a/openaz-xacml/src/main/java/org/apache/openaz/xacml/util/XACMLPolicyScanner.java
+++ b/openaz-xacml/src/main/java/org/apache/openaz/xacml/util/XACMLPolicyScanner.java
@@ -41,7 +41,6 @@
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
@@ -74,6 +73,7 @@
import org.apache.openaz.xacml.std.StdAttributeValue;
import org.apache.openaz.xacml.std.StdMutableAdvice;
import org.apache.openaz.xacml.std.StdMutableObligation;
+import org.apache.openaz.xacml.std.dom.DOMUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -830,14 +830,9 @@
public static Object readPolicy(InputStream is) {
try {
//
- // Create a DOM parser
- //
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- DocumentBuilder db = dbf.newDocumentBuilder();
- //
// Parse the policy file
//
+ DocumentBuilder db = DOMUtil.getDocumentBuilder();
Document doc = db.parse(is);
//
// Because there is no root defined in xacml,