@Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain)
            throws IOException, ServletException {

        if (debug) {
            log("LoginFilter:doFilter()");
        }
        doBeforeProcessing(request, response);
        HttpServletRequest servletRequest = (HttpServletRequest) request;
        if (filter(servletRequest)) {
            HttpServletResponse servletResponse = (HttpServletResponse) response;
            HttpSession session = servletRequest.getSession();
            Object user = session.getAttribute("sessionUser");
            if (user == null || !(user instanceof Usuarios)) {
                if (redirectForLogin(servletRequest)) {
                    servletResponse.sendRedirect("/carrinho/login");
                    return;
                }
                servletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Sua sessão expirou.");
                return;
            }
        }
        Throwable problem = null;
        try {
            chain.doFilter(request, response);
        } catch (Throwable t) {
            problem = t;
            t.printStackTrace();
        }
        doAfterProcessing(request, response);
        if (problem != null) {
            if (problem instanceof ServletException) {
                throw (ServletException) problem;
            }
            if (problem instanceof IOException) {
                throw (IOException) problem;
            }
            sendProcessingError(problem, response);
        }
    }