spring - spring boot security 不允许我访问 h2-console
问题描述
我正在尝试在 Spring Boot 中实现 JWT。出于某些调试目的,我需要 H2 控制台。
所以在我的WebSecurityConfiguration我写道:
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
//httpSecurity.headers().frameOptions().disable();
httpSecurity.authorizeRequests().antMatchers("/h2").permitAll();
httpSecurity
.csrf().disable()
.authorizeRequests()
.antMatchers("/auth/check/username").permitAll()
.antMatchers("/auth/signup").permitAll()
.antMatchers("/auth/login").permitAll()
.anyRequest().authenticated().and()
.exceptionHandling().and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
}
在我的应用程序属性中,我有这个配置:
spring.h2.console.enabled=true
spring.h2.console.path=/h2
当我点击 ":8080/h2" 时,它给了我403。
所以问题仍然存在,如何正确配置 Spring Boot Web Security。
解决方案
请尝试“h2”模式为:
httpSecurity.authorizeRequests().antMatchers("/h2/**").permitAll();
这也是:
httpSecurity.headers().frameOptions().disable();
推荐阅读
- c# - EF Core:嵌套实体外键未更新
- r - 给定一个data.table,对于每列上的每个子组,选择第一个非NA
- javascript - 高级下拉菜单
- java - 您的 SQL 语法有错误;请查看与您的 MariaDB 服务器版本相对应的手册,了解在第 1 行使用 near table 的正确语法
- google-apps-script - 在高级日历更新后显示对日历事件的更改
- pine-script - 解决OCHL上执行代码的问题
- javascript - 如何在 Nuxt 中处理 setInterval
- visual-studio - 从 Visual Studio 部署到 Hololens 2 模拟器工作正常,但我无法通过 USB 部署到设备本身
- crystal-reports - 水晶报表显示线
- node.js - 错误:14 不可用:未建立连接 - Cloud Firestore