Spring boot Spring安全性:无法启用permitAll()来发布API

Spring boot Spring安全性:无法启用permitAll()来发布API,spring-boot,spring-security,Spring Boot,Spring Security,我正在尝试将spring安全性实现到PostAPI- http?.authorizeRequests() ?.antMatchers(HttpMethod.POST, "/user/details")?.permitAll() ?.antMatchers("/user/**")?.hasRole("admin") ?.and()

我正在尝试将spring安全性实现到PostAPI-

http?.authorizeRequests()
                ?.antMatchers(HttpMethod.POST, "/user/details")?.permitAll()
                ?.antMatchers("/user/**")?.hasRole("admin")
                ?.and()
                ?.formLogin()
但是,
permitAll()
似乎不起作用。但是,如果我将
HttpMethod.POST
替换为
HttpMethod.GET
,则其下的GET请求将按照预期遵循
antMatcher
规则

POST请求有不同的方式吗?

  • Spring security默认情况下启用
    csrf
    。因此,通过您的配置,csrf已启用

  • csrf
    不适用于
    GET
    请求,但适用于
    PUT
    DELETE
    POST
    PATCH

  • 因此,出于测试目的,您也可以将其添加到配置中
    http.csrf().disable()
    和您的
    POST
    将起作用

注意

一旦它开始工作,您可以了解如何保持
csrf
启用,并将
csrf
令牌作为修改请求的一部分发送