gpt4 book ai didi

java - Spring WebSecurityConfigurerAdapter 允许 POST?

转载 作者:可可西里 更新时间:2023-11-01 16:29:38 27 4
gpt4 key购买 nike

我想为我网站上的某个“/interface”URL 启用 POST 请求。我已经通过 Class<?>[] getRootConfigClasses() 成功加载了类(class), HttpSecurity http 的指定 CSP header 存在。

每当我向 /interface 发出请求时, 我得到 HTTP 403 .

@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter
{

@Override
protected void configure(HttpSecurity http) throws Exception
{
http
.authorizeRequests().antMatchers(HttpMethod.POST, "/interface").permitAll().and()
.headers()
.contentTypeOptions().and()
.cacheControl().and()
.httpStrictTransportSecurity().and()
.frameOptions().and()
.contentSecurityPolicy("the csp header. it is present on every response.");
}
}

最佳答案

尝试覆盖另一种配置方法:configure(WebSecurity webSecurity)

@Override
public void configure(WebSecurity webSecurity) throws Exception {
webSecurity.ignoring().antMatchers(POST, "/interface");
}

关于java - Spring WebSecurityConfigurerAdapter 允许 POST?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48476279/

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