So I started writing a DelegatingAccessDecisionVoter, which accept an AccessDecisionManager in the constructor. Here is what I have:
Code:
public class DelegatingAccessDecisionVoter implements AccessDecisionVoter {
private AccessDecisionManager accessDecisionManager;
public DelegatingAccessDecisionVoter(
AccessDecisionManager accessDecisionManager) {
super();
Assert.notNull(accessDecisionManager,
"An AccessDecisionManager is mandatory");
this.accessDecisionManager = accessDecisionManager;
}
public boolean supports(ConfigAttribute attribute) {
return accessDecisionManager.supports(attribute);
}
public boolean supports(Class clazz) {
return accessDecisionManager.supports(clazz);
}
public int vote(Authentication authentication, Object object,
ConfigAttributeDefinition config) {
Iterator iter = config.getConfigAttributes().iterator();
while (iter.hasNext()) {
ConfigAttribute attr = (ConfigAttribute) iter.next();
if (this.supports(attr)) {
try {
accessDecisionManager
.decide(authentication, object, config);
} catch (AccessDeniedException e) {
return AccessDecisionVoter.ACCESS_DENIED;
} catch (InsufficientAuthenticationException e) {
return AccessDecisionVoter.ACCESS_DENIED;
}
return AccessDecisionVoter.ACCESS_GRANTED;
}
}
return AccessDecisionVoter.ACCESS_ABSTAIN;
}
public AccessDecisionManager getAccessDecisionManager() {
return accessDecisionManager;
}
}
This does allow me to use existing decision managers, but I seem unable to support this scenario: (Role_A AND (Role_B OR Role_C).
The config attribute definition would be ["Role_A", "Role_B", "Role_C"]
Here is the config I tried (unsuccessfully):
HTML Code:
UnanimousBased
RoleVoter
-> supports "Role_A"
DelegatingVoter
AffirmativeBased
RoleVoter
-> supports "Role_B"
RoleVoter
-> supports "Role_C"
With this config (and my above implementation of the Delegating voter), a user that has only "Role_A" is still granted access.
I understand expression support in the upcoming release may make this AND/OR logic possible, but does anyone see a way to make it work in 2.0?