HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
// if the requested page is the onFailure page continue
// down the chain to avoid an infinite redirect loop
if (req.getServletPath().equals(onFailure)) {
chain.doFilter(request, response);
return;
}
HttpSession session = req.getSession(); // get the session or create it
User user = (User) session.getAttribute("user");
if (user == null) {
// redirect to the login page
res.sendRedirect(req.getContextPath()+onFailure);
}
else {
chain.doFilter(request, response);
}