我想在我的Spring Boot项目中使用h2-console,同时启用Spring Security。我的配置如下所示,但我无法访问任何未经身份验证的路径。如果我打开控制台路径,登录提示符就会出现。
有什么东西顺序错了吗?
我用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();
}
}发布于 2019-08-04 23:35:20
H2控制台似乎只在基于servlet的服务器上可用,而webflux使用的是jetty,它不是基于servlet的服务器。
https://stackoverflow.com/questions/57346505
复制相似问题