2016-03-07 28 views
5

附上了我的上下文提供的SAMLContextProviderLB豆Spring Security的SAML,重定向的頁面,而不是去到HTTP HTTPS的使用SAMLContextProviderLB設置爲https配置

**<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時,它按預期工作。看到下面的日誌顯示,從DefaultSavedRequest url 返回的值是HTTP,它應該是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;[email protected] ;;

2016-03-07 18:24:11,909 DEBUG org.springframework.security.saml.SAMLProcessingFilter.successfulAuthentication:317 - 認證成功。更新SecurityContextHolder以包含:org.springf[email protected]830e9237:Principal:[email protected];證書:[PROTECTED];已驗證:true;詳細信息:null;未授予任何機關

2016年3月7日18:24:11,910 DEBUG org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler.onAuthenticationSuccess:79 - 重定向到DefaultSavedRequest網址:HTTP:// MYSERVER: 89/FCT /頁

2016年3月7日18:24:11911 DEBUG org.springframework.security.web.DefaultRedirectStrategy.sendRedirect:36 - 重定向到 'http://myserver:89/fct/page'

2016年3月7日18: 24:11,911 DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository.saveCon文本:292 - SecurityContext存儲到HttpSession:'[email protected]0e9237:身份驗證:org.springf[email protected]830e9237:主體:[email protected];證書:[PROTECTED];已驗證:true;詳細信息:null;未授予任何當局

2016年3月7日18:24:11912 DEBUG org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter:97 - SecurityContextHolder中已被清除,已完成

任何想法,請求處理如何在此設置下強制使用HTTPS?提前致謝。

回答

3

這個問題是舊的,但如果我發現它的人可能會這樣我會發表一個答案。

您的負載平衡器或您的反向代理(Apache httpdnginx)必須爲您做一些額外的工作。 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/ 

ProxyPassProxyPassReverse是什麼,你可能已經擁有。但ProxyPreserveHostX-Forwarded-Proto真的很重要。

查看Spring Boot Docs的這一部分。如果X-Forwarded-ForX-Forwarded-Proto設置,你需要添加到您的application.properties文件:

server.use-forward-headers=true 

您還將看到在該文件中,你可以爲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。是的,這是一團糟。但是這讓所有這些荒唐的事情都變得有用了。

相關問題