ajax login with spring webMVC and spring security

前端 未结 2 1932
悲&欢浪女
悲&欢浪女 2020-12-07 23:34

I\'ve been using Spring Security 3.0 for our website login mechanism using a dedicated login webpage. Now I need that login webpage to instead be a lightbox/popup window on

2条回答
  •  感动是毒
    2020-12-07 23:58

    I did something similar (thanks axtavt):

    public class AjaxAuthenticationSuccessHandler extends
        SimpleUrlAuthenticationSuccessHandler {
    
    public void onAuthenticationSuccess(HttpServletRequest request,
            HttpServletResponse response, Authentication auth)
            throws IOException, ServletException {
        if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) {
            response.getWriter().print(
                    "{success:true, targetUrl : \'"
                            + this.getTargetUrlParameter() + "\'}");
            response.getWriter().flush();
        } else {
            super.onAuthenticationSuccess(request, response, auth);
        }
    }}
    

    I chose to extend the simple success handler for the default behavior on non-Ajax requests. Here's the XML to make it work:

    
        
    ...
    ...
    
    
    
        
        
    
    
    
        
        
        
        
        
    
    
    
        
    
    
    
    

提交回复
热议问题