[seam-commits] Seam SVN: r9222 - trunk/src/main/org/jboss/seam/security/management.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Oct 8 03:43:31 EDT 2008


Author: shane.bryzak at jboss.com
Date: 2008-10-08 03:43:31 -0400 (Wed, 08 Oct 2008)
New Revision: 9222

Modified:
   trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java
Log:
JBSEAM-3466

Modified: trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java
===================================================================
--- trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java	2008-10-08 04:23:23 UTC (rev 9221)
+++ trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java	2008-10-08 07:43:31 UTC (rev 9222)
@@ -141,16 +141,16 @@
       }      
       
       if (roleClass != null)
-      {
+      {         
+         roleNameProperty = new AnnotatedBeanProperty(roleClass, RoleName.class);
+         roleGroupsProperty = new AnnotatedBeanProperty(roleClass, RoleGroups.class);
+         roleConditionalProperty = new AnnotatedBeanProperty(roleClass, RoleConditional.class);
+         
          if (!roleNameProperty.isSet())
          {
             throw new IdentityManagementException("Invalid roleClass " + roleClass.getName() + 
             " - required annotation @RoleName not found on any Field or Method.");         
-         }
-         
-         roleNameProperty = new AnnotatedBeanProperty(roleClass, RoleName.class);
-         roleGroupsProperty = new AnnotatedBeanProperty(roleClass, RoleGroups.class);
-         roleConditionalProperty = new AnnotatedBeanProperty(roleClass, RoleConditional.class);
+         }         
                  
          Type type = userRolesProperty.getPropertyType();
          if (type instanceof ParameterizedType && 
@@ -300,12 +300,29 @@
       Collection userRoles = (Collection) userRolesProperty.getValue(user); 
       if (userRoles == null)
       {
+         Type propType = userRolesProperty.getPropertyType();
+         Class collectionType;
+         
+         if (propType instanceof Class && Collection.class.isAssignableFrom((Class) propType))
+         {
+            collectionType = (Class) propType;
+         }
+         else if (propType instanceof ParameterizedType &&
+                  Collection.class.isAssignableFrom((Class) ((ParameterizedType) propType).getRawType()))
+         {
+            collectionType = (Class) ((ParameterizedType) propType).getRawType();
+         }
+         else
+         {
+            throw new IllegalStateException("Could not determine collection type for user roles.");
+         }
+         
          // This should either be a Set, or a List...
-         if (Set.class.isAssignableFrom((Class) userRolesProperty.getPropertyType()))
+         if (Set.class.isAssignableFrom(collectionType))
          {
             userRoles = new HashSet();
          }
-         else if (List.class.isAssignableFrom((Class) userRolesProperty.getPropertyType()))
+         else if (List.class.isAssignableFrom(collectionType))
          {
             userRoles = new ArrayList();
          }
@@ -583,12 +600,22 @@
       }
 
       List<String> roles = new ArrayList<String>();
+      
       Collection userRoles = (Collection) userRolesProperty.getValue(user);
       if (userRoles != null)
       {
          for (Object role : userRoles)
          {
-            roles.add((String) roleNameProperty.getValue(role));
+            if (xrefClass == null)
+            {
+               roles.add((String) roleNameProperty.getValue(role));
+            }
+            else
+            {
+               Object xref = roleNameProperty.getValue(role);
+               Object userRole = xrefRoleProperty.getValue(xref);
+               roles.add((String) roleNameProperty.getValue(userRole));
+            }
          }
       }
       




More information about the seam-commits mailing list