spring boot in a frame because it set ‘X-Frame-Options‘ to ‘deny‘

在spring boot security 项目中出现不能加载iframe.

解决:

@Override
    protected void configure(HttpSecurity http) throws Exception {
       
        //  允许所有用户访问"/"和"/index.html"
        http.authorizeRequests()
                .antMatchers("/js/**").permitAll()
                .anyRequest().authenticated()   // 其他地址的访问均需验证权限
                .and()
                .formLogin()
                .loginPage("/login")   //  登录页
                .defaultSuccessUrl("/index")
                .usernameParameter("username")
                .passwordParameter("password")
                .and()
                .headers().frameOptions().disable()// 不加报 in a frame because it set 'X-Frame-Options' to 'deny'.
                .and().csrf().disable(); // TODO spring security的跨域保护(CSRF Protection) CSRF是指跨站请求伪造(Cross-site request forgery),是web常见的攻击之一。
    }

猜你喜欢

转载自blog.csdn.net/csl12919/article/details/113094953
今日推荐