[jboss-cvs] JBossAS SVN: r58044 - branches/JEE5_TCK/server/src/main/org/jboss/metadata

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 2 23:48:37 EST 2006


Author: anil.saldhana at jboss.com
Date: 2006-11-02 23:48:36 -0500 (Thu, 02 Nov 2006)
New Revision: 58044

Modified:
   branches/JEE5_TCK/server/src/main/org/jboss/metadata/AssemblyDescriptorMetaData.java
   branches/JEE5_TCK/server/src/main/org/jboss/metadata/WebMetaData.java
Log:
method to obtain the reverse principal->roles map

Modified: branches/JEE5_TCK/server/src/main/org/jboss/metadata/AssemblyDescriptorMetaData.java
===================================================================
--- branches/JEE5_TCK/server/src/main/org/jboss/metadata/AssemblyDescriptorMetaData.java	2006-11-03 04:46:57 UTC (rev 58043)
+++ branches/JEE5_TCK/server/src/main/org/jboss/metadata/AssemblyDescriptorMetaData.java	2006-11-03 04:48:36 UTC (rev 58044)
@@ -21,6 +21,7 @@
 */
 package org.jboss.metadata;
 
+import java.security.Principal;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -32,6 +33,7 @@
  * This implementation only contains the security-role meta data
  *
  * @author Thomas.Diesler at jboss.org
+ * @author Anil.Saldhana at jboss.org
  * @version $Revision$
  */
 public class AssemblyDescriptorMetaData extends MetaData
@@ -40,11 +42,11 @@
    private HashMap securityRoles = new HashMap();
 
    /** The message destinations */
-   private HashMap messageDestinations = new HashMap();
+   private HashMap messageDestinations = new HashMap(); 
    
    public void addSecurityRoleMetaData(SecurityRoleMetaData srMetaData)
    {
-      securityRoles.put(srMetaData.getRoleName(), srMetaData);
+      securityRoles.put(srMetaData.getRoleName(), srMetaData); 
    }
 
    public Map getSecurityRoles()
@@ -74,7 +76,7 @@
          {
             securityRoles.put(roleName, entry.getValue());
          }
-      }
+      } 
    }
 
    public SecurityRoleMetaData getSecurityRoleByName(String roleName)
@@ -95,6 +97,36 @@
       return roleNames;
    }
    
+   /**
+    * Generate a Map of Principal keyed against a set of role names
+    * @return
+    */
+   public Map getPrincipalVersusRolesMap()
+   {
+      Map principalRolesMap = null;
+      
+      Iterator iter = securityRoles.keySet().iterator();
+      while(iter.hasNext())
+      {
+         if(principalRolesMap == null)
+            principalRolesMap = new HashMap(); 
+         String rolename = (String)iter.next();
+         SecurityRoleMetaData srm = (SecurityRoleMetaData) securityRoles.get(rolename);
+         Iterator principalIter = srm.getPrincipals().iterator();
+         while(principalIter.hasNext())
+         {
+            String pr = (String)principalIter.next(); 
+            Set roleset = (Set)principalRolesMap.get(pr);
+            if(roleset == null)
+               roleset = new HashSet();
+            if(!roleset.contains(rolename))
+               roleset.add(rolename);
+            principalRolesMap.put(pr, roleset);
+         } 
+      } 
+      return principalRolesMap;
+   }
+   
    public void addMessageDestinationMetaData(MessageDestinationMetaData metaData)
    {
       messageDestinations.put(metaData.getName(), metaData);
@@ -103,5 +135,5 @@
    public MessageDestinationMetaData getMessageDestinationMetaData(String name)
    {
       return (MessageDestinationMetaData) messageDestinations.get(name);
-   }
+   } 
 }

Modified: branches/JEE5_TCK/server/src/main/org/jboss/metadata/WebMetaData.java
===================================================================
--- branches/JEE5_TCK/server/src/main/org/jboss/metadata/WebMetaData.java	2006-11-03 04:46:57 UTC (rev 58043)
+++ branches/JEE5_TCK/server/src/main/org/jboss/metadata/WebMetaData.java	2006-11-03 04:48:36 UTC (rev 58044)
@@ -518,7 +518,7 @@
    }
 
    /**
-    *
+    * Get set of security role names keyed by principal
     * @param userName
     * @return Set<String>
     */
@@ -534,6 +534,37 @@
       }
       return roleNames;
    }
+   
+   /**
+    * Get a map of principals versus set of roles
+    * that may be configured by the user at the deployment level
+    * @return
+    */
+   public Map getPrincipalVersusRolesMap()
+   {
+      Map principalRolesMap = null;
+      
+      Iterator iter = securityRoles.keySet().iterator();
+      while(iter.hasNext())
+      {
+         if(principalRolesMap == null)
+            principalRolesMap = new HashMap(); 
+         String rolename = (String)iter.next();
+         SecurityRoleMetaData srm = (SecurityRoleMetaData) securityRoles.get(rolename);
+         Iterator principalIter = srm.getPrincipals().iterator();
+         while(principalIter.hasNext())
+         {
+            String pr = (String)principalIter.next(); 
+            Set roleset = (Set)principalRolesMap.get(pr);
+            if(roleset == null)
+               roleset = new HashSet();
+            if(!roleset.contains(rolename))
+               roleset.add(rolename);
+            principalRolesMap.put(pr, roleset);
+         } 
+      } 
+      return principalRolesMap;
+   }
 
    /**
     * Access the RunAsIdentity associated with the given servlet




More information about the jboss-cvs-commits mailing list