gpt4 book ai didi

spring - 如何让 SpringSecurity/Grails 与终止 SSL 的负载均衡器很好地配合

转载 作者:行者123 更新时间:2023-11-28 21:50:18 24 4
gpt4 key购买 nike

我们在 Tomcat 上部署了一个 Grails 应用程序,该应用程序部署在终止 SSL 的负载均衡器后面(负载均衡器然后与端口 8080 上的 tomcat 实例通信)。我们已经将 SpringSecurity 配置为需要所有资源的安全通道,注意来自负载均衡器的 header ,强制使用 https 并映射来自负载均衡器的端口:

grails.plugin.springsecurity.secureChannel.useHeaderCheckChannelSecurity = true
grails.plugin.springsecurity.auth.forceHttps = true
grails.plugin.springsecurity.portMapper.httpPort = 80
grails.plugin.springsecurity.portMapper.httpsPort = 443
grails.plugin.springsecurity.secureChannel.definition = [
'/**': 'REQUIRES_SECURE_CHANNEL'
]

其中大部分工作正常 - 来自 Grails 内部的重定向正按预期使用 https 协议(protocol),以及大多数 ajax 请求。

但是有一些 ajax 请求正常工作。它们都与与 j_spring_security_check 等 j_spring_security* 端点交互的结果有关。例如,如果用户尝试通过 ajax 登录,我们会在浏览器中收到此错误(这是成功登录启动的重定向):

 Mixed Content: The page at 'https://www.servernamehere.com/' was loaded over HTTPS, but 
requested an insecure XMLHttpRequest endpoint 'http://www.servernamehere.com/login/ajaxSuccess'.
This request has been blocked; the content must be served over HTTPS.

认证失败会出现同样的问题:

Mixed Content: The page at 'https://www.servernamehere.com/' was loaded over HTTPS, but requested 
an insecure XMLHttpRequest endpoint 'http://www.servernamehere.com/login/authfail?ajax=true'.
This request has been blocked; the content must be served over https.

我们如何配置 spring security 来理解来自身份验证事件的所有重定向都需要是 https?

最佳答案

我们能够通过创建自定义重定向策略(实现 org.springframework.security.web.RedirectStrategy)并用我们的自定义重定向策略 bean 替换默认重定向策略 bean 来解决此问题。自定义重定向策略检查负载均衡器传入的 header ,并确保将响应重定向到适当的协议(protocol)

关于spring - 如何让 SpringSecurity/Grails 与终止 SSL 的负载均衡器很好地配合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27413217/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com