Ok, here's the scenario (a common ACL implementation):
- One User can have 0-many Roles
- One Role includes 0-many Permissions
(User m-t-m Role m-t-m Permission)
Now, I realized it would be nifty to be able to get the complete list of permission names (eg "order_add", "order_view", "order_update", etc) for all roles associated with each user, using
Code:
List permissionNames = user.getPermissionNames();
without having to do
Code:
Collection userRoles = user.getRoles();
for ( Iterator ri = userRoles.iterator(); ri.hasNext() ;) {
Role role = (Role) ri.next();
Collection rolePermissions = role.getPermissions();
for ( Iterator pi = rolePermissions.iterator(); pi.hasNext() ;) {
Permission p = (Permission) pi.next();
permissionNames.add( p.getName() );
}
}
The corresponding SQL query would be
Code:
select
distinct p.name
from
permission p
,role_permission rp
,role r
,user_role ur
,user u
where
p.id = rp.id
and rp.id = r.id
and r.id = ur.id
and ur.id = u.id
and u.name = 'foo'
Is this doable with Hib2.x (or 3.x, for that matter) ?
/Mikael