Как мне продолжать прослушивать порт 80 (http), но отправить перенаправление 302 на порт 443 (https) в приложении Spring Boot для страницы входа в систему.Мне это нужно, потому что мое приложение находится за прокси-сервером Big5 F5, который завершает SSL-сертификат и отправляет запросы http моему приложению, и в настоящее время я наблюдаю такое поведение:
Это текущий дефектный поток :
- Клиентские запросы https://myapp.example.com
- F5 BigIP переводится в (HTTP) myapp.example.com
мое приложение 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 отвечает со страницей входа в систему и все Honky Dory
Я использую Spring Boot версии 1.2.8, и мое приложение работает за балансировщиком нагрузки FI BigIp.BigIP завершает SSL-сертификат и перенаправляет все HTTPS-запросы приложению Spring Boot, прослушивающему ТОЛЬКО порт 80 (http).
@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: форсирование HTTPS с помощью http.requiresChannel (). anyRequest() .requiresSecure ();в этом случае не работает, потому что мне нужен второй запрос, исходящий от FI BigIp по HTTP, для работы с этим параметром будет зацикливаться весь танец перенаправления.
Мне нужно настроить приложение для перенаправления клиентского запросаhttps://myApp.example.com, который BigIP передает через http://myApp.example.com/ В https://myApp.example.com/login, поэтому FIP BigIP принимает его.
Это результат запроса curl: curl -L-b -vk --url 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