CAS(Central Authentication Service)默認強制 HTTPS,生產環境必須啟用,但在開發測試階段配置證書繁瑣。本文記錄通過修改三個核心配置文件實現「純 HTTP 模式」運行的完整步驟。
D:\test\sso\tomcat-cas文件:webapps\cas\WEB-INF\deployerConfigContext.xml
<bean id="proxyAuthenticationHandler"
class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"
p:httpClient-ref="httpClient"
p:requireSecure="false" />
關鍵點:新增 p:requireSecure="false",允許 HTTP 回調驗證票據。
文件:webapps\cas\WEB-INF\spring-configuration\ticketGrantingTicketCookieGenerator.xml
<bean id="ticketGrantingTicketCookieGenerator"
class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
p:cookieSecure="false"
p:cookieMaxAge="-1"
p:cookieName="CASTGC"
p:cookiePath="/cas" />
關鍵點:將 p:cookieSecure="true" 改為 false,Cookie 不再要求 HTTPS 傳輸。
文件:webapps\cas\WEB-INF\spring-configuration\warnCookieGenerator.xml
<bean id="warnCookieGenerator"
class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
p:cookieSecure="false" />
https://localhost:8080/cas/loginCASTGC 和 warnCookie 的 Secure 標志均為未勾選僅限開發/測試環境使用!
requireSecure="true"、cookieSecure="true"requireSecure:控制 CAS Server 驗證 Service Ticket 時是否要求 HTTPS 回調cookieSecure:控制 Set-Cookie 標頭是否包含 Secure 屬性,瀏覽器僅在 HTTPS 下發送 Secure Cookie三處配置修改,重啟即可,讓開發調試告別證書煩惱。