[jboss-cvs] JBossAS SVN: r107904 - in projects/security/security-xacml/trunk: jboss-xacml/src/test/java/org/jboss/test/security/test/xacml and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 30 21:09:29 EDT 2010
Author: anil.saldhana at jboss.com
Date: 2010-08-30 21:09:29 -0400 (Mon, 30 Aug 2010)
New Revision: 107904
Added:
projects/security/security-xacml/trunk/jboss-sunxacml/src/test/resources/requests/DuplicateAttributes.xml
projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/request/
projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/request/XACMLRequestUnitTestCase.java
Modified:
projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/test/xacml/XACMLRequestCreationUnitTestCase.java
Log:
SECURITY-523: internal data structure should be list rather than set due to the possibility of attributes being duplicate
Added: projects/security/security-xacml/trunk/jboss-sunxacml/src/test/resources/requests/DuplicateAttributes.xml
===================================================================
--- projects/security/security-xacml/trunk/jboss-sunxacml/src/test/resources/requests/DuplicateAttributes.xml (rev 0)
+++ projects/security/security-xacml/trunk/jboss-sunxacml/src/test/resources/requests/DuplicateAttributes.xml 2010-08-31 01:09:29 UTC (rev 107904)
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Request
+ 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>
+ <Attribute
+ AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string">
+ <AttributeValue>Julius Hibbert</AttributeValue>
+ </Attribute>
+ <Attribute
+ AttributeId="urn:oasis:names:tc:xacml:1.0:conformance-test:test-attr"
+ DataType="http://www.w3.org/2001/XMLSchema#string">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string"> This is IT! </AttributeValue>
+ </Attribute>
+ <Attribute
+ AttributeId="urn:oasis:names:tc:xacml:1.0:conformance-test:test-attr"
+ DataType="http://www.w3.org/2001/XMLSchema#string">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string"> This is IT! </AttributeValue>
+ </Attribute>
+ </Subject>
+ <Resource>
+ <Attribute
+ AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id"
+ DataType="http://www.w3.org/2001/XMLSchema#anyURI">
+ <AttributeValue>http://medico.com/record/patient/BartSimpson</AttributeValue>
+ </Attribute>
+ </Resource>
+ <Action>
+ <Attribute
+ AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string">
+ <AttributeValue>read</AttributeValue>
+ </Attribute>
+ </Action>
+</Request>
\ No newline at end of file
Modified: projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/test/xacml/XACMLRequestCreationUnitTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/test/xacml/XACMLRequestCreationUnitTestCase.java 2010-08-31 00:54:47 UTC (rev 107903)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/test/xacml/XACMLRequestCreationUnitTestCase.java 2010-08-31 01:09:29 UTC (rev 107904)
@@ -22,7 +22,10 @@
package org.jboss.test.security.test.xacml;
import java.net.URI;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
+import java.util.List;
import java.util.Set;
import junit.framework.TestCase;
@@ -55,14 +58,14 @@
//Create the subject set
URI subjectAttrUri = new URI("urn:oasis:names:tc:xacml:1.0:subject:subject-id");
- Set subjectAttributeValues = new HashSet();
+ List subjectAttributeValues = new ArrayList();
subjectAttributeValues.add(new StringAttribute("Anil Saldhana"));
Attribute subjectAttr = new Attribute(subjectAttrUri, new URI(StringAttribute.identifier), null, null,
subjectAttributeValues);
- Set subjectAttrSet = new HashSet();
- subjectAttrSet.add(subjectAttr);
- Set subjectSet = new HashSet();
- subjectSet.add(new Subject(subjectAttrSet));
+ List subjectAttrList = new ArrayList();
+ subjectAttrList.add(subjectAttr);
+ List subjectList = new ArrayList();
+ subjectList.add(new Subject(subjectAttrList));
//Create the resource set
URI resourceUri = new URI("urn:oasis:names:tc:xacml:1.0:resource:resource-id");
@@ -70,8 +73,8 @@
resourceAttributeValues.add(new StringAttribute("http://jboss.com/developers/payroll/anilsaldhana"));
Attribute resourceAttr = new Attribute(resourceUri, new URI(StringAttribute.identifier), null, null,
resourceAttributeValues);
- Set resourceSet = new HashSet();
- resourceSet.add(resourceAttr);
+ List resourceList = new ArrayList();
+ resourceList.add(resourceAttr);
//Create the action set
URI actionUri = new URI("urn:oasis:names:tc:xacml:1.0:action:action-id");
@@ -79,13 +82,13 @@
actionAttributeValues.add(new StringAttribute("read"));
Attribute actionAttr = new Attribute(actionUri, new URI(StringAttribute.identifier), null, null,
actionAttributeValues);
- Set actionSet = new HashSet();
- actionSet.add(actionAttr);
+ List actionList = new ArrayList();
+ actionList.add(actionAttr);
//Create the environment set
- Set environSet = new HashSet();
+ List environList = new ArrayList();
- RequestCtx request = new RequestCtx(subjectSet, resourceSet, actionSet, environSet);
+ RequestCtx request = new RequestCtx(subjectList, resourceList, actionList, environList);
assertNotNull("XACML Request != null", request);
//Log the request for viewing
@@ -93,19 +96,19 @@
XACMLUtil.logRequest(request);
//Test the request contents
- Set subjects = request.getSubjects();
+ List subjects = request.getSubjectsAsList();
assertTrue("We have one subject?", subjects.size() == 1);
Subject subj = (Subject) (subjects.iterator().next());
assertNotNull("Subject != null", subj);
assertEquals("Attributes in subject match", subjectAttr, (Attribute) (subj.getAttributes().iterator().next()));
//Test the resource attributes
- Set resources = request.getResource();
+ List resources = request.getResourceAsList();
assertTrue("# of resources = 1", resources.size() == 1);
assertEquals("Attributes in resources match", resourceAttr, (Attribute) (resources.iterator().next()));
//Test the action attributes
- Set actions = request.getAction();
+ List actions = request.getActionAsList();
assertTrue("# of actions = 1", actions.size() == 1);
assertEquals("Attributes in actions match", actionAttr, (Attribute) (actions.iterator().next()));
}
Added: projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/request/XACMLRequestUnitTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/request/XACMLRequestUnitTestCase.java (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/request/XACMLRequestUnitTestCase.java 2010-08-31 01:09:29 UTC (rev 107904)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.request;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.jboss.security.xacml.interfaces.RequestContext;
+import org.jboss.security.xacml.interfaces.XACMLConstants;
+import org.jboss.security.xacml.sunxacml.ctx.RequestCtx;
+import org.jboss.security.xacml.sunxacml.ctx.Subject;
+import org.jboss.test.security.xacml.factories.util.XACMLTestUtil;
+import org.junit.Test;
+
+/**
+ * Unit Test various possibilities with xacml request
+ * @author Anil.Saldhana at redhat.com
+ * @since Aug 30, 2010
+ */
+public class XACMLRequestUnitTestCase
+{
+
+ private static String REQUEST1 = "test/requests/interop/scenario2-testcase1-request.xml";
+ private static String REQUEST2 = "test/requests/interop/scenario2-testcase2-request.xml";
+
+ @Test
+ public void testEquality() throws Exception
+ {
+ RequestContext requestContext1 = XACMLTestUtil.getRequest( REQUEST1 );
+ RequestCtx xacmlRequest1 = requestContext1.get( XACMLConstants.REQUEST_CTX );
+
+ RequestContext requestContext2 = XACMLTestUtil.getRequest( REQUEST2 );
+ RequestCtx xacmlRequest2 = requestContext2.get( XACMLConstants.REQUEST_CTX );
+
+ RequestContext copyRequestContext1 = XACMLTestUtil.getRequest( REQUEST1 );
+ RequestCtx copyXacmlRequest1 = copyRequestContext1.get( XACMLConstants.REQUEST_CTX );
+
+ RequestContext copyRequestContext2 = XACMLTestUtil.getRequest( REQUEST2 );
+ RequestCtx copyXacmlRequest2 = copyRequestContext2.get( XACMLConstants.REQUEST_CTX );
+
+ assertEquals( "Requests are equal", xacmlRequest1, copyXacmlRequest1 );
+ assertEquals( "Requests are equal", xacmlRequest2, copyXacmlRequest2 );
+ }
+
+ @Test
+ public void testDuplicateAttributes() throws Exception
+ {
+ RequestContext requestContext = XACMLTestUtil.getRequest( "test/requests/DuplicateAttributes.xml" );
+ RequestCtx xacmlRequest = requestContext.get( XACMLConstants.REQUEST_CTX );
+
+ List subjectSet = xacmlRequest.getSubjectsAsList();
+ Subject subject = (Subject) subjectSet.iterator().next();
+ List attributes = subject.getAttributesAsList();
+ assertEquals( "Attribs are 3", 3, attributes.size() );
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list