SpringSecurity不允许匿名(anonymous)访问Post接口(403)

问题背景:系统对外暴露接口,接口路径配置了匿名访问(anonymous),Get请求可正常访问,Post请求报错403或直接跳转到登陆页。

解决方案:在SecurityConfig中关闭CSRF

httpSecurity.csrf().disable()

上述问题解决,但前端调用的时候新问题出现了。

问题背景:前端传递token调用匿名接口,报错403,不传递token可正常访问。

原因:anonymous允许匿名访问,传递token就不是匿名了,所以不能访问。

解决方案:将anonymous 改为permitAll。

最终配置:

附SpringSecurity可配置的权限类型,如下:

猜你喜欢

转载自blog.csdn.net/secretdaixin/article/details/128955214
今日推荐