You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openaz.apache.org by co...@apache.org on 2015/07/15 15:11:47 UTC

incubator-openaz git commit: Misc improvements

Repository: incubator-openaz
Updated Branches:
  refs/heads/master bf9799986 -> 01ef51b29


Misc improvements


Project: http://git-wip-us.apache.org/repos/asf/incubator-openaz/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-openaz/commit/01ef51b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-openaz/tree/01ef51b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-openaz/diff/01ef51b2

Branch: refs/heads/master
Commit: 01ef51b292e553be80b29b9e6b8b6676d493b2f8
Parents: bf97999
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Wed Jul 15 14:11:38 2015 +0100
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Wed Jul 15 14:11:38 2015 +0100

----------------------------------------------------------------------
 .../pdp/std/StdEvaluationContextFactory.java    |  2 +-
 .../openaz/xacml/pdp/std/StdPolicyFinder.java   | 23 +++++----------
 .../xacml/pdp/std/StdPolicyFinderFactory.java   | 31 +++++++++-----------
 .../openaz/xacml/util/XACMLPolicyScanner.java   |  9 ++----
 4 files changed, 24 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/01ef51b2/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdEvaluationContextFactory.java
----------------------------------------------------------------------
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 @@ public class StdEvaluationContextFactory extends EvaluationContextFactory {
      * 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

http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/01ef51b2/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdPolicyFinder.java
----------------------------------------------------------------------
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 @@ public class StdPolicyFinder implements PolicyFinder {
     }
 
     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;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/01ef51b2/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/StdPolicyFinderFactory.java
----------------------------------------------------------------------
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 @@ public class StdPolicyFinderFactory extends PolicyFinderFactory {
         }
 
         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());
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/01ef51b2/openaz-xacml/src/main/java/org/apache/openaz/xacml/util/XACMLPolicyScanner.java
----------------------------------------------------------------------
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.JAXBContext;
 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.StdAttributeAssignment;
 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 class XACMLPolicyScanner {
     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,