如何继续侦听端口80(http),但在Spring Boot应用程序中为登录页面发送302重定向到端口443(https)。我需要这个,因为我的应用程序是F5 BigIP代理的后面,它终止SSL证书并将http请求发送到我的应用程序,目前,我看到了这种行为:
这是当前有缺陷的流程:
我的Spring Boot应用程序重定向到(HTTP)myapp.example.com/login作为客户端的302指令
客户请求( HTTP )myapp.example.com/login
F5 BigIP拒绝HTTP请求
通缉流程:
我的Spring Boot应用程序将重定向发送到(HTTPS)myapp.example.com/login作为302到客户端(Location =(HTTPS)myapp.example.com/login)
F5 BigIP转换为(HTTP)myapp.example.com/login
我使用的是Spring Boot 1.2.8版,我的应用程序是F5 BigIp负载均衡器的后面。 BigIP终止SSL证书,并将所有HTTPS请求重定向到仅在端口80(http)上侦听的Spring Boot应用程序。
@Configuration
public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/error", "/js/**", "/css/**", "/img/**", "/help", "/favicon.ico").permitAll()
.anyRequest().hasAuthority("USER")
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login-error")
.permitAll()
.and()
.exceptionHandling().accessDeniedPage("/403")
.and()
.logout()
.permitAll();
}
}
我按照//docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-enable-https文档添加:
这些application.properties:
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto
server.tomcat.internal-proxies=x\.x\.x\.x|x\.x\.x\.x (I tested without this parameter as well)
BTW:使用http.requiresChannel()强制HTTPS.anyRequest()。requiresSecure();在这种情况下不起作用,因为我需要来自HTTP上的F5 BigIp的第二个请求才能工作,使用此设置将循环整个重定向舞蹈。
我需要配置我的应用以将由BigIP代理的客户端请求https://myApp.example.com重定向到http://myApp.example.com/ 至https://myApp.example.com/login,以便F5 BigIP接受它。
这是卷曲请求的结果: curl -L -b -vk --ur https://myApp.example.com --verbose -vs> curl-output.txt 2>& 1
STATE: INIT => CONNECT handle 0x440f160; line 1392 (connection #-5000)
* Rebuilt URL to: https://myApp.example.com/
* Added connection 0. The cache now contains 1 members
* STATE: CONNECT => WAITRESOLVE handle 0x440f160; line 1428 (connection #0)
* Trying XXX.XX.XX.XXX...
…
* SSL certificate verify ok.
* STATE: PROTOCONNECT => DO handle 0x440f160; line 1596 (connection #0)
} [5 bytes data]
> GET / HTTP/1.1
> Host: myApp.example.com
> User-Agent: curl/7.58.0
> Accept: */*
…
< HTTP/1.1 302
…
< X-XSS-Protection: 1; mode=block
* Added cookie JSESSIONID="4CE1A6F2AB684C6E01774E5289AF2AC0" for domain myApp.example.com, path /, expire 0
< Set-Cookie: JSESSIONID=4CE1A6F2AB684C6E01774E5289AF2AC0;path=/;HttpOnly
****< Location: http://myApp.example.com/login <- this needs to be HTTPS****
< Date: Wed, 09 May 2018 22:30:36 GMT
…
* Connection #0 to host myApp.example.com left intact
* Issue another request to this URL: 'http://myApp.example.com/login' <- this needs to be HTTPS
* STATE: PERFORM => CONNECT handle 0x440f160; line 1949 (connection #-5000)
* Added connection 1. The cache now contains 2 members
* STATE: CONNECT => WAITRESOLVE handle 0x440f160; line 1428 (connection #1)
* Trying XXX.XX.XX.XXX...
* TCP_NODELAY set
* STATE: WAITRESOLVE => WAITCONNECT handle 0x440f160; line 1509 (connection #1)
* connect to XXX.XX.XX.XXX port 80 failed: Connection refused
* Failed to connect to myApp.example.com port 80: Connection refused<= Not the result we want
* Closing connection 1
答案 0 :(得分:0)
这个问题在服务器端从未解决过。负责BIG IP的系统工程师改变了一些配置设置,现在,它的工作就像他们希望它工作一样。我还没有问过Big-IP配置是如何工作的。如果可能的话,当我发现时,我会发布一些东西。