Spring Security&ExtJS-在会话超时时重定向到登录页面

Spring Security&ExtJS-在会话超时时重定向到登录页面,第1张

概述我在Spring MVC / Security中使用ExtJS.我希望在会话过期后将用户重定向到登录页面,并在Spring安全应用程序上下文中提供了该密码-<session-management invalid-session-url='/login.jsp'></session-management> 但是由于对服务器的调用全部基于

我在Spring MVC / Security中使用ExtJs.我希望在会话过期后将用户重定向到登录页面,并在Spring安全应用程序上下文中提供了该密码-

<session-management invalID-session-url="/login.Jsp"></session-management>

但是由于对服务器的调用全部基于AJAX,因此不会发生重定向.
请提出实现此目标的最佳方法.
我有一个用于AJAX登录的自定义UsernamePasswordAuthenticationFilter:

@OverrIDe    protected voID successfulAuthentication(httpServletRequest request,httpServletResponse response,Authentication authResult) throws IOException,servletexception {        SavedRequestAwareAuthenticationSuccessHandler srh = new SavedRequestAwareAuthenticationSuccessHandler();        this.setAuthenticationSuccessHandler(srh);        srh.setRedirectStrategy(new RedirectStrategy() {            @OverrIDe            public voID sendRedirect(httpServletRequest httpServletRequest,httpServletResponse httpServletResponse,String s) throws IOException {                // do nothing,no redirect            }        });        super.successfulAuthentication(request,response,authResult);        httpServletResponseWrapper responseWrapper = new httpServletResponseWrapper(         response);        Writer out = responseWrapper.getWriter();        out.write("{success:true}");        out.close();    }
最佳答案您也许可以塑造以下内容以覆盖所有AJAX请求,以测试超时的会话响应并相应地进行处理:

var origHandleResponse = Ext.data.Connection.prototype.handleResponse;Ext.overrIDe(Ext.data.Connection,{handleResponse : function(response){    var text = Ext.decode(response.responseText);    if (<test for response that means the session timed out>)    {            var login = new Ext.Window({                plain: true,closeAction: 'hIDe',modal: true,Title: "Login timed out,please log in.",wIDth: 400,autoHeight: true,items: [                {                    xtype: 'form',ID: 'login-form',items: [                    {                        xtype: 'textfIEld',fIEldLabel: 'Username',name: 'username'                    },{                        xtype: 'textfIEld',inputType: 'password',fIEldLabel: 'Password',name: 'password'                    }]                }],buttons: [                {                    text: 'submit',handler: function() {                        Ext.getCmp('login-form').getForm().submit({url: '<login url>'});                        login.hIDe();                    }                }]            });            login.show();    }    //else (optional?)    origHandleResponse.apply(this,arguments);}   

}); 总结

以上是内存溢出为你收集整理的Spring Security&ExtJS-在会话超时时重定向到登录页面 全部内容,希望文章能够帮你解决Spring Security&ExtJS-在会话超时时重定向到登录页面 所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1233912.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存