Java Spring安全性-基本身份验证

Java Spring安全性-基本身份验证,java,spring,spring-security,spring-boot,basic-authentication,Java,Spring,Spring Security,Spring Boot,Basic Authentication,我试图使用POST请求插入数据,但收到403错误。当我使用GET时,基本的身份验证工作。为了进行测试,我使用Fiddler 有什么问题吗 安全配置: @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exce

我试图使用POST请求插入数据,但收到403错误。当我使用GET时,基本的身份验证工作。为了进行测试,我使用Fiddler

有什么问题吗

安全配置:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/**").hasRole("USER").and()
                .httpBasic();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth)
            throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("user")
                    .password("password")
                    .roles("USER");
    }
}
请求-员额:

User-Agent: Fiddler
Host: localhost:8080
Content-Length: 200
Content-Type: application/json
Authorization: Basic dXNlcjpwYXNzd29yZA==
请求机构:

{"name" : "name1",
"description" : "desc1"}
试试这个:

@Configuration
@EnableWebSecurity
public class HelloWebSecurityConfiguration
   extends WebSecurityConfigurerAdapter {

  @Autowired
  public void configureGlobal(AuthenticationManagerBuilder auth) {
    auth
      .inMemoryAuthentication()
        .withUser("user").password("password").roles("USER");
  }
}

来源:

可能是CSRF,spring security默认启用它。在GET请求中查找X-XSRF-TOKEN头,并在帖子中使用该头和值

在执行此操作之前请三思,但可以使用禁用csrf

http.csrf().disable()

不太清楚:您是否试图使用表单和POST登录/插入数据等,并且它不适用于SpringSecurity,但GET可以?