public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
      throws ServletException, IOException {
    HttpServletRequest request = (HttpServletRequest) req;
    if (!isTokenValid(request)) {
      ((HttpServletResponse) resp).sendRedirect("/error.ctrl");
    }
    saveToken(request);
    chain.doFilter(req, resp);
  }