springBoot springSecurty OAuth2.0 x-frame-options deny

背景说明

应公司要求,需要对一个接口平台加OAuth2.0认证(客户端模式)功能,该平台有自己的管理维护页面,且页面采用了Iframe嵌套,在我加入认证功能以前,平台可以正常运行,但就在我加入认证功能之后(通过postman已经可以正常获取access_token),打开维护界面出现了问题:iframe中的页面打不开了,错误如图:

错误截图

问题原因

我的OAuth2.0是基于SpringSecurty实现的,而SpringSecurty默认使用X-Frame-Options防止网页被Frame。

解决方案

修改OAuth资源服务器的配置,加上一行代码即可,如图:

解决方案

代码:

@Override
        public void configure(HttpSecurity http) throws Exception {
            http

                    .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED).and()
                    .requestMatchers().anyRequest().and().anonymous().and().authorizeRequests()
                    .antMatchers("/rest/adi/**").authenticated()// 配置adi访问控制,必须认证过后才可以访问
                    .and().headers().frameOptions().disable();
        }

猜你喜欢

转载自blog.csdn.net/aiyo92/article/details/87918136
今日推荐