Fer*_*ndo 6 java ssl reverse-proxy spring-security spring-saml
附上SAMLContextProviderLB bean的上下文提供程序
**<property name="scheme" value="https"/>**
<property name="serverName" value="${sp.hostname}"/>
<property name="serverPort" value="#{'${sp.ssl.port}'=='' ? 443 : '${sp.ssl.port}'}"/>
<property name="includeServerPortInRequestURL" value="#{'${sp.ssl.port}'=='443' ? false : true }"/>
<property name="contextPath" value="/${sp.context.root}"/>
Run Code Online (Sandbox Code Playgroud)
我在反向代理服务器后面,所以我正在卸载SSL终端.后端服务器本身正在侦听非SSL,但是webtier正在为我们终止SSL并转发到非ssl端口.我已经设置了具有上述属性的SAMLContextProviderLB,因此即使后端是https,它也会知道将saml令牌的预期收件人映射为https受众.然而,当我访问受保护资源时,我在下面的日志中看到了它在浏览器上返回的垃圾.当我在浏览器中将其更改为https时,它可以按预期工作.查看下面的日志显示,当 DefaultSavedRequest url 应该是HTTP时,从DefaultSavedRequest url返回的值是HTTP.
2016-03-07 18:24:11,907 INFO org.springframework.security.saml.log.SAMLDefaultLogger.log:127 - AuthNResponse; SUCCESS; 10.4.203.88; https:// myserver:89/fct; https://www.myADFS.com/adfs/services/trust; camachof@email.com ;;
2016-03-07 18:24:11,909 DEBUG org.springframework.security.saml.SAMLProcessingFilter.successfulAuthentication:317 - 身份验证成功.更新SecurityContextHolder以包含:org.springframework.security.providers.ExpiringUsernameAuthenticationToken@830e9237:校长:camachof@email.com; 证书:[保护]; 认证:真实; 细节:null; 没有授予任何权力
2016-03-07 18:24:11,910 DEBUG org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler.onAuthenticationSuccess:79 - 重定向到DefaultSavedRequest网址:http:// myserver:89/fct/page
2016-03-07 18:24:11,911 DEBUG org.springframework.security.web.DefaultRedirectStrategy.sendRedirect:36 - 重定向到' http:// myserver:89/fct/page '
2016-03-07 18:24:11,911 DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository.saveContext:292 - 存储到HttpSession的SecurityContext:'org.springframework.security.core.context.SecurityContextImpl@830e9237:身份验证:org .springframework.security.providers.ExpiringUsernameAuthenticationToken @ 830e9237:校长:camachof@email.com; 证书:[保护]; 认证:真实; 细节:null; 没有授予任何权力机构
2016-03-07 18:24:11,912 DEBUG org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter:97 - SecurityContextHolder现已清除,请求处理完成
任何想法如何在此设置下强制这个到HTTPS?提前致谢.
这个问题很旧,但是如果我发现了其他人,那么我将发布答案。
您的负载平衡器或反向代理(Apache httpd或nginx)必须为您做一些额外的工作。Spring(或Spring Boot)和嵌入式Tomcat(或Jetty)认为它们正在运行http服务器。它在做什么。如果代理传递了一些标头变量,则Tomcat将开始认为它正在运行https。
以下是Apache需要的示例:
ProxyPreserveHost On
RequestHeader add X-Forwarded-Proto https
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
Run Code Online (Sandbox Code Playgroud)
ProxyPass并且ProxyPassReverse可能是您已经拥有的。但是ProxyPreserveHost和X-Forwarded-Proto真正计数。
查看Spring Boot Docs的这一部分。如果设置了X-Forwarded-For或,X-Forwarded-Proto则需要将其添加到application.properties文件中:
server.use-forward-headers=true
Run Code Online (Sandbox Code Playgroud)
您还将在该文档中看到可以为Tomcat特定的配置添加以下属性:
server.tomcat.remote-ip-header=x-your-remote-ip-header
server.tomcat.protocol-header=x-your-protocol-header
Run Code Online (Sandbox Code Playgroud)
除了上述功能之外,请执行所有其他操作,它将开始起作用。上面的内容本身不足以迫使Tomcat开始使用转发请求https。
我发现由于我的公司有一个基于硬件的负载平衡器(由Rackspace管理),因此很难对其进行配置以进行这些更改。因此,我们在防火墙/负载平衡器中执行SSL终止,然后将请求转发到端口80上的Apache,然后Apache将请求转发到端口8080上的Java。是的,这很糟。但这一切都是胡说八道。
| 归档时间: |
|
| 查看次数: |
2302 次 |
| 最近记录: |