[jboss-cvs] JBossAS SVN: r112475 - 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:20:41 EST 2011


Author: dgradl
Date: 2011-11-27 20:20:40 -0500 (Sun, 27 Nov 2011)
New Revision: 112475

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

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	2011-11-23 21:59:54 UTC (rev 112474)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/core/JBossRequestContext.java	2011-11-28 01:20:40 UTC (rev 112475)
@@ -152,7 +152,9 @@
     */
    public Element asElement(Document root)
    { 
-      throw new RuntimeException("SECURITY-176");
+      String contextSchema = "urn:oasis:names:tc:xacml:2.0:context:schema:os";
+      NodeList nodes = root.getElementsByTagNameNS(contextSchema, "Request");
+      return (Element) nodes.item(0);
    }
    
    

Added: projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/JBossRequestContextTest.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/JBossRequestContextTest.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/JBossRequestContextTest.java	2011-11-28 01:20:40 UTC (rev 112475)
@@ -0,0 +1,73 @@
+/*
+ * 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.JBossRequestContext;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * @author Dan Gradl
+ * @since Nov 24, 2011
+ */
+public class JBossRequestContextTest
+{
+
+   @Test
+   public void testAsElement() throws Exception
+   {
+      JBossRequestContext context = new JBossRequestContext();
+
+      //Create a request Document
+      InputStream is = Thread.currentThread().getContextClassLoader()
+            .getResourceAsStream("test/requests/SimpleRequest.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 resourceElement = (Element) element.getElementsByTagName("Resource").item(0);
+      String attributeId = resourceElement.getElementsByTagName("Attribute").item(0).getAttributes()
+            .getNamedItem("AttributeId").getNodeValue();
+      Assert.assertEquals("AttributeId not as expected", "urn:oasis:names:tc:xacml:1.0:resource:resource-id",
+            attributeId);
+   }
+
+}

Added: projects/security/security-xacml/trunk/jboss-xacml/src/test/resources/test/requests/SimpleRequest.xml
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/test/resources/test/requests/SimpleRequest.xml	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/test/resources/test/requests/SimpleRequest.xml	2011-11-28 01:20:40 UTC (rev 112475)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xacml-context:Request 
+    xmlns:xacml-context="urn:oasis:names:tc:xacml:2.0:context:schema:os" 
+    xmlns="urn:oasis:names:tc:xacml:2.0:context:schema:os" 
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+    xsi:schemaLocation=" urn:oasis:names:tc:xacml:2.0:context:schema:os 
+      http://docs.oasis-open.org/xacml/access_control-xacml-2.0-context-schema-os.xsd">
+	<Subject SubjectCategory="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" />
+	<Resource>
+		<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id"
+			DataType="http://www.w3.org/2001/XMLSchema#string">
+			<AttributeValue>resource1</AttributeValue>
+		</Attribute>
+	</Resource>
+	<Action />
+	<Environment>
+	</Environment>
+</xacml-context:Request>
\ No newline at end of file



More information about the jboss-cvs-commits mailing list