HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
HttpSession session = req.getSession();
User user = (User) session.getAttribute("user");
ActionErrors errors = new ActionErrors();
if (user != null) {
boolean hasRole = false;
for (int i = 0; i < roleNames.length; i++) {
if (user.hasRole(roleNames[i])) {
hasRole = true;
break;
}
}
if (!hasRole) {
errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage(
"error.authorization.required"));
}
}
if (errors.isEmpty()) {
chain.doFilter(request, response);
} else {
req.setAttribute(Globals.ERROR_KEY, errors);
req.getRequestDispatcher(onFailure).forward(req, res);
}