栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring防止Ajax调用成为身份验证的目标URL

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring防止Ajax调用成为身份验证的目标URL

我的解决方案受Rob Winch的回答启发。尽管在我的场景中,Spring 正在 保存已

X-Requested-With:XMLHttpRequest
设置的请求。这些是我不得不忽略的要求。

我创建了一个类作为自定义

RequestCache
类。

@Service("customRequestCache")public class CustomRequestCache extends HttpSessionRequestCache { //this class (bean) is used by spring security    @Override    public void saveRequest(HttpServletRequest request, HttpServletResponse response) {        if (!"XMLHttpRequest".equalsIgnoreCase(request.getHeader("X-Requested-With"))) { //request is not ajax, we can store it super.saveRequest(request, response);        } else { //do nothing, add some logs if you want        }    }}

然后,在我的spring安全配置中:

<http>    <request-cache ref="customRequestCache" /></http>

使用此自定义请求缓存类后,不再存储ajax请求。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/381170.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号