gpt4 book ai didi

java - 如何使用 Spring Security 允许所有请求?

转载 作者:行者123 更新时间:2023-12-01 16:46:36 24 4
gpt4 key购买 nike

我刚刚将 Spring Security 添加到我的项目中。我还添加了此配置:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll();
}

}

但现在并非所有端点都可以工作。事实上,只有一个端点有效,其余的我得到403 Forbidden。可能是什么问题呢?我如何允许任何和所有请求(有效地使安全性成为传递)。

最佳答案

我必须添加 .csrf().disable() 才能使其正常工作。

所以对我来说整个解决方案是

http.csrf().disable().authorizeRequests().anyRequest().permitAll();

关于java - 如何使用 Spring Security 允许所有请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61761499/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com