使用 Spring 安全启用 h2 控制台
enable h2 console with Spring Security
我想在启用 Spring 安全性的 Spring 引导项目中使用 h2 控制台。我的配置如下所示,但我无法访问任何未经身份验证的路径。如果我打开控制台路径,登录提示符就会出现。
是不是顺序错了?
我已经用 WebSecurityConfigurerAdapter 以旧方式尝试过它并且它有效,但我想使用新的东西。
@EnableWebFluxSecurity
public class SecurityConfiguration {
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
return http
.csrf().disable()
.headers().frameOptions().disable().and()
.authorizeExchange()
.anyExchange().permitAll()
.and()
.httpBasic().and()
.build();
}
}
我将配置更改为以下内容,并且身份验证像我预期的那样排除了 h2 控制台:
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.headers().frameOptions().disable().and()
.csrf().disable();
http
.authorizeRequests()
.antMatchers("/", "/h2-console/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.permitAll()
.and()
.logout()
.permitAll();
}
}
H2 控制台似乎只能在基于 servlet 的服务器上使用,而 webflux 使用的码头不是基于 servlet 的服务器。
我想在启用 Spring 安全性的 Spring 引导项目中使用 h2 控制台。我的配置如下所示,但我无法访问任何未经身份验证的路径。如果我打开控制台路径,登录提示符就会出现。
是不是顺序错了?
我已经用 WebSecurityConfigurerAdapter 以旧方式尝试过它并且它有效,但我想使用新的东西。
@EnableWebFluxSecurity
public class SecurityConfiguration {
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
return http
.csrf().disable()
.headers().frameOptions().disable().and()
.authorizeExchange()
.anyExchange().permitAll()
.and()
.httpBasic().and()
.build();
}
}
我将配置更改为以下内容,并且身份验证像我预期的那样排除了 h2 控制台:
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.headers().frameOptions().disable().and()
.csrf().disable();
http
.authorizeRequests()
.antMatchers("/", "/h2-console/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.permitAll()
.and()
.logout()
.permitAll();
}
}
H2 控制台似乎只能在基于 servlet 的服务器上使用,而 webflux 使用的码头不是基于 servlet 的服务器。