我正在制作网站,我必须使用SecurityFilterChain。 顺便说一句,起始页 - localhost:8080/始终是安全的。 当我输入 localhost:8080/时,浏览器总是要求我登录。 如何调整“/”模式上的permitAll?
public class SecurityConfig {
@Bean
public SecurityFilterChain web(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(auth -> {
auth.requestMatchers("/", "/hello").permitAll();
auth.anyRequest().authenticated();
})
.formLogin(Customizer.withDefaults())
.build();
}
}
当我输入 localhost:8080/时,我希望看到该页面,而不是登录页面。
最佳答案
我找到了答案。 没有用“/”映射的分页。 当我映射“/”页面后,它就工作了。 我认为它应该显示白页,但似乎如果起始页是白页,那么即使有permitAll允许,它也会打印登录页。
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello(){
return "hello";
}
@GetMapping("/hello2")
public String hello2(){
return "hello2";
}
//
// @GetMapping("/")
// public String start(){
// return "startpage";
// }
}
关于java - allowedAll requestMatchers 不适用于 "/"模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75020008/