我正在尝试向我的应用程序添加一个不安全的 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/