H2数据库控制台春季启动加载被X-Frame-Options拒绝



我正在为具有spring4引导安全性和其他功能的开发人员构建一个框架项目。在尝试登录到数据库控制台并管理我的数据库时使用H2,我得到了以下错误。页面是空白的,在firebug konsole:中有4个错误

 Load denied by X-Frame-Options: http://localhost:8080/console

带有到的链接

/header.jsp?jsessionid=f71207a702c9177e57208414721bbe93 does not permit framing.
/query.jsp?jsessionid=f71207a702c9177e57208414721bbe93 does not permit framing.
/help.jsp?jsessionid=f71207a702c9177e57208414721bbe93 does not permit framing.
/tables.do?jsessionid=f71207a702c9177e57208414721bbe93 does not permit framing.
  1. 我可以从控制台级别测试连接-可以
  2. DB运行良好,import.sql运行良好,我可以在spring启动时创建用户实体

我使用的配置来自(它在spring3.2上使用xml配置)

spring-boot默认H2 jdbc连接(和H2控制台)

使用:弹簧引导启动器父级1.1.4.释放

也可以通过以下方式简化@chrsciu的答案:

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.headers().frameOptions().disable();
  }
}

将下面的代码添加到Application.java中,目前它可以工作,默认在8082端口,从spring-app开始。它没有切中要害,但出于开发目的,一切都还好

@Bean
org.h2.tools.Server h2Server() {
    Server server = new Server();
    try {
        server.runTool("-tcp");
        server.runTool("-tcpAllowOthers");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return server;
}

这对我有效:

@EnableWebSecurity
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.headers().addHeaderWriter(
            new XFrameOptionsHeaderWriter(
                new WhiteListedAllowFromStrategy(Arrays.asList("localhost"))));
    }
}

当然,当应用程序在不同于localhost的地方运行时,应该调整白名单的内容。

相关内容

最新更新