* @throws ServiceException if the access controller resolver could not be created.
*/
protected void authorizeRequest() throws AccessControlException, ServiceException {
ServiceSelector selector = null;
AccessControllerResolver acResolver = null;
AccessController controller = null;
try {
selector = (ServiceSelector) this.manager.lookup(AccessControllerResolver.ROLE
+ "Selector");
acResolver = (AccessControllerResolver) selector
.select(AccessControllerResolver.DEFAULT_RESOLVER);
controller = acResolver.resolveAccessController(getSourceURL());
getLogger().debug("Add identity to session");
getLogger().debug("User ID: [" + this.userId + "]");
getLogger().debug("Machine: [" + this.machineIp + "]");
Request request = ContextHelper.getRequest(this.context);
((DefaultAccessController) controller).setupIdentity(request);
Session session = request.getSession(false);
Identity identity = (Identity) session.getAttribute(Identity.class.getName());
Identifiable[] identifiables = identity.getIdentifiables();
for (int i = 0; i < identifiables.length; i++) {
identity.removeIdentifiable(identifiables[i]);
}
UserManager userManager = ((DefaultAccessController) controller)
.getAccreditableManager().getUserManager();
if (this.userId != null) {
User user = userManager.getUser(this.userId);
if (user == null) {
throw new RuntimeException("User [" + this.userId + "] does not exist!");
}
identity.addIdentifiable(user);
}
if (this.machineIp != null) {
Machine machine = new Machine(this.machineIp);
identity.addIdentifiable(machine);
}
controller.authorize(request);
} finally {
if (selector != null) {
if (acResolver != null) {
if (controller != null) {
acResolver.release(controller);
}
selector.release(acResolver);
}
this.manager.release(selector);
}