首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> Java 程式設計 >> Java 綜合教學

CAS SSO 單點登錄:取消 HTTPS 配置全流程(適用測試環境)

     編輯:Java 綜合教學

CAS SSO 單點登錄:取消 HTTPS 配置全流程(適用測試環境)

CAS(Central Authentication Service)默認強制 HTTPS,生產環境必須啟用,但在開發測試階段配置證書繁瑣。本文記錄通過修改三個核心配置文件實現「純 HTTP 模式」運行的完整步驟。

前置條件

  • 已搭建基礎 CAS Server(參考:CAS 搭建隨筆)
  • Tomcat 部署路徑:D:\test\sso\tomcat-cas

三處關鍵修改

1. 修改代理認證處理器 - 允許非安全連接

文件: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 回調驗證票據。

2. 修改 TGC Cookie 生成器 - 關閉 Secure 標志

文件: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 傳輸。

3. 修改警告 Cookie 生成器 - 同步關閉 Secure

文件:webapps\cas\WEB-INF\spring-configuration\warnCookieGenerator.xml

<bean id="warnCookieGenerator" 
      class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator" 
      p:cookieSecure="false" />

驗證效果

  1. 重啟 CAS Server(tomcat-cas)
  2. 瀏覽器訪問 https://localhost:8080/cas/login
  3. 登錄成功後,Cookie 域中 CASTGC 和 warnCookie 的 Secure 標志均為未勾選
  4. 客戶端應用可通過 HTTP 正常完成單點登錄/登出流程

⚠️ 重要提醒

僅限開發/測試環境使用!

  • 生產環境必須啟用 HTTPS,否則憑證傳輸明文極易被劫持
  • 正式部署時請恢復所有 requireSecure="true"、cookieSecure="true"
  • 生產環境建議配置正規 CA 簽發證書或 Let's Encrypt 免費證書

原理補充

  • requireSecure:控制 CAS Server 驗證 Service Ticket 時是否要求 HTTPS 回調
  • cookieSecure:控制 Set-Cookie 標頭是否包含 Secure 屬性,瀏覽器僅在 HTTPS 下發送 Secure Cookie
  • 兩者配合確保「登錄會話建立」與「會話標識傳輸」全鏈路加密

三處配置修改,重啟即可,讓開發調試告別證書煩惱。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved