Java Spring Security SAML,当使用SAMLContextProviderLB设置为HTTPS方案时,重定向到HTTP而不是HTTPS

Java Spring Security SAML,当使用SAMLContextProviderLB设置为HTTPS方案时,重定向到HTTP而不是HTTPS,java,ssl,spring-security,reverse-proxy,spring-saml,Java,Ssl,Spring Security,Reverse Proxy,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}'

附加了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}"/>
****
我在一个反向代理后面,所以我正在卸载SSL终端。后端服务器本身正在侦听非SSL,但webtier正在为我们终止SSL并转发到非SSL端口。我已经使用上述属性设置了SAMLContextProviderLB,这样即使后端是https,它也会知道将saml令牌的预期收件人映射为https访问群体。但是,我在下面的日志中看到,当我转到受保护的资源时,它会在浏览器上返回垃圾。当我在浏览器中将其更改为https时,它会按预期工作。查看下面的日志显示,从DefaultSavedRequestURL返回的值是HTTP,而它应该是HTTPs。

2016-03-07 18:24:11907 INFO org.springframework.security.saml.log.SAMLDefaultLogger.log:127-AuthNResponse;成功;10.4.203.88;;;

2016-03-07 18:24:11909调试org.springframework.security.saml.SAMLProcessingFilter.successfulAuthentication:317-验证成功。正在更新SecurityContextHolder以包含:org.springframework.security.providers。ExpiringUsernameAuthenticationToken@830e9237:校长:camachof@email.com; 凭据:[受保护];认证:正确;详细信息:空;没有授予任何权限

2016-03-07 18:24:11910调试org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler.onAuthenticationSuccess:79-重定向到DefaultSavedRequestUrl:http://myserver:89/fct/page

2016-03-07 18:24:11911调试组织springframework.security.web.DefaultRedirectStrategy.sendRedirect:36-重定向到“”

2016-03-07 18:24:11911调试org.springframework.security.web.context.httpsessionsecuritycontextextrepository.saveContext:292-存储到HttpSession的SecurityContext:'org.springframework.security.core.context。SecurityContextImpl@830e9237:身份验证:org.springframework.security.providers。ExpiringUsernameAuthenticationToken@830e9237: 负责人:camachof@email.com; 凭据:[受保护];认证:正确;详细信息:空;没有得到任何当局的批准

2016-03-07 18:24:11912调试org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter:97-请求处理完成后,SecurityContextHolder现在已清除


有没有办法在这种设置下强制使用HTTPS?提前谢谢。

这个问题很老了,但如果我发现了,其他人可能会问,所以我会发布答案

负载平衡器或反向代理(
apachehttpd
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/
ProxyPass
ProxyPassReverse
可能是您已经拥有的。但是
proxypervehost
X-Forwarded-Proto
确实很重要

查看本节的内容。如果设置了
X-Forwarded-For
X-Forwarded-Proto
,则需要将其添加到application.properties文件中:

server.use-forward-headers=true
和/或

server.forward-headers-strategy=native
取决于您使用的spring boot版本

您还将在该文档中看到,您可以为Tomcat特定配置添加以下属性:

server.tomcat.remote-ip-header=x-your-remote-ip-header
server.tomcat.protocol-header=x-your-protocol-header
除了上述内容之外,还要做所有这些,它就会开始工作。以上内容本身并不足以迫使Tomcat开始使用
https
转发请求

我发现,因为我的公司有一个基于硬件的负载平衡器(由Rackspace管理),所以很难配置它来进行这些更改。因此,我们在防火墙/负载平衡器中终止SSL,然后将请求转发到端口80上的Apache,Apache将请求转发到端口8080上的Java。是的,一团乱。但这些胡说八道都起作用了