Author: shane.bryzak(a)jboss.com
Date: 2008-10-24 02:21:57 -0400 (Fri, 24 Oct 2008)
New Revision: 9406
Modified:
trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java
trunk/src/main/org/jboss/seam/util/TypedBeanProperty.java
Log:
optimized
Modified: trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java
===================================================================
--- trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java 2008-10-24
03:28:28 UTC (rev 9405)
+++ trunk/src/main/org/jboss/seam/security/management/JpaIdentityStore.java 2008-10-24
06:21:57 UTC (rev 9406)
@@ -520,18 +520,27 @@
throw new NoSuchRoleException("Could not delete role, role '" +
role + "' does not exist");
}
- for (Principal principal : listMembers(role))
+ if (xrefClass != null)
{
- if (SimplePrincipal.class.equals(principal.getClass()))
+ lookupEntityManager().createQuery("delete " + xrefClass.getName() +
" where role = :role")
+ .setParameter("role", roleToDelete)
+ .executeUpdate();
+ }
+ else
+ {
+ List<String> users = listUserMembers(role);
+ for (String user : users)
{
- revokeRole(principal.getName(), role);
+ revokeRole(user, role);
}
- else if (Role.class.equals(principal.getClass()))
- {
- removeRoleFromGroup(principal.getName(), role);
- }
}
+ List<String> roles = listRoleMembers(role);
+ for (String r : roles)
+ {
+ removeRoleFromGroup(r, role);
+ }
+
removeEntity(roleToDelete);
return true;
}
@@ -859,37 +868,65 @@
{
List<Principal> members = new ArrayList<Principal>();
+ for (String user : listUserMembers(role))
+ {
+ members.add(new SimplePrincipal(user));
+ }
+
+ for (String roleName : listRoleMembers(role))
+ {
+ members.add(new Role(roleName));
+ }
+
+ return members;
+ }
+
+ private List<String> listUserMembers(String role)
+ {
Object roleEntity = lookupRole(role);
if (xrefClass == null)
{
- List<String> users = lookupEntityManager().createQuery("select
u." + userPrincipalProperty.getName() +
+ return lookupEntityManager().createQuery("select u." +
userPrincipalProperty.getName() +
" from " + userClass.getName() + " u where :role member of
u." + userRolesProperty.getName())
.setParameter("role", roleEntity)
.getResultList();
+ }
+ else
+ {
+ List xrefs = lookupEntityManager().createQuery("select x from " +
xrefClass.getName() + " x where x." +
+ xrefRoleProperty.getName() + " = :role")
+ .setParameter("role", roleEntity)
+ .getResultList();
+
+ List<String> members = new ArrayList<String>();
- for (String user : users)
+ for (Object xref : xrefs)
{
- members.add(new SimplePrincipal(user));
+ Object user = xrefUserProperty.getValue(xref);
+ members.add(userPrincipalProperty.getValue(user).toString());
}
- if (roleGroupsProperty != null)
- {
- List<String> roles = lookupEntityManager().createQuery("select
r." + roleNameProperty.getName() +
- " from " + roleClass.getName() + " r where :role member
of r." + roleGroupsProperty.getName())
- .setParameter("role", roleEntity)
- .getResultList();
-
- for (String roleName : roles)
- {
- members.add(new Role(roleName));
- }
- }
+ return members;
}
-
- return members;
+
}
+ private List<String> listRoleMembers(String role)
+ {
+ if (roleGroupsProperty != null)
+ {
+ Object roleEntity = lookupRole(role);
+
+ return lookupEntityManager().createQuery("select r." +
roleNameProperty.getName() +
+ " from " + roleClass.getName() + " r where :role member of
r." + roleGroupsProperty.getName())
+ .setParameter("role", roleEntity)
+ .getResultList();
+ }
+
+ return null;
+ }
+
public List<String> listGrantableRoles()
{
StringBuilder roleQuery = new StringBuilder();
Modified: trunk/src/main/org/jboss/seam/util/TypedBeanProperty.java
===================================================================
--- trunk/src/main/org/jboss/seam/util/TypedBeanProperty.java 2008-10-24 03:28:28 UTC (rev
9405)
+++ trunk/src/main/org/jboss/seam/util/TypedBeanProperty.java 2008-10-24 06:21:57 UTC (rev
9406)
@@ -102,6 +102,11 @@
}
}
+ public String getName()
+ {
+ return name;
+ }
+
public boolean isSet()
{
return set;
Show replies by date