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

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

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请求。



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

原文地址:https://54852.com/zaji/4934359.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存