Spring boot Spring security requireSecure重定向循环
默认注销方法使用以下配置生成重定向到HTTP url。当我添加Spring boot Spring security requireSecure重定向循环,spring-boot,spring-security,Spring Boot,Spring Security,默认注销方法使用以下配置生成重定向到HTTP url。当我添加.requireChannel().anyRequest().requirescure()时,它进入重定向循环。据我所知,这是因为spring发出HTTPS请求,tomcat将其转换为http请求,然后spring再次尝试执行HTTPS请求,这就是循环?不确定。这种循环发生在根url上 我试着添加 server.tomcat.remote-ip-header = x-forwarded-for server.tomcat.protoc
.requireChannel().anyRequest().requirescure()
时,它进入重定向循环。据我所知,这是因为spring发出HTTPS请求,tomcat将其转换为http请求,然后spring再次尝试执行HTTPS请求,这就是循环?不确定。这种循环发生在根url上
我试着添加
server.tomcat.remote-ip-header = x-forwarded-for
server.tomcat.protocol-header = x-forwarded-proto
server.use-forward-headers: true
创建属性文件,但没有任何效果
httpSecurity
.csrf().disable()
.anonymous()
.and()
.exceptionHandling()
.authenticationEntryPoint(new OowAccessDeniedEntryPoint())
.and()
.authorizeRequests()
.antMatchers(ignoreStaticResourceMatchers()).permitAll()
.antMatchers(ignoreEndpointMatchers()).permitAll()
.anyRequest().authenticated()
.and()
.oauth2Login()
.and()
.rememberMe()
.key(key)
.rememberMeServices(new OowTokenBasedRememberMeServices(key, cookies, encrypt, gson))
.and()
.logout()
目前正在计划解决这个问题,但我有点惊讶,在抓取了6个小时的网页后,我还没有找到解决这个问题的方法。解决方法是
static class OowLogoutSuccessHandler implements LogoutSuccessHandler {
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
log.debug("Logout success");
}
}
但是我觉得下面的代码解决了这个问题
(1) application.yml
server:
use-forward-headers: true
(2) 在服务器中/etc/apache2/sites enabled/oow.com le ssl.conf
RequestHeader set X-Forwarded-Proto https
RequestHeader set X-Forwarded-Port 443
(2.1)并使用
sudo a2enmod headers
在和的帮助下将其组合在一起