Spring security Spring安全性不允许POST方法

Spring security Spring安全性不允许POST方法,spring-security,Spring Security,我开始在一个个人项目上使用SpringSecurity,我只想公开一条路径。为了做到这一点,我喜欢这样做 @Override protected void configure(HttpSecurity http) throws Exception { //Enabling access to my public End Points (No authentication needed) http.authorizeRequests() .antMatch

我开始在一个个人项目上使用SpringSecurity,我只想公开一条路径。为了做到这一点,我喜欢这样做

@Override
protected void configure(HttpSecurity http) throws Exception {

    //Enabling access to my public End Points (No authentication needed)
    http.authorizeRequests()
            .antMatchers(HttpMethod.POST, "/login").permitAll();

}
问题是,现在我所有的POST请求都返回Forbbiden,而GET可以自由访问

你们有什么线索吗


提前感谢

很可能是因为您没有提供CSRF代币
websecurityConfigureAdapter
默认情况下为所有POST请求启用CSRF保护

您可以查看以了解如何修改其行为,并了解其实际操作。默认匹配器(
defaultrequiressrfmatcher
)也在
CsrfFilter
中定义

http.authorizeRequests()
            .antMatchers("/login").permitAll()
            .anyRequest().authenticated()
            .and().csrf().disable();
上面的代码帮了我的忙,谢谢大家的帮助