Java HttpSecurity配置-允许所有仍然需要基本的身份验证
我正试图将一个不安全的控制器端点Java HttpSecurity配置-允许所有仍然需要基本的身份验证,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,我正试图将一个不安全的控制器端点/foo/bar添加到我的应用程序中,但每当我尝试调用它时,就会得到401个未经授权的 这是我的网站安全配置适配器: http .authorizeRequests() .antMatchers("/foo/**").permitAll() .and() .formLogin() .loginPage("/login").permitAll() .and() .requestMatchers(
/foo/bar
添加到我的应用程序中,但每当我尝试调用它时,就会得到401个未经授权的
这是我的网站安全配置适配器
:
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();
}
我不确定您的配置中的层次结构是什么,但它似乎不正确
尝试:
/GET或POST应该允许foo/bar,或者两者都允许?@Sanj它不应该与身份验证机制有关,方法由RequestMapping过滤掉
http
.formLogin()
.loginPage("/login")
.and()
.authorizeRequests()
.antMatchers("/foo/**").permitAll()
.anyRequest().authenticated();