更新答案
如果您使用的是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服务而不是表单提交也是如此。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)