我无法在启用spring secutity的情况下访问/h2-console。
下面是配置
@Configuration
@EnableWebSecurity(debug = true)
public class WebSecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeRequests(authorizeRequests -> authorizeRequests
.requestMatchers(antMatcher("/h2-console/**")).permitAll()
.anyRequest()
.authenticated())
.httpBasic(withDefaults())
.csrf(csrf -> csrf.ignoringRequestMatchers(toH2Console()))
.csrf(httpSecurityCsrfConfigurer -> httpSecurityCsrfConfigurer.disable())
.addFilterBefore(new ProductFilter(), BasicAuthenticationFilter.class);
return http.build();
}
}
我尝试了堆栈溢出中建议的多个选项,但似乎不起作用。
1条答案
按热度按时间ldfqzlk81#
最简单的方法是为H2控制台公开一个单独的
SecurityFilterChain
,如下所示:在参考文档中有关于此的更多信息:https://docs.spring.io/spring-boot/docs/current/reference/html/data.html#data.sql.h2-web-console.spring-security