* @return All users which have the role on this URL.
* @throws AccessControlException if an error occurs.
*/
public static final User[] getUsersWithRole(ServiceManager manager, String webappUrl,
String role, Logger logger) throws AccessControlException {
ServiceSelector selector = null;
AccessControllerResolver resolver = null;
AccessController controller = null;
try {
selector = (ServiceSelector) manager.lookup(AccessControllerResolver.ROLE + "Selector");
resolver = (AccessControllerResolver) selector
.select(AccessControllerResolver.DEFAULT_RESOLVER);
controller = resolver.resolveAccessController(webappUrl);
AccreditableManager accreditableManager = controller.getAccreditableManager();
UserManager userManager = accreditableManager.getUserManager();
User[] users = userManager.getUsers();
List usersWithRole = new ArrayList();
PolicyManager policyManager = controller.getPolicyManager();
Role roleObject = accreditableManager.getRoleManager().getRole(role);
for (int i = 0; i < users.length; i++) {
Identity identity = new Identity(logger);
identity.addIdentifiable(users[i]);
Role[] roles = policyManager.getGrantedRoles(accreditableManager, identity,
webappUrl);
if (Arrays.asList(roles).contains(roleObject)) {
usersWithRole.add(users[i]);
}
}
return (User[]) usersWithRole.toArray(new User[usersWithRole.size()]);
} catch (ServiceException e) {
throw new AccessControlException(e);
} finally {
if (selector != null) {
if (resolver != null) {
if (controller != null) {
resolver.release(controller);
}
selector.release(resolver);
}
manager.release(selector);
}
}
}