/** * creates a instance of the requested provider from AuthProviderFactory and calls the * getLoginRedirectURL() method to find the URL which the user should be redirect to. * * @param mapping the action mapping * @param form the action form * @param request the http servlet request * @param response tc the http servlet response * @return ActionForward where the action should flow * @throws Exception if an error occurs */ @Override public ActionForward execute( final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception { SASFHelper helper = SASFStaticHelper.getHelper(request); AuthForm authForm = (AuthForm) form; String id = authForm.getId(); String mode = request.getParameter("mode"); ActionForward fwd = null; if (mode == null) { String filterUrl = "/SAF/SocialAuth?id=" + id; fwd = new ActionForward("openAuthUrl", filterUrl, true); } else if (mode.equals("signout")) { SocialAuthManager manager = null; if (helper != null) { manager = helper.getAuthManager(); if (manager != null) manager.disconnectProvider(id); } fwd = mapping.findForward("home"); } return fwd; }
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); } }