我有一个 Spring Boot 应用程序,它作为 CF 应用程序推送到 Bluemix 上。 它可以有效地与 http 协议(protocol)一起工作。但是,如果我尝试强制使用 https,则会收到 502 错误。
我有:
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.requiresChannel().anyRequest().requiresSecure();
//http.csrf().disable();
}
}
我有一个包含这些条目的 application.properties
文件:
server.ssl.key-store = classpath:**.jks
server.ssl.key-store-password = *******
server.ssl.key-password = ******
server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto
我知道 Bluemix 执行 SSL 终止;事实上它正确地设置了 x-forwarded-proto 和 x-forwarded-for。我寻找类似 1 的解决方案和 2但没有任何运气。
然后我按照 this article 中的建议尝试了以下解决方案但是收到了一个重定向循环:
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory(){
return new TomcatEmbeddedServletContainerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
}
我在方法中遗漏了什么?非常感谢您提供给我的任何提示/建议
最佳答案
为了社区的利益,很高兴看到 Rob 的评论被接受为答案。 Rob,如果您希望看到该答案被接受,请随时添加您自己的答案。
Tomcat is not detecting the x-forwarded headers as being a trusted proxy. Try setting server.tomcat.internal-proxies=.* and logging.level.org.apache.catalina.valves=DEBUG
关于ssl - Bluemix 在 Spring Boot 应用程序上强制使用 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39004986/