[jboss-cvs] JBossAS SVN: r71678 - in projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml: interfaces and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 3 03:05:52 EDT 2008


Author: anil.saldhana at jboss.com
Date: 2008-04-03 03:05:51 -0400 (Thu, 03 Apr 2008)
New Revision: 71678

Modified:
   projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/core/JBossRequestContext.java
   projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/core/JBossResponseContext.java
   projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/interfaces/RequestContext.java
   projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/interfaces/ResponseContext.java
Log:
SECURITY-175: getDocumentElement

Modified: projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/core/JBossRequestContext.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/core/JBossRequestContext.java	2008-04-03 07:02:29 UTC (rev 71677)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/core/JBossRequestContext.java	2008-04-03 07:05:51 UTC (rev 71678)
@@ -52,6 +52,8 @@
 public class JBossRequestContext implements RequestContext
 {
    private Map<String, Object> map = new HashMap<String, Object>();
+   
+   private Node documentElement = null;
 
    /**
     * @see ContextMapOp#get(String)
@@ -69,8 +71,17 @@
    {
       map.put(key, obj);
    }
+   
 
    /**
+    * @see RequestContext#getDocumentElement()
+    */
+   public Node getDocumentElement()
+   {
+      return documentElement;
+   }
+
+   /**
     * @see RequestContext#setRequest(RequestType)
     */
    public void setRequest(RequestType requestType) throws IOException
@@ -90,6 +101,8 @@
       try
       {
          Node root = getRequest(is);
+         this.documentElement = root;
+         
          if (root == null)
             throw new IllegalStateException("Root node read from the input stream is null");
          RequestCtx request = RequestCtx.getInstance(root);
@@ -106,6 +119,10 @@
     */
    public void readRequest(Node node) throws IOException
    {
+      this.documentElement = node;
+      if(node == null)
+         throw new IllegalArgumentException("node is null");
+      
       try
       {
          RequestCtx request = RequestCtx.getInstance(node);

Modified: projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/core/JBossResponseContext.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/core/JBossResponseContext.java	2008-04-03 07:02:29 UTC (rev 71677)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/core/JBossResponseContext.java	2008-04-03 07:05:51 UTC (rev 71678)
@@ -22,18 +22,23 @@
 package org.jboss.security.xacml.core;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
+import javax.xml.parsers.DocumentBuilderFactory;
+
 import org.jboss.security.xacml.interfaces.ContextMapOp;
 import org.jboss.security.xacml.interfaces.ResponseContext;
 import org.jboss.security.xacml.interfaces.XACMLConstants;
 import org.jboss.security.xacml.sunxacml.ParsingException;
 import org.jboss.security.xacml.sunxacml.ctx.ResponseCtx;
 import org.jboss.security.xacml.sunxacml.ctx.Result;
+import org.w3c.dom.Document;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 /**
  *  Implementation of the ResponseContext interface
@@ -46,6 +51,8 @@
    private int decision = XACMLConstants.DECISION_DENY;
 
    private Map<String, Object> map = new HashMap<String, Object>();
+   
+   private Node documentElement = null;
 
    /**
     * @see ContextMapOp#get(String)
@@ -80,6 +87,14 @@
       return decision;
 
    }
+   
+   /**
+    * @see ResponseContext#getDocumentElement()
+    */
+   public Node getDocumentElement()
+   { 
+      return documentElement;
+   }
 
    /**
     * @see ResponseContext#marshall(OutputStream)
@@ -90,12 +105,25 @@
       if (storedResponse != null)
          storedResponse.encode(os);
    }
+   
+   /**
+    * @see ResponseContext#readResponse(InputStream)
+    */
+   public void readResponse(InputStream is) throws Exception
+   {   
+      readResponse(getResponse(is));
+   }
 
    /**
     * @see ResponseContext#readResponse(Node)
     */
    public void readResponse(Node node) throws IOException
    {
+      if(node == null)
+         throw new IllegalArgumentException("node is null");
+      
+      this.documentElement = node;
+      
       ResponseCtx responseCtx;
       try
       {
@@ -107,4 +135,15 @@
          throw new RuntimeException(e);
       }
    }
+   
+   private Node getResponse(InputStream is) throws Exception
+   {
+      String contextSchema = XACMLConstants.CONTEXT_SCHEMA;
+      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+      factory.setNamespaceAware(true);
+      factory.setIgnoringComments(true);
+      Document doc = factory.newDocumentBuilder().parse(is);
+      NodeList nodes = doc.getElementsByTagNameNS(contextSchema, "Response");
+      return nodes.item(0);
+   }
 }
\ No newline at end of file

Modified: projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/interfaces/RequestContext.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/interfaces/RequestContext.java	2008-04-03 07:02:29 UTC (rev 71677)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/interfaces/RequestContext.java	2008-04-03 07:05:51 UTC (rev 71678)
@@ -27,9 +27,7 @@
 
 import org.jboss.security.xacml.core.model.context.RequestType;
 import org.w3c.dom.Node;
-
-//$Id$
-
+ 
 /**
  *  Represents a Request
  *  @author Anil.Saldhana at redhat.com
@@ -39,6 +37,14 @@
 public interface RequestContext extends ContextMapOp
 {
    /**
+    * Return the element of the document
+    * from where the request was created if available
+    * Null if no parsing was involved
+    * @return
+    */
+   Node getDocumentElement();
+   
+   /**
     * Place the Request instance on the context
     * @param requestType An instance of RequestType 
     * @throws IOException

Modified: projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/interfaces/ResponseContext.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/interfaces/ResponseContext.java	2008-04-03 07:02:29 UTC (rev 71677)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/interfaces/ResponseContext.java	2008-04-03 07:05:51 UTC (rev 71678)
@@ -22,12 +22,12 @@
 package org.jboss.security.xacml.interfaces;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.w3c.dom.Node;
+ 
 
-//$Id$
-
 /**
  *  Represents a XACML Response
  *  @author Anil.Saldhana at redhat.com
@@ -44,6 +44,21 @@
    int getDecision();
 
    /**
+    * Return the element of the document
+    * from where the response was created if available
+    * Null if no parsing was involved
+    * @return
+    */
+   Node getDocumentElement();
+   
+   /**
+    * Read a response from an input stream
+    * @param is
+    * @throws Exception
+    */
+   void readResponse(InputStream is) throws Exception;
+   
+   /**
     * Read a preparsed Node
     * @param node
     * @throws IOException




More information about the jboss-cvs-commits mailing list