[jboss-cvs] JBossAS SVN: r107902 - in projects/security/security-xacml/trunk: jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/attr and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 30 20:54:18 EDT 2010


Author: anil.saldhana at jboss.com
Date: 2010-08-30 20:54:17 -0400 (Mon, 30 Aug 2010)
New Revision: 107902

Added:
   projects/security/security-xacml/trunk/jboss-xacml/src/test/resources/test/requests/DuplicateAttributes.xml
Modified:
   projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/BasicEvaluationCtx.java
   projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/Obligation.java
   projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/attr/TimeAttribute.java
   projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/Attribute.java
   projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/RequestCtx.java
   projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/Status.java
   projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/StatusDetail.java
   projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/Subject.java
Log:
SECURITY-523: internal data structure should be list rather than set due to the possibility of attributes being duplicate

Modified: projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/BasicEvaluationCtx.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/BasicEvaluationCtx.java	2010-08-30 22:11:27 UTC (rev 107901)
+++ projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/BasicEvaluationCtx.java	2010-08-31 00:54:17 UTC (rev 107902)
@@ -44,7 +44,6 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -85,6 +84,7 @@
  * @since 1.2
  * @author Seth Proctor
  */
+ at SuppressWarnings({"unchecked", "rawtypes"}) 
 public class BasicEvaluationCtx implements EvaluationCtx
 {
     // the finder to use if a value isn't in the request
@@ -198,19 +198,19 @@
 
         // get the subjects, make sure they're correct, and setup tables
         subjectMap = new HashMap();
-        setupSubjects(request.getSubjects());
+        setupSubjects(request.getSubjectsAsList());
 
         // next look at the Resource data, which needs to be handled specially
         resourceMap = new HashMap();
-        setupResource(request.getResource());
+        setupResource(request.getResourceAsList());
         
         // setup the action data, which is generic
         actionMap = new HashMap();
-        mapAttributes(request.getAction(), actionMap);
+        mapAttributes(request.getActionAsList(), actionMap);
 
         // finally, set up the environment data, which is also generic
         environmentMap = new HashMap();
-        mapAttributes(request.getEnvironmentAttributes(), environmentMap);
+        mapAttributes(request.getEnvironmentAttributesAsList(), environmentMap);
     }
 
     /**
@@ -220,7 +220,7 @@
      * Maps that in turn are indexed by id and keep the unique ctx.Attribute
      * objects.
      */
-    private void setupSubjects(Set subjects) throws ParsingException {
+    private void setupSubjects(List subjects) throws ParsingException {
         // make sure that there is at least one Subject
         if (subjects.size() == 0)
             throw new ParsingException("Request must a contain subject");
@@ -242,7 +242,7 @@
             }
 
             // iterate over the set of attributes
-            Iterator attrIterator = subject.getAttributes().iterator();
+            Iterator attrIterator = subject.getAttributesAsList().iterator();
 
             while (attrIterator.hasNext()) {
                 Attribute attr = (Attribute)(attrIterator.next());
@@ -250,11 +250,11 @@
 
                 if (categoryMap.containsKey(id)) {
                     // add to the existing set of Attributes w/this id
-                    Set existingIds = (Set)(categoryMap.get(id));
+                    List existingIds = (List)(categoryMap.get(id));
                     existingIds.add(attr);
                 } else {
                     // this is the first Attr w/this id
-                    HashSet newIds = new HashSet();
+                    List newIds = new ArrayList();
                     newIds.add(attr);
                     categoryMap.put(id, newIds);
                 }
@@ -269,7 +269,7 @@
      * there, and for the optional scope attribute, to see what the scope
      * of the attribute is
      */
-    private void setupResource(Set resource) throws ParsingException {
+    private void setupResource(List resource) throws ParsingException {
         mapAttributes(resource, resourceMap);
 
         // make sure there resource-id attribute was included
@@ -337,17 +337,17 @@
      * by the String form of the attribute ids, and that contains Sets at
      * each entry with all attributes that have that id
      */
-    private void mapAttributes(Set input, Map output) {
+    private void mapAttributes(List input, Map output) {
         Iterator it = input.iterator();
         while (it.hasNext()) {
             Attribute attr = (Attribute)(it.next());
             String id = attr.getId().toString();
 
             if (output.containsKey(id)) {
-                Set set = (Set)(output.get(id));
+                List set = (List)(output.get(id));
                 set.add(attr);
             } else {
-                Set set = new HashSet();
+                List set = new ArrayList();
                 set.add(attr);
                 output.put(id, set);
             }
@@ -611,7 +611,7 @@
                                                   Map map, URI category,
                                                   int designatorType) {
         // try to find the id
-        Set attrSet = (Set)(map.get(id.toString()));
+        List attrSet = (List)(map.get(id.toString()));
         if (attrSet == null) {
             // the request didn't have an attribute with that id, so we should
             // try asking the attribute finder

Modified: projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/Obligation.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/Obligation.java	2010-08-30 22:11:27 UTC (rev 107901)
+++ projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/Obligation.java	2010-08-31 00:54:17 UTC (rev 107902)
@@ -40,15 +40,12 @@
 
 import java.io.OutputStream;
 import java.io.PrintStream;
-
 import java.net.URI;
 import java.net.URISyntaxException;
-
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 
 import org.jboss.security.xacml.sunxacml.attr.AttributeFactory;
 import org.jboss.security.xacml.sunxacml.attr.AttributeValue;
@@ -233,7 +230,7 @@
             str.append("<AttributeAssignment AttributeId=\"");
             str.append(attr.getId().toString() + "\" DataType=\"");
             str.append(attr.getType().toString() + "\">");
-            Set<AttributeValue> attrValues = attr.getValues();
+            List<AttributeValue> attrValues = attr.getValues();
             if(attrValues != null)
             {
                for(AttributeValue val: attrValues)

Modified: projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/attr/TimeAttribute.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/attr/TimeAttribute.java	2010-08-30 22:11:27 UTC (rev 107901)
+++ projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/attr/TimeAttribute.java	2010-08-31 00:54:17 UTC (rev 107902)
@@ -40,7 +40,6 @@
 import java.net.URI;
 import java.text.ParseException;
 import java.util.Date;
-import java.util.TimeZone;
 
 import org.jboss.security.xacml.sunxacml.ParsingException;
 import org.jboss.security.xacml.sunxacml.ProcessingException;
@@ -56,7 +55,7 @@
  * @since 1.0
  * @author Steve Hanna
  * @author Seth Proctor
- */
+ */ 
 public class TimeAttribute extends AttributeValue
 {
     /**
@@ -267,8 +266,7 @@
 
         Date dateValue = dateTime.getValue();
         int defaultedTimeZone = dateTime.getDefaultedTimeZone();
-        if (dateTime.getTimeZone() == TZ_UNSPECIFIED) {
-            TimeZone localTZ = TimeZone.getDefault();
+        if (dateTime.getTimeZone() == TZ_UNSPECIFIED) { 
             int newDefTimeZone =
                 DateTimeAttribute.getDefaultTZOffset(new Date());
             dateValue = new Date(dateValue.getTime() -

Modified: projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/Attribute.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/Attribute.java	2010-08-30 22:11:27 UTC (rev 107901)
+++ projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/Attribute.java	2010-08-31 00:54:17 UTC (rev 107902)
@@ -42,7 +42,9 @@
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.net.URI;
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.jboss.security.xacml.sunxacml.Indenter;
@@ -78,7 +80,7 @@
    //private AttributeValue value;
    
    //SECURITY-157: support multiple values
-   private Set<AttributeValue> attributeValues = null;
+   private List<AttributeValue> attributeValues = new ArrayList<AttributeValue>();
 
    /**
     * Creates a new <code>Attribute</code> of the type specified in the
@@ -97,7 +99,7 @@
       this.issuer = issuer;
       this.issueInstant = issueInstant;
       if(this.attributeValues == null)
-         this.attributeValues = new HashSet<AttributeValue>();
+         this.attributeValues = new ArrayList<AttributeValue>();
       this.attributeValues.add(value); 
       if(value != null)
         this.type = value.getType();
@@ -110,8 +112,18 @@
       this.type = type;
       this.issuer = issuer;
       this.issueInstant = issueInstant;
-      this.attributeValues = values; 
+      this.attributeValues.addAll( values ); 
    }
+   
+   public Attribute(URI id, URI type, String issuer, DateTimeAttribute issueInstant,
+         List<AttributeValue> values) 
+   {
+      this.id = id;
+      this.type = type;
+      this.issuer = issuer;
+      this.issueInstant = issueInstant;
+      this.attributeValues.addAll( values ); 
+   }
 
    /**
     * Creates a new <code>Attribute</code>
@@ -270,7 +282,7 @@
     * Return all the values
     * @return
     */
-   public Set<AttributeValue> getValues()
+   public List<AttributeValue> getValues()
    {
       return this.attributeValues;
    }
@@ -345,4 +357,65 @@
       
       return encoded;
    }
-}
+
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((attributeValues == null) ? 0 : attributeValues.hashCode());
+      result = prime * result + ((id == null) ? 0 : id.hashCode());
+      result = prime * result + ((issueInstant == null) ? 0 : issueInstant.hashCode());
+      result = prime * result + ((issuer == null) ? 0 : issuer.hashCode());
+      result = prime * result + ((type == null) ? 0 : type.hashCode());
+      return result;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      Attribute other = (Attribute) obj;
+      if (attributeValues == null)
+      {
+         if (other.attributeValues != null)
+            return false;
+      }
+      else if (!attributeValues.equals(other.attributeValues))
+         return false;
+      if (id == null)
+      {
+         if (other.id != null)
+            return false;
+      }
+      else if (!id.equals(other.id))
+         return false;
+      if (issueInstant == null)
+      {
+         if (other.issueInstant != null)
+            return false;
+      }
+      else if (!issueInstant.equals(other.issueInstant))
+         return false;
+      if (issuer == null)
+      {
+         if (other.issuer != null)
+            return false;
+      }
+      else if (!issuer.equals(other.issuer))
+         return false;
+      if (type == null)
+      {
+         if (other.type != null)
+            return false;
+      }
+      else if (!type.equals(other.type))
+         return false;
+      return true;
+   }
+}
\ No newline at end of file

Modified: projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/RequestCtx.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/RequestCtx.java	2010-08-30 22:11:27 UTC (rev 107901)
+++ projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/RequestCtx.java	2010-08-31 00:54:17 UTC (rev 107902)
@@ -43,9 +43,11 @@
 import java.io.PrintStream;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 import org.jboss.security.xacml.sunxacml.Indenter;
@@ -63,20 +65,21 @@
  * @author Seth Proctor
  * @author Marco Barreno
  */
+ at SuppressWarnings({"unchecked", "rawtypes"})
 public class RequestCtx
 {
 
     // There must be at least one subject
-    private Set subjects = null;
+    private List subjects = null;
 
     // There must be exactly one resource
-    private Set resource = null;
+    private List resource = null;
 
     // There must be exactly one action
-    private Set action = null;
+    private List action = null;
 
     // There may be any number of environment attributes
-    private Set environment = null;
+    private List environment = null;
 
     // Hold onto the root of the document for XPath searches
     private Node documentRoot = null;
@@ -92,9 +95,22 @@
      * @param action a <code>Set</code> of <code>Attribute</code>s
      * @param environment a <code>Set</code> of environment attributes
      */
-    public RequestCtx(Set subjects, Set resource, Set action,
+    /*public RequestCtx(Set subjects, Set resource, Set action,
                       Set environment) {
         this(subjects, resource, action, environment, null, null);
+    }*/
+    
+    /**
+     * Constructor that creates a <code>RequestCtx</code> from components.
+     *
+     * @param subjects a <code>Set</code> of <code>Subject</code>s
+     * @param resource a <code>Set</code> of <code>Attribute</code>s
+     * @param action a <code>Set</code> of <code>Attribute</code>s
+     * @param environment a <code>Set</code> of environment attributes
+     */
+    public RequestCtx(List subjects, List resource, List action,
+                      List environment) {
+        this(subjects, resource, action, environment, null, null);
     }
 
     /**
@@ -110,6 +126,20 @@
                       Set environment, Node documentRoot) {
         this(subjects, resource, action, environment, documentRoot, null);
     }
+    
+    /**
+     * Constructor that creates a <code>RequestCtx</code> from components.
+     *
+     * @param subjects a <code>Set</code> of <code>Subject</code>s
+     * @param resource a <code>Set</code> of <code>Attribute</code>s
+     * @param action a <code>Set</code> of <code>Attribute</code>s
+     * @param environment a <code>Set</code> of environment attributes
+     * @param documentRoot the root node of the DOM tree for this request
+     */
+    public RequestCtx(List subjects, List resource, List action, 
+                      List environment, Node documentRoot) {
+        this(subjects, resource, action, environment, documentRoot, null);
+    }
 
     /**
      * Constructor that creates a <code>RequestCtx</code> from components.
@@ -144,8 +174,11 @@
     public RequestCtx(Set subjects, Set resource, Set action, 
                       Set environment, Node documentRoot,
                       String resourceContent) throws IllegalArgumentException {
+       
+       this( new ArrayList( subjects ), new ArrayList( resource ),
+             new ArrayList(action), new ArrayList( environment ), documentRoot, resourceContent );
       
-        // make sure subjects is well formed
+        /*// make sure subjects is well formed
         Iterator sIter = subjects.iterator();
         while (sIter.hasNext()){
             if (!(sIter.next() instanceof Subject))
@@ -183,6 +216,65 @@
             Collections.unmodifiableSet(new HashSet(environment));
 
         this.documentRoot = documentRoot;
+        this.resourceContent = resourceContent;*/
+    }
+    
+    /**
+     * Constructor that creates a <code>RequestCtx</code> from components.
+     *
+     * @param subjects a <code>Set</code> of <code>Subject</code>s
+     * @param resource a <code>Set</code> of <code>Attribute</code>s
+     * @param action a <code>Set</code> of <code>Attribute</code>s
+     * @param environment a <code>Set</code> of environment attributes
+     * @param documentRoot the root node of the DOM tree for this request
+     * @param resourceContent a text-encoded version of the content, suitable
+     *                        for including in the RequestType, including the
+     *                        root <code>RequestContent</code> node
+     *
+     * @throws IllegalArgumentException if the inputs are not well formed
+     */
+    public RequestCtx( List subjects, List resource, List action, 
+                      List environment, Node documentRoot,
+                      String resourceContent) throws IllegalArgumentException {
+      
+        // make sure subjects is well formed
+        Iterator sIter = subjects.iterator();
+        while (sIter.hasNext()){
+            if (!(sIter.next() instanceof Subject))
+                throw new IllegalArgumentException("Subjects input is not " +
+                                                   "well formed");
+        }
+        this.subjects = Collections.unmodifiableList(subjects);
+
+        // make sure resource is well formed
+        Iterator rIter = resource.iterator();
+        while (rIter.hasNext()){
+            if (!(rIter.next() instanceof Attribute))
+                throw new IllegalArgumentException("Resource input is not " +
+                                                   "well formed");
+        }
+        this.resource = Collections.unmodifiableList( resource );
+
+        // make sure action is well formed
+        Iterator aIter = action.iterator();
+        while (aIter.hasNext()){
+            if (!(aIter.next() instanceof Attribute))
+                throw new IllegalArgumentException("Action input is not " +
+                                                   "well formed");
+        }
+        this.action = Collections.unmodifiableList( action );
+        
+        // make sure environment is well formed
+        Iterator eIter = environment.iterator();
+        while (eIter.hasNext()){
+            if (!(eIter.next() instanceof Attribute))
+                throw new IllegalArgumentException("Environment input is not" +
+                                                   " well formed");
+        }
+        this.environment =
+            Collections.unmodifiableList( environment );
+
+        this.documentRoot = documentRoot;
         this.resourceContent = resourceContent;
     }
 
@@ -199,11 +291,10 @@
      * @throws ParsingException if the DOM node is invalid
      */
     public static RequestCtx getInstance(Node root) throws ParsingException {
-        Set newSubjects = new HashSet();
-        Set newResource = null;
-        Set newAction = null;
-        Set newEnvironment = null;
-        String resourceContent;
+        List newSubjects = new ArrayList();
+        List newResource = null;
+        List newAction = null;
+        List newEnvironment = null; 
 
         // First check to be sure the node passed is indeed a Request node.
         String tagName = SunxacmlUtil.getNodeName(root); 
@@ -235,7 +326,7 @@
                 }
                 
                 // now we get the attributes
-                Set attributes = parseAttributes(node);
+                List attributes = parseAttributes(node);
 
                 // finally, add the list to the set of subject attributes
                 newSubjects.add(new Subject(category, attributes));
@@ -257,7 +348,7 @@
         // if we didn't have an environment section, the only optional section
         // of the four, then create a new empty set for it
         if (newEnvironment == null)
-            newEnvironment = new HashSet();
+            newEnvironment = new ArrayList();
 
         // Now create and return the RequestCtx from the information
         // gathered
@@ -269,8 +360,8 @@
      * Helper method that parses a set of Attribute types. The Subject,
      * Action and Environment sections all look like this.
      */
-    private static Set parseAttributes(Node root) throws ParsingException {
-        Set set = new HashSet();
+    private static List parseAttributes(Node root) throws ParsingException {
+        List set = new ArrayList();
 
         // the Environment section is just a list of Attributes
         NodeList nodes = root.getChildNodes();
@@ -309,8 +400,48 @@
      * Returns a <code>Set</code> containing <code>Subject</code> objects.
      *
      * @return the request's subject attributes
+     * @deprecated
      */
     public Set getSubjects() {
+        return Collections.unmodifiableSet( new HashSet( subjects )) ;
+    }
+
+    /**
+     * Returns a <code>Set</code> containing <code>Attribute</code> objects.
+     *
+     * @return the request's resource attributes
+     * @deprecated
+     */
+    public Set getResource() {
+        return Collections.unmodifiableSet( new HashSet( resource ));
+    }
+
+    /**
+     * Returns a <code>Set</code> containing <code>Attribute</code> objects.
+     *
+     * @return the request's action attributes
+     * @deprecated
+     */
+    public Set getAction() {
+        return Collections.unmodifiableSet( new HashSet( action ));
+    }
+
+    /**
+     * Returns a <code>Set</code> containing <code>Attribute</code> objects.
+     *
+     * @return the request's environment attributes
+     * @deprecated
+     */
+    public Set getEnvironmentAttributes() {
+        return Collections.unmodifiableSet( new HashSet( environment ));
+    }
+    
+    /**
+     * Returns a <code>Set</code> containing <code>Subject</code> objects.
+     *
+     * @return the request's subject attributes
+     */
+    public List getSubjectsAsList() {
         return subjects;
     }
 
@@ -319,7 +450,7 @@
      *
      * @return the request's resource attributes
      */
-    public Set getResource() {
+    public List getResourceAsList() {
         return resource;
     }
 
@@ -328,7 +459,7 @@
      *
      * @return the request's action attributes
      */
-    public Set getAction() {
+    public List getActionAsList() {
         return action;
     }
 
@@ -337,7 +468,7 @@
      *
      * @return the request's environment attributes
      */
-    public Set getEnvironmentAttributes() {
+    public List getEnvironmentAttributesAsList() {
         return environment;
     }
 
@@ -400,7 +531,7 @@
             out.print(indent + "<Subject SubjectCategory=\"" +
                       subject.getCategory().toString() + "\"");
 
-            Set subjectAttrs = subject.getAttributes();
+            List subjectAttrs = subject.getAttributesAsList();
             
             if (subjectAttrs.size() == 0) {
                 // there's nothing in this Subject, so just close the tag
@@ -476,7 +607,7 @@
             out.print(indent + "<Subject SubjectCategory=\"" +
                       subject.getCategory().toString() + "\"");
 
-            Set subjectAttrs = subject.getAttributes();
+            List subjectAttrs = subject.getAttributesAsList();
             
             if (subjectAttrs.size() == 0) {
                 // there's nothing in this Subject, so just close the tag
@@ -526,12 +657,12 @@
         indenter.out();
         
         out.println(topIndent + "</Request>");
-    }
-
+    } 
+    
     /**
      * Private helper function to encode the attribute sets
      */
-    private void encodeAttributes(Set attributes, PrintStream out,
+    private void encodeAttributes(List attributes, PrintStream out,
                                   Indenter indenter) {
         Iterator it = attributes.iterator();
         while (it.hasNext()) {
@@ -539,4 +670,65 @@
             attr.encode(out, indenter);
         }
     } 
-}
+    
+
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((action == null) ? 0 : action.hashCode()); 
+      result = prime * result + ((environment == null) ? 0 : environment.hashCode());
+      result = prime * result + ((resource == null) ? 0 : resource.hashCode()); 
+      result = prime * result + ((subjects == null) ? 0 : subjects.hashCode());
+      return result;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      RequestCtx other = (RequestCtx) obj;
+      if (action == null)
+      {
+         if (other.action != null)
+            return false;
+      }
+      else if (!action.equals(other.action))
+         return false; 
+      if (environment == null)
+      {
+         if (other.environment != null)
+            return false;
+      }
+      else if (!environment.equals(other.environment))
+         return false;
+      if (resource == null)
+      {
+         if (other.resource != null)
+            return false;
+      }
+      else if (!resource.equals(other.resource))
+         return false;
+      if (resourceContent == null)
+      {
+         if (other.resourceContent != null)
+            return false;
+      }
+      else if (!resourceContent.equals(other.resourceContent))
+         return false;
+      if (subjects == null)
+      {
+         if (other.subjects != null)
+            return false;
+      }
+      else if (!subjects.equals(other.subjects))
+         return false;
+      return true;
+   } 
+}
\ No newline at end of file

Modified: projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/Status.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/Status.java	2010-08-30 22:11:27 UTC (rev 107901)
+++ projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/Status.java	2010-08-31 00:54:17 UTC (rev 107902)
@@ -317,5 +317,50 @@
         } else {
             out.println(in + "<StatusCode Value=\"" + code + "\"/>");
         }
-    } 
+    }
+
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((code == null) ? 0 : code.hashCode());
+      result = prime * result + ((detail == null) ? 0 : detail.hashCode());
+      result = prime * result + ((message == null) ? 0 : message.hashCode());
+      return result;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      Status other = (Status) obj;
+      if (code == null)
+      {
+         if (other.code != null)
+            return false;
+      }
+      else if (!code.equals(other.code))
+         return false;
+      if (detail == null)
+      {
+         if (other.detail != null)
+            return false;
+      }
+      else if (!detail.equals(other.detail))
+         return false;
+      if (message == null)
+      {
+         if (other.message != null)
+            return false;
+      }
+      else if (!message.equals(other.message))
+         return false;
+      return true;
+   }  
 }

Modified: projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/StatusDetail.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/StatusDetail.java	2010-08-30 22:11:27 UTC (rev 107901)
+++ projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/StatusDetail.java	2010-08-31 00:54:17 UTC (rev 107902)
@@ -194,5 +194,34 @@
             throw new IllegalStateException("no encoded form available");
         
         return detailText;
-    } 
-}
+    }
+
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1; 
+      result = prime * result + ((detailText == null) ? 0 : detailText.hashCode());
+      return result;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      StatusDetail other = (StatusDetail) obj; 
+      if (detailText == null)
+      {
+         if (other.detailText != null)
+            return false;
+      }
+      else if (!detailText.equals(other.detailText))
+         return false;
+      return true;
+   }   
+}
\ No newline at end of file

Modified: projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/Subject.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/Subject.java	2010-08-30 22:11:27 UTC (rev 107901)
+++ projects/security/security-xacml/trunk/jboss-sunxacml/src/main/java/org/jboss/security/xacml/sunxacml/ctx/Subject.java	2010-08-31 00:54:17 UTC (rev 107902)
@@ -39,8 +39,10 @@
 
 
 import java.net.URI;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.jboss.security.xacml.sunxacml.attr.AttributeDesignator;
@@ -53,6 +55,7 @@
  * @since 1.1
  * @author seth proctor
  */
+ at SuppressWarnings({"unchecked", "rawtypes"})
 public class Subject
 {
 
@@ -60,7 +63,7 @@
     private URI category;
 
     // the attributes associated with the subject
-    private Set attributes;
+    private List attributes;
 
     /**
      * <code>URI</code> form of the default subject category
@@ -73,11 +76,24 @@
      *
      * @param attributes a non-null <code>Set</code> of <code>Attribute</code>
      *                   objects
-     */
+     * @deprecated                  
+     */ 
     public Subject(Set attributes) {
         this(null, attributes);
     }
+    
+    /**
+     * Creates a new collection of subject attributes using the default
+     * subject cateorgy.
+     *
+     * @param attributes a non-null <code>Set</code> of <code>Attribute</code>
+     *                   objects
+     */ 
+    public Subject(List attributes) {
+        this(null, attributes);
+    }
 
+    
     /**
      * Creates a new collection of subject attributes using the given
      * subject category.
@@ -85,6 +101,7 @@
      * @param category the subject category or null for the default category
      * @param attributes a non-null <code>Set</code> of <code>Attribute</code>
      *                   objects
+     * @deprecated
      */
     public Subject(URI category, Set attributes) {
         if (category == null)
@@ -92,9 +109,27 @@
         else
             this.category = category;
 
-        this.attributes = Collections.unmodifiableSet(new HashSet(attributes));
+        this.attributes = Collections.unmodifiableList( new ArrayList( attributes ));
     }
+    
+    /**
+     * Creates a new collection of subject attributes using the given
+     * subject category.
+     *
+     * @param category the subject category or null for the default category
+     * @param attributes a non-null <code>Set</code> of <code>Attribute</code>
+     *                   objects
+     */ 
+    public Subject(URI category, List attributes) {
+        if (category == null)
+            this.category = DEFAULT_CATEGORY;
+        else
+            this.category = category;
 
+        this.attributes = Collections.unmodifiableList( attributes );
+    }
+    
+
     /**
      * Returns the category of this subject's attributes.
      *
@@ -108,9 +143,55 @@
      * Returns the <code>Attribute</code>s associated with this subject.
      *
      * @return the immutable <code>Set</code> of <code>Attribute</code>s
+     * @deprecated 
+     */ 
+    public Set getAttributes() {
+        return Collections.unmodifiableSet( new HashSet( attributes ) );
+    }
+    
+    /**
+     * Returns the <code>Attribute</code>s associated with this subject.
+     *
+     * @return the immutable <code>Set</code> of <code>Attribute</code>s
      */
-    public Set getAttributes() {
+    public List getAttributesAsList() {
         return attributes;
     }
 
-}
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
+      result = prime * result + ((category == null) ? 0 : category.hashCode());
+      return result;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      Subject other = (Subject) obj;
+      if (attributes == null)
+      {
+         if (other.attributes != null)
+            return false;
+      }
+      else if (!attributes.equals(other.attributes))
+         return false;
+      if (category == null)
+      {
+         if (other.category != null)
+            return false;
+      }
+      else if (!category.equals(other.category))
+         return false;
+      return true;
+   } 
+}
\ No newline at end of file

Added: projects/security/security-xacml/trunk/jboss-xacml/src/test/resources/test/requests/DuplicateAttributes.xml
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/test/resources/test/requests/DuplicateAttributes.xml	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/test/resources/test/requests/DuplicateAttributes.xml	2010-08-31 00:54:17 UTC (rev 107902)
@@ -0,0 +1,41 @@
+<?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>
+        <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>
+</xacml-context:Request>
\ No newline at end of file



More information about the jboss-cvs-commits mailing list