spring security ajax 跳转登录页
来源:互联网 发布:衣柜要做到顶吗 知乎 编辑:程序博客网 时间:2024/05/18 03:44
对于 ajax 无法捕获302的原理参考
http://www.cnblogs.com/dudu/p/ajax_302_found.html
大体流程为
ajax -> browser -> server -> 302 -> browser(redirect) -> server -> browser -> ajax callback
结论
如果你想在ajax请求中根据302响应通过location.href进行重定向是不可行的。
下面进行解决方案
1.新增
public class AjaxAwareLoginUrlAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint {
public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException, ServletException {
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access Denied");//对于ajax请求不重定向 而是返回错误代码
} else {
super.commence(request, response, authException);
}
}
}
2.配置 springSecurity
<beans:bean id="authEntryPoint" class="org.springframework.web.filter.AjaxAwareLoginUrlAuthenticationEntryPoint" scope="singleton">
<beans:property name="loginFormUrl" value="/login.html" />
</beans:bean>
<http auto-config="true" entry-point-ref="authEntryPoint">
……
3.前台页面
$(document).ready(function(){
$.ajaxSetup({
complete: function(xmlHttp) {
if(xmlHttp.status==403){
location.href= //跳转到登陆页面
}
}
});
});
- spring security ajax 跳转登录页
- 理解Spring Web Security实现Ajax登录
- Spring security invalid-session-url 的坑(配了permitAll仍然跳转到登录页)
- 解决:spring security 登录页停留时间过长 跳转至 403页面
- Spring security 3中登录后跳转到不同页面
- spring security 处理session 超时跳转到登录页面
- spring security起步二:自定义登录页
- spring security起步二:自定义登录页
- spring security 登录验证
- spring Security 登录验证
- Spring security登录原理
- spring security手动登录
- Spring security注销登录
- spring security登录验证
- ajax登录过期跳转
- spring security 采用 数据库配置检测用户登录,并跳转不同页面
- spring security 登录根据用户角色跳转到不同的页面
- 总结一下关于 spring-security 3 ajax session 超时首页无法跳转的问题
- gdb调试&C语言指针高级编程(5.7)
- 电信141p123第32题
- [leetcode]Remove Nth Node From End of List
- iOS多线程为什么会出现不安全的情况
- P123.36T 切换时间显示
- spring security ajax 跳转登录页
- shell编程
- HDU5052 Yaoge’s maximum profit(树链剖分)点权更新,经典题
- Codeforces Round #162 (Div. 1) B dp
- POJ2081
- 今天在CentOS6.4操作系统下安装了Oracle客户端
- 循环队列的基本用法(链式存储结构)
- Ubuntu 12.04(64位)安装Android Studio 全过程
- linux grep命令详解