gpt4 book ai didi

java - HttpSecurity 配置 - permitall 仍然需要基本身份验证

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:16:31 24 4
gpt4 key购买 nike

我正在尝试向我的应用程序添加一个不安全的 Controller 端点 /foo/bar,但每当我尝试调用它时,我都会收到 401 Unauthorized

这是我的 WebSecurityConfigurerAdapter:

http
.authorizeRequests()
.antMatchers("/foo/**").permitAll()
.and()
.formLogin()
.loginPage("/login").permitAll()
.and()
.requestMatchers()
.antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access")
.and()
.authorizeRequests()
.anyRequest().authenticated();

有人能指出我遗漏了什么吗?

最佳答案

在一个 authorizeRequests 部分中连接多个 antMatchers:

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/foo/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage("/login").permitAll();
}

关于java - HttpSecurity 配置 - permitall 仍然需要基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36252941/

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