【发布时间】:2019-11-30 04:28:08
【问题描述】:
我有一个非常简单的 spring boot 应用程序,它作为一个控制器:
@RestController
public class HomeController {
@GetMapping(path = "/")
public String getHome() {
return "Hello world";
}
}
以及执行 https 的以下安全配置:
@Configuration
public class SslWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// require https!
http.requiresChannel().anyRequest().requiresSecure();
}
}
application.properties 看起来像这样:
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto
maven 依赖项是:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
manifest.mf 看起来像这样:
applications:
- name: jt-demo
memory: 1G
instances: 1
path: ./target/demo.jar
buildpacks:
- https://github.com/cloudfoundry/java-buildpack#v4.17.2
env:
JAVA_OPTS: -Djava.security.egd=file:///dev/urandom
JBP_CONFIG_OPEN_JDK_JRE: '{jre: { version: 11.+ }}'
我通过以下命令在两个不同的 cloudfoundry 提供商(pivotal 和 swisscom)上安装应用程序:cf push jt-demo -f manifest.yml
当我在 https://run.pivotal.io 上运行此应用程序并通过 https 访问它时,它会按预期工作,并且浏览器会向我显示预期的“Hello world”。但是当我在 swisscom 开发者应用程序云 (https://developer.swisscom.com) 上运行它时,我会得到 ERR_TOO_MANY_REDIRECTS(很多 302)。
似乎两个 cloudfoundry 环境处理 HTTPS 的方式不同。
我知道 pivotal 运行 cf api 版本 2.138.0 而 swisscom 有 2.136.0 - 但我不认为这是原因。
如何修复 swisscom dev 的应用程序/配置?
【问题讨论】: