【问题标题】:Force Grails/Weblogic To Only Redirect Using HTTPS protocol强制 Grails/Weblogic 仅使用 HTTPS 协议重定向
【发布时间】:2014-07-03 02:37:46
【问题描述】:

我在一个项目中使用 Grails (2.2.2),我的应用程序发出了不需要的 http 重定向而不是 https 重定向。

我们目前在 Oracle Weblogic 前面有一个 F5 负载均衡器。 F5 正在从 Weblogic 卸载我们的 SSL。 F5只接受https请求,Weblogic只接受http请求。

我的 Grails 项目使用 Spring Security 和 Spring Security CAS 插件。

此问题通常发生在成功的 CAS 登录时。 Grails 似乎总是发出 HTTP 重定向。

我的 serverURL 指定 HTTPS,我的所有 CAS 配置变量也是如此。喜欢

grails.serverURL = "https://example.com/${appName}"

有没有办法强制 GRAILS/Weblogic 只发出 https 重定向?

编辑 #1 - 更多信息

我试过没有运气:

grails.plugin.springsecurity.secureChannel.useHeaderCheckChannelSecurity = true
grails.plugin.springsecurity.secureChannel.definition = [
    '/**': 'REQUIRES_SECURE_CHANNEL'
 ]
grails.plugin.springsecurity.portMapper.httpPort = 80
grails.plugin.springsecurity.portMapper.httpsPort = 443
grails.plugin.springsecurity.secureChannel.secureHeaderName = 'WL-Proxy-SSL'
grails.plugin.springsecurity.secureChannel.secureHeaderValue = 'http'
grails.plugin.springsecurity.secureChannel.insecureHeaderName = 'WL-Proxy-SSL'
grails.plugin.springsecurity.secureChannel.insecureHeaderValue = 'https'

此外,该行为似乎与不尊重协议的 Spring Security/Spring CAS 插件有关

在 j_spring_security_check 之后发生的重定向似乎总是返回一个 http 重定向而不是一个 https 重定向。 这会产生一个问题,因为我们不允许 F5 服务器上的 http 请求。 即。

https://www.example.com/grailsapp/
-> 
https://www.casserver.com/cas/login?service=https%3A%2F%2Fwww.example.com%2Fgrailsapp%2Fj_spring_cas_security_check
-> https://www.example.com/grailsapp/j_spring_cas_security_check;jsessionid=f6T8RyDZ83Z2QQQlMQ7fGXvlrs05m9hTjlBkndD6stBh1s20v2ZH!-1677111548?ticket=ST-231-4Dl5PVDe4RRLpAW5CEXb-www.casserver.com
->
http://www.example.com/grailsapp/

CAS 插件配置:

production {
    grails.plugins.springsecurity.cas.loginUri = '/login'
    grails.plugins.springsecurity.cas.serviceUrl = 'https://example.com/grailsapp/j_spring_cas_security_check'
    grails.plugins.springsecurity.cas.serverUrlPrefix = 'https://casserver.com/cas'
    grails.plugins.springsecurity.logout.afterLogoutUrl = 'https://casserver.com/cas/logout?url=https://example.com/grailsapp/'
}

【问题讨论】:

    标签: grails ssl spring-security weblogic offloading


    【解决方案1】:

    我建议您查看 Spring Security 的通道安全设置。请注意documentation中有关F5s和SSL的部分。

    我怀疑您的配置中缺少以下内容:

    grails.plugin.springsecurity.secureChannel.useHeaderCheckChannelSecurity = true
    

    我还怀疑您并没有通过设置强制您的应用程序始终在 SSL 下运行:

    grails.plugin.springsecurity.secureChannel.definition = [
       '/**': 'REQUIRES_SECURE_CHANNEL'
    ]
    

    【讨论】:

    • 过去这种配置不走运,我还更改了标题以查找“WL-Proxy-SSL”,因为这是 Weblogic。理想情况下,我什至不必对 Grails 级别的协议做任何事情。由于负载均衡器保证我的 SSL 连接。即使我像 http 一样运行 grails 应用程序中的所有内容,也应该无关紧要,因为它应该都是相对的,但这似乎并没有发生。
    • 仅仅使用 grails.plugin.springsecurity.secureChannel.definition = [ '/**': 'REQUIRES_SECURE_CHANNEL' ] 就完美了
    【解决方案2】:

    你可以考虑http://grails.org/plugin/force-ssl

    否则我们建议使用 Apache / Nginx 进行重定向

    【讨论】:

    • 嗯,我不认为 force-ssl 会做我想要的。问题是..在我当前的用例中,我永远不会发生 http 调用。我的应用程序正在通过 iFrame 显示在门户中,该门户使用 https。不幸的是,Chrome 现在会阻止发出 http 请求的 https 会话中的代码。因此,一个 http 调用会导致非常糟糕的用户体验。我很想使用 Apache,但由于我们的基础架构,我坚持使用 Weblogic。
    【解决方案3】:

    我能够通过 F5 重定向重写规则提出解决方案。不幸的是,它不如提出 Grails 解决方案那么理想,但它适用于我的环境。

    when HTTP_RESPONSE { 
      if { [HTTP::is_redirect] }{ 
            HTTP::header replace Location [string map {"http://example.com/grailsapp/" "https://example.com/grailsapp/"} [HTTP::header Location]] 
        } 
    }
    

    【讨论】:

      猜你喜欢
      • 2015-08-17
      • 2012-11-18
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多