小编Tan*_*hur的帖子

在Spring Boot应用程序中禁用HTTP OPTIONS方法

我已经在spring boot应用程序上开发了rest API。API仅接受GET和POST,但在使用OPTIONS方法请求时,API会响应200状态(而不是405)。我用谷歌搜索了这个问题,但是没有一个解决方案是基于springboot的。

响应:

Allow: OPTIONS, TRACE, GET, HEAD, POST
Public: OPTIONS, TRACE, GET, HEAD, POST
Run Code Online (Sandbox Code Playgroud)

需要禁用OPTIONS方法。

java spring-security spring-boot

6
推荐指数
1
解决办法
8037
查看次数

Spring Security在基本身份验证后抛出403

我使用Spring Security进行基本身份验证来保护我的REST API.

以下是配置代码:

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("user")
                    .password("password")
                    .roles("admin");
    }

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

        http
            .csrf().disable()
            .authorizeRequests()
                .anyRequest().authenticated();
    }
}
Run Code Online (Sandbox Code Playgroud)

我在使用正确的用户名和密码验证自己时遇到了禁止(403)错误.

在此输入图像描述

请建议修改以使其正常工作.

java spring spring-security basic-authentication

3
推荐指数
1
解决办法
2585
查看次数