【问题标题】:IBM Bluemix enforcing https on spring boot application(Jhipster generated)IBM Bluemix 在 Spring Boot 应用程序上强制执行 https(Jhipster 生成)
【发布时间】:2017-02-05 09:25:19
【问题描述】:

我需要对部署在 IBM Bluemix 上的 spring-boot 应用程序(生成的 jhipster)强制执行 https。我正在部署没有嵌入式 tomcat 的 spring-boot war,cloudfoundry 的文档指定 java 构建包本身提供了配置有 RemoteIPValve 的 Tomcat ,所以我不需要像 StackoverFlow 上的许多答案所指定的那样添加下面的标题。

server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto

我还在安全配置中添加了以下代码

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.requiresChannel().anyRequest().requiresSecure();
}

我的应用仍然没有被重定向到 https。

我也有一个疑问,如果在 bluemix 域上执行 https ,那么对于自定义域也同样有效吗?

谢谢, 瓦苏

【问题讨论】:

  • 您是否在应用程序属性中尝试了 security.require-ssl=true?
  • 是的,David 我也试过了,但是没有用。

标签: tomcat https spring-boot ibm-cloud jhipster


【解决方案1】:

应用 Yaml 配置

服务器:

  tomcat:
     remote_ip_header: x-forwarded-for
     protocol_header: x-forwarded-proto

上面的tomcat headers告诉服务器原始请求是http还是https,

在 ResourceServerConfigurerAdapter 中的方法 configure(...) 中重写:configure(...),我们必须添加以下行

if (profile.equalsIgnoreCase(Constants.SPRING_PROFILE_PRODUCTION)) { http.requiresChannel().anyRequest().requiresSecure(); }

【讨论】:

    猜你喜欢
    • 2016-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    • 2021-06-24
    相关资源
    最近更新 更多