如何在Spring Security中启用POST,PUT和DELETE方法

如何在Spring Security中启用POST,PUT和DELETE方法,第1张

如何在Spring Security中启用POST,PUT和DELETE方法

更新答案

如果您使用的是Spring Security 4,则可以轻松禁用特定路由

http.csrf().ignoringAntMatchers("/nocsrf","/ignore/startswith.*", null);    @Override    public boolean matches(HttpServletRequest request) {        // No CSRF due to allowedMethod        if(allowedMethods.matcher(request.getMethod()).matches()) return false;        // No CSRF due to api call        if(apiMatcher.matches(request)) return false;        // CSRF for everything else that is not an API call or an allowedMethod        return true;    }});

原始答案

您收到错误消息是因为Spring Security默认将CSRF处理设置为“开”。

您可以通过添加禁用它

http.csrf().disable();

但是,实际上,您会将应用程序置于不安全状态吗?我邀请您阅读
本文以保护您的应用程序免受CSRF的侵害,即使您的应用程序基于REST服务而不是表单提交也是如此。



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

原文地址: http://outofmemory.cn/zaji/5152953.html

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

发表评论

登录后才能评论

评论列表(0条)

保存