I have been playing with it and made a prototype implementation and it works like a dream:
//admins are allowed to disable other users from the same application
foo.UserManager.disable=ROLE_ADMIN:arg0.applicatio n.equals(authentication.principal.user.application )
foo.UserManager.createPasswordLogin=ROLE_ANONYMOUS ,ROLE_USER,ROLE_ADMIN
foo.UserManager.createCookieLogin=ROLE_ANONYMOUS,R OLE_USER,ROLE_ADMIN
foo.UserManager.confirmPasswordLogin=ROLE_ANONYMOU S,ROLE_USER,ROLE_ADMIN
//an admin of the same application as the user is allowed to update another user
//a user is able to update himself.
foo.UserManager.update=ROLE_ADMIN:arg0.application .equals(authentication.principal.user.application) ,ROLE_USER:arg0.equals(authentication.principal.us er)
foo.UserManager.findById=ROLE_ANONYMOUS,ROLE_USER, ROLE_ADMIN
I have to do 2 things in the app context:
1) replace the RoleVoter by a different version
Code:
public int vote(Authentication auth, Object object, ConfigAttributeDefinition config) {
int result = ACCESS_ABSTAIN;
Iterator iter = config.getConfigAttributes();
while (iter.hasNext()) {
ConfigAttribute requiredAttribute = (ConfigAttribute)iter.next();
if (this.supports(requiredAttribute)) {
result = ACCESS_DENIED;
// Attempt to find a matching granted authority
for (int i = 0; i < auth.getAuthorities().length;i++) {
String requiredRole = requiredAttribute.getAttribute();
String grantedRole = auth.getAuthorities()[i].getAuthority();
if (requiredRole.equals(grantedRole)) {
if(requiredAttribute instanceof MyConfigAttribute){
MethodInvocation mi = (MethodInvocation)object;
MyConfigAttribute myAttr = (MyConfigAttribute)requiredAttribute;
myAttr.getInvocationChecker().check(mi);
}
return ACCESS_GRANTED;
}
}
}
}
return result;
}
2) Replace the ObjectDefinitionSource by one that also can handle ognl expressions.