使用 Spring boot 时出现 403 禁止错误 - 安全

Sup*_*iya 3 post spring-boot

403 forbidden error在使用 Spring Boot 安全性进行基本身份验证时得到了。使用该POST方法时出现此错误。

我的主要类代码如下,

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) 
    {
       return builder.sources(MyContext.class);
    }
Run Code Online (Sandbox Code Playgroud)

请为此提出一个解决方案。谢谢

Ali*_*ien 5

我使用 Post 方法收到此错误。

上面的行提示问题是由于CSRF 保护造成的。如果用户不会在 Web 浏览器中使用您的应用程序,则禁用 CSRF 保护是安全的。否则,您应该确保在请求中包含 CSRF 令牌。

要禁用 CSRF 保护,您可以使用以下命令:

@Override
protected void configure(HttpSecurity http) throws Exception {
     http
     // ...
     .csrf().disable();
}
Run Code Online (Sandbox Code Playgroud)

参考spring-security-csrf