作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们在 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/
我是一名优秀的程序员,十分优秀!