[jboss-cvs] JBossAS SVN: r112476 - in projects/security/security-xacml/trunk/jboss-xacml/src: test/java/org/jboss/test/security/xacml/core and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Nov 27 20:32:45 EST 2011


Author: dgradl
Date: 2011-11-27 20:32:45 -0500 (Sun, 27 Nov 2011)
New Revision: 112476

Added:
   projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/JBossResponseContextTest.java
   projects/security/security-xacml/trunk/jboss-xacml/src/test/resources/test/requests/SimpleResponse.xml
Modified:
   projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/core/JBossResponseContext.java
Log:
RESOLVED - issue SECURITY-177: Implement JBossResponseContext.asElement(Document) 
https://issues.jboss.org/browse/SECURITY-177

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	2011-11-28 01:20:40 UTC (rev 112475)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/core/JBossResponseContext.java	2011-11-28 01:32:45 UTC (rev 112476)
@@ -224,14 +224,20 @@
     */
    public Element asElement(Document root)
    { 
-      throw new RuntimeException("SECURITY-177");
+      String contextSchema = XACMLConstants.CONTEXT_SCHEMA;
+      NodeList nodes = root.getElementsByTagNameNS(contextSchema, "Response");
+      if(nodes.getLength() == 0)
+      {
+         nodes = root.getElementsByTagName("Response");
+      }
+      return (Element)nodes.item(0);
    }
    
    private Node getResponse(InputStream is) throws Exception
    {
       String contextSchema = XACMLConstants.CONTEXT_SCHEMA;
       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-      factory.setNamespaceAware(true);
+//      factory.setNamespaceAware(true);
       factory.setIgnoringComments(true);
       Document doc = factory.newDocumentBuilder().parse(is);
       NodeList nodes = doc.getElementsByTagNameNS(contextSchema, "Response");

Added: projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/JBossResponseContextTest.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/JBossResponseContextTest.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/JBossResponseContextTest.java	2011-11-28 01:32:45 UTC (rev 112476)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+/**
+ * 
+ */
+package org.jboss.test.security.xacml.core;
+
+import java.io.InputStream;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.Assert;
+
+import org.jboss.security.xacml.core.JBossResponseContext;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * @author Dan Gradl
+ * @since Nov 24, 2011
+ */
+public class JBossResponseContextTest
+{
+
+   @Test
+   public void testAsElement() throws Exception
+   {
+      JBossResponseContext context = new JBossResponseContext();
+
+      //Create a response Document
+      InputStream is = Thread.currentThread().getContextClassLoader()
+            .getResourceAsStream("test/requests/SimpleResponse.xml");
+      String contextSchema = "urn:oasis:names:tc:xacml:2.0:context:schema:os";
+      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+      factory.setNamespaceAware(true);
+      factory.setIgnoringComments(true);
+      Document doc = factory.newDocumentBuilder().parse(is);
+
+      //Get as element
+      Element element = context.asElement(doc);
+
+      //Assert results
+      Assert.assertNotNull("Element should not be null", element);
+
+      //Just a test to see if it can parse out a value
+      Element statusCodeElement = (Element) element.getElementsByTagName("StatusCode").item(0);
+      String statusCodeValue = statusCodeElement.getAttributes().getNamedItem("Value").getNodeValue();
+      Assert.assertEquals("StatusCode Value not as expected", "urn:oasis:names:tc:xacml:1.0:status:ok", statusCodeValue);
+   }
+
+}

Added: projects/security/security-xacml/trunk/jboss-xacml/src/test/resources/test/requests/SimpleResponse.xml
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/test/resources/test/requests/SimpleResponse.xml	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/test/resources/test/requests/SimpleResponse.xml	2011-11-28 01:32:45 UTC (rev 112476)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Response xmlns='urn:oasis:names:tc:xacml:2.0:context:schema:os'>
+	<Result ResourceId="">
+		<Decision>NotApplicable</Decision>
+		<Status>
+			<StatusCode Value="urn:oasis:names:tc:xacml:1.0:status:ok" />
+		</Status>
+	</Result>
+</Response>



More information about the jboss-cvs-commits mailing list