public void doFilter(
      final HttpServletRequest req, final HttpServletResponse res, final FilterChain fc)
      throws Exception {
    SASFHelper h =
        new DefaultSASFHelper(req, this.props, this.sdbSocialAuthManager, req.getSession());
    String path = lookupPath(req);
    if (path != null && path.startsWith(h.getServletMain())) {
      try {
        if (path.equals(h.getServletSuccess())) {
          SocialAuthManager manager = h.getAuthManager();
          AuthProvider provider = manager.connect(SocialAuthUtil.getRequestParametersMap(req));
          h.setProvider(provider);
          res.sendRedirect(h.getWebappSuccessAction());
          return;
        } else {
          String id = req.getParameter("id");
          SocialAuthManager socialAuthManager = null;
          synchronized (req.getSession()) {
            if (h.getAuthManager() != null) {
              socialAuthManager = h.getAuthManager();
            } else {
              socialAuthManager = h.getMgr().getSocialAuthManager();
              h.setAuthManager(socialAuthManager);
            }
          }

          res.sendRedirect(socialAuthManager.getAuthenticationUrl(id, h.getOpenidReturnUrl()));
          return;
        }
      } catch (Throwable t) {
        h.setError(t.getMessage(), t);
        res.sendRedirect(h.getErrorPage());
        return;
      }
    }
    if (!res.isCommitted()) {
      fc.doFilter(req, res);
    }
  }