首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Spring Security启用h2控制台

使用Spring Security启用h2控制台
EN

Stack Overflow用户
提问于 2019-08-04 20:19:20
回答 1查看 891关注 0票数 0

我想在我的Spring Boot项目中使用h2-console,同时启用Spring Security。我的配置如下所示,但我无法访问任何未经身份验证的路径。如果我打开控制台路径,登录提示符就会出现。

有什么东西顺序错了吗?

我用WebSecurityConfigurerAdapter用旧的方法试过了,它起作用了,但我想用新的东西。

代码语言:javascript
复制
@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控制台:

代码语言:javascript
复制
@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();
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-04 23:35:20

H2控制台似乎只在基于servlet的服务器上可用,而webflux使用的是jetty,它不是基于servlet的服务器。

h2 no accessible

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57346505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档