* @see org.apache.lenya.workflow.impl.AbstractCondition#isComplied(Workflow, Workflowable)
*/
public boolean isComplied(Workflow workflow, Workflowable instance) {
DocumentWorkflowable workflowable = (DocumentWorkflowable) instance;
ServiceManager manager = workflowable.getServiceManager();
String url = workflowable.getDocument().getCanonicalWebappURL();
ServiceSelector selector = null;
AccessControllerResolver acResolver = null;
AccessController accessController = null;
try {
selector = (ServiceSelector) manager.lookup(AccessControllerResolver.ROLE + "Selector");
acResolver = (AccessControllerResolver) selector
.select(AccessControllerResolver.DEFAULT_RESOLVER);
accessController = acResolver.resolveAccessController(url);
PolicyManager policyManager = accessController.getPolicyManager();
Identity identity = workflowable.getSession().getIdentity();
if (identity == null) {
throw new IllegalArgumentException("The session of the workflowable "
+ workflowable + " has no identity.");
}
AccreditableManager accreditableMgr = accessController.getAccreditableManager();
Policy policy = policyManager.getPolicy(accreditableMgr, url);
RoleManager roleManager = accreditableMgr.getRoleManager();
boolean complied = false;
for (Iterator i = this.roleIds.iterator(); i.hasNext();) {
String roleId = (String) i.next();
Role role = roleManager.getRole(roleId);
if (policy.check(identity, role) == Policy.RESULT_GRANTED) {
complied = true;
}
}
return complied;
} catch (final Exception e) {
throw new RuntimeException(e);
} finally {
if (selector != null) {
if (acResolver != null) {
if (accessController != null) {
acResolver.release(accessController);
}
selector.release(acResolver);
}
manager.release(selector);
}
}
}