<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CAS 教學 &#8211; FoxDevelop</title>
	<atom:link href="https://www.foxdevelop.com/zh-tw/category/c-zh-tw/cas-%e6%95%99%e5%ad%b8/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.foxdevelop.com</link>
	<description>獨立軟體開發工作室</description>
	<lastBuildDate>Thu, 06 Aug 2026 08:06:56 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.2</generator>

<image>
	<url>https://www.foxdevelop.com/wp-content/uploads/2026/05/fox-svgrepo-com-1.png</url>
	<title>CAS 教學 &#8211; FoxDevelop</title>
	<link>https://www.foxdevelop.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>CAS 的實作</title>
		<link>https://www.foxdevelop.com/zh-tw/2026/08/06/cas-%e7%9a%84%e5%af%a6%e4%bd%9c/</link>
					<comments>https://www.foxdevelop.com/zh-tw/2026/08/06/cas-%e7%9a%84%e5%af%a6%e4%bd%9c/#respond</comments>
		
		<dc:creator><![CDATA[jack]]></dc:creator>
		<pubDate>Thu, 06 Aug 2026 08:06:56 +0000</pubDate>
				<category><![CDATA[CAS 教學]]></category>
		<guid isPermaLink="false">https://www.foxdevelop.com/?p=7821</guid>

					<description><![CDATA[舊版 CAS 的實作思路 核心原理（CAS 1.0 協定）  ...]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">舊版 CAS 的實作思路</p>



<h4 class="wp-block-heading">核心原理（CAS 1.0 協定）</h4>



<ol class="wp-block-list">
<li>使用者存取受保護頁面 <code>/admin/admin.aspx</code></li>



<li><code>web.config</code> 權限設定攔截匿名使用者，自動跳轉至登入頁 <code>CasEnter.aspx</code></li>



<li><code>CasEnter.aspx</code> 判斷網址是否帶有 <code>ticket</code> 參數</li>
</ol>



<ul class="wp-block-list">
<li>沒有 ticket：重新導向到 CAS 伺服器登入位址，並傳入目前網站位址做為 <code>service</code></li>



<li>攜帶 ticket：呼叫 <code>serviceValidate</code> 介面向 CAS 伺服器驗證票證</li>
</ul>



<ol class="wp-block-list">
<li>CAS 返回 XML，解析出登入使用者名稱</li>



<li>驗證成功後呼叫 <code>FormsAuthentication.SetAuthCookie()</code> 寫入本機 Forms 登入票證，跳轉至目標頁面</li>



<li>後續存取受保護目錄，由 ASP.NET Forms 辨識登入狀態</li>
</ol>



<h4 class="wp-block-heading">web.config 設定</h4>


<pre class="wp-block-code"><span><code class="hljs language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">system.web</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">authentication</span> <span class="hljs-attr">mode</span>=<span class="hljs-string">"Forms"</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- loginUrl 指向 CasEnter.aspx 做為 CAS 入口轉頁 --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">forms</span> <span class="hljs-attr">loginUrl</span>=<span class="hljs-string">"CasEnter.aspx"</span> 
           <span class="hljs-attr">defaultUrl</span>=<span class="hljs-string">"admin/admin.aspx"</span> 
           <span class="hljs-attr">name</span>=<span class="hljs-string">".LoginFormsTicket"</span> 
           <span class="hljs-attr">path</span>=<span class="hljs-string">"/"</span> 
           <span class="hljs-attr">timeout</span>=<span class="hljs-string">"40"</span> 
           <span class="hljs-attr">protection</span>=<span class="hljs-string">"All"</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">forms</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">authentication</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">authorization</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">allow</span> <span class="hljs-attr">users</span>=<span class="hljs-string">"*"</span>/&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">authorization</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">system.web</span>&gt;</span>

<span class="hljs-comment">&lt;!-- 限制 admin 目錄禁止匿名存取 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">location</span> <span class="hljs-attr">path</span>=<span class="hljs-string">"admin"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">system.web</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">authorization</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">deny</span> <span class="hljs-attr">users</span>=<span class="hljs-string">"?"</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">authorization</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">system.web</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">location</span>&gt;</span></code></span></pre>


<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">新版 CAS 伺服器預設強制使用 HTTPS，<code>casUrl</code> 務必填寫 <code>https://127.0.0.1:8443/cas/</code></p>
</blockquote>


<pre class="wp-block-code"><span><code class="hljs language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">appSettings</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- CAS7 新版位址，結尾必須加上斜線 --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">add</span> <span class="hljs-attr">key</span>=<span class="hljs-string">"casUrl"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"https://127.0.0.1:8443/cas/"</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">appSettings</span>&gt;</span></code></span></pre>


<h4 class="wp-block-heading">CasEnter.aspx 頁面程式碼</h4>



<h5 class="wp-block-heading">1. CasEnter.aspx 前端標籤</h5>


<pre class="wp-block-code"><span><code class="hljs language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">%@</span> <span class="hljs-attr">Page</span> <span class="hljs-attr">Language</span>=<span class="hljs-string">"C#"</span> <span class="hljs-attr">AutoEventWireup</span>=<span class="hljs-string">"true"</span> <span class="hljs-attr">CodeBehind</span>=<span class="hljs-string">"CasEnter.aspx.cs"</span> <span class="hljs-attr">Inherits</span>=<span class="hljs-string">"CasStudy.Web.CasEnter"</span> %&gt;</span>
<span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://www.w3.org/1999/xhtml"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span> <span class="hljs-attr">runat</span>=<span class="hljs-string">"server"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>CAS 轉接登入<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"form1"</span> <span class="hljs-attr">runat</span>=<span class="hljs-string">"server"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">asp:Label</span> <span class="hljs-attr">ID</span>=<span class="hljs-string">"Label1"</span> <span class="hljs-attr">runat</span>=<span class="hljs-string">"server"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">asp:Label</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">asp:HyperLink</span> <span class="hljs-attr">ID</span>=<span class="hljs-string">"HyperLink1"</span> <span class="hljs-attr">runat</span>=<span class="hljs-string">"server"</span>&gt;</span>重新驗證<span class="hljs-tag">&lt;/<span class="hljs-name">asp:HyperLink</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></code></span></pre>


<h5 class="wp-block-heading">2. CasEnter.aspx.cs 後端程式</h5>



<p class="wp-block-paragraph"><br>介面升級為 CAS3.0 <code>p3/serviceValidate</code><br>以 HttpClient 取代已淘汰的 WebClient </p>



<p class="wp-block-paragraph">加入自簽憑證相容性（本機測試新版 CAS 必備）<br>處理 CAS 返回 XML 的命名空間</p>


<pre class="wp-block-code"><span><code class="hljs language-xml">using System;
using System.Configuration;
using System.Net;
using System.Net.Http;
using System.Xml;
using System.Web.Security;

public partial class CasEnter : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string casHost = ConfigurationManager.AppSettings&#91;"casUrl"];
        string ticket = Request.QueryString&#91;"ticket"];
        string service = Request.Url.GetLeftPart(UriPartial.Path);

        // 沒有票證就跳轉 CAS 登入頁
        if (string.IsNullOrEmpty(ticket))
        {
            string redirectUrl = $"{casHost}login?service={Uri.EscapeDataString(service)}";
            Response.Redirect(redirectUrl);
            return;
        }

        // 驗證票證
        string username = ValidateTicket(casHost, ticket, service);
        if (string.IsNullOrEmpty(username))
        {
            Label1.Text = "很抱歉！CAS 驗證失敗，請重新嘗試！";
            HyperLink1.NavigateUrl = Request.Url.AbsolutePath;
        }
        else
        {
            // 寫入 Forms 驗證票證，完成本機登入
            FormsAuthentication.SetAuthCookie(username, false);
            // 跳轉至目標頁面
            Response.Redirect(FormsAuthentication.DefaultUrl);
        }
    }

    /// <span class="hljs-tag">&lt;<span class="hljs-name">summary</span>&gt;</span>
    /// CAS3.0 p3/serviceValidate 票證驗證
    /// <span class="hljs-tag">&lt;/<span class="hljs-name">summary</span>&gt;</span>
    private string ValidateTicket(string casHost, string ticket, string service)
    {
        // 新版 CAS 建議使用 p3/serviceValidate（CAS3.0 協定）
        string validateUrl = $"{casHost}p3/serviceValidate?ticket={Uri.EscapeDataString(ticket)}&amp;service={Uri.EscapeDataString(service)}";

        // 僅本機測試：允許不受信任的SSL憑證（正式環境務必刪除此段！）
        ServicePointManager.ServerCertificateValidationCallback += (s, cert, chain, err) =&gt; true;

        using var httpClient = new HttpClient();
        string xml = httpClient.GetStringAsync(validateUrl).Result;

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xml);
        XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);
        // CAS3 返回 XML 的命名空間
        nsMgr.AddNamespace("cas", "http://www.yale.edu/tp/cas");

        // 尋找使用者節點
        XmlNode userNode = doc.SelectSingleNode("//cas:authenticationSuccess/cas:user", nsMgr);
        return userNode?.InnerText;
    }
}</code></span></pre>


<p class="wp-block-paragraph">CAS 的實作</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.foxdevelop.com/zh-tw/2026/08/06/cas-%e7%9a%84%e5%af%a6%e4%bd%9c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>安裝</title>
		<link>https://www.foxdevelop.com/zh-tw/2026/08/06/%e5%ae%89%e8%a3%9d/</link>
					<comments>https://www.foxdevelop.com/zh-tw/2026/08/06/%e5%ae%89%e8%a3%9d/#respond</comments>
		
		<dc:creator><![CDATA[jack]]></dc:creator>
		<pubDate>Thu, 06 Aug 2026 07:45:53 +0000</pubDate>
				<category><![CDATA[CAS 教學]]></category>
		<guid isPermaLink="false">https://www.foxdevelop.com/?p=7805</guid>

					<description><![CDATA[舊版安裝說明－CAS 5.0以前版本 相依套件 1. JDK ...]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">舊版安裝說明－CAS 5.0以前版本</h3>



<ol class="wp-block-list">
<li>CAS伺服器以Java開發，執行需仰賴兩大核心執行環境：</li>
</ol>



<ul class="wp-block-list">
<li><strong>JDK（Java開發套件）</strong>：內含Java虛擬機(JVM)，負責執行Java程式，是執行的基礎。</li>



<li><strong>Tomcat（Web容器）</strong>：用來部署並執行CAS的war網頁套件。</li>
</ul>



<ol class="wp-block-list">
<li>安裝順序建議：<strong>先安裝JDK → 再安裝Tomcat</strong>（Tomcat安裝時會自動偵測本機的JDK環境）</li>
</ol>



<h4 class="wp-block-heading">相依套件</h4>



<h5 class="wp-block-heading">1. JDK</h5>



<p class="wp-block-paragraph">版本：（JDK）Java 17<br>直接下載連結：<code><a href="https://www.oracle.com/cn/java/technologies/downloads/">Java Downloads | Oracle </a></code></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/26a0.png" alt="⚠" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 注意：JDK7屬舊版，僅能對應舊版CAS；新專案不建議使用。</p>
</blockquote>



<h5 class="wp-block-heading">2. Apache Tomcat</h5>



<p class="wp-block-paragraph">版本：<strong>Tomcat（Windows安裝版）</strong><br><a href="https://tomcat.apache.org/">Apache Tomcat® &#8211; Welcome!</a></p>



<h4 class="wp-block-heading">安裝步驟</h4>



<ol class="wp-block-list">
<li><strong>安裝JDK</strong>
<ul class="wp-block-list">
<li>執行exe安裝檔，可自行設定安裝路徑</li>



<li>【重點】安裝完建議設定環境變數：<code>JAVA_HOME</code>、<code>Path</code>，讓Tomcat可以正確辨識Java環境</li>
</ul>
</li>



<li><strong>安裝Tomcat7</strong>
<ul class="wp-block-list">
<li>執行安裝程式，安裝過程會自動掃描已安裝的JDK</li>



<li>可自訂Tomcat連接埠（預設8080）、設定管理帳號密碼</li>



<li>安裝完成頁面選項：</li>



<li> <code>Run Apache Tomcat</code>：勾選後按下Finish就會自動啟動Tomcat服務</li>



<li><code>Show Readme</code>：可以取消勾選，不需要閱讀說明文件</li>



<li>點擊<code>Finish</code>結束安裝</li>
</ul>
</li>
</ol>



<h4 class="wp-block-heading">Tomcat設定SSL/HTTPS</h4>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">核心前提：<strong>CAS協定強制伺服器必須使用HTTPS</strong>，不允許HTTP，所以一定要幫Tomcat匯入SSL憑證。</p>
</blockquote>



<ol class="wp-block-list">
<li>使用JDK內建工具 <code>keytool</code> 產生 <strong>JKS金鑰儲存庫（自簽憑證）</strong></li>



<li>修改Tomcat的 <code>conf/server.xml</code>，開啟SSL連接器</li>



<li>重新啟動Tomcat，造訪 <code>https://localhost:8443</code> 測試HTTPS是否正常</li>
</ol>



<h4 class="wp-block-heading">產生自簽憑證（JKS）</h4>



<h5 class="wp-block-heading">事前準備</h5>



<ol class="wp-block-list">
<li>建立憑證存放資料夾，範例：<code>C:\Keys</code></li>



<li><strong>以系統管理員身分執行 cmd</strong><br>&gt; Windows7/10/11 如果用一般cmd寫入C碟根目錄，會出現權限不足錯誤。</li>



<li>切換到JDK/JRE的bin目錄</li>
</ol>


<pre class="wp-block-code"><span><code class="hljs language-javascript">cd <span class="hljs-string">"c:\Program Files\Java\jre\bin"</span></code></span></pre>


<p class="wp-block-paragraph">通用命令範本（新版JDK同樣適用）</p>


<pre class="wp-block-code"><span><code class="hljs language-css"><span class="hljs-selector-tag">keytool</span> <span class="hljs-selector-tag">-genkey</span> <span class="hljs-selector-tag">-alias</span> <span class="hljs-selector-tag">tomcat</span> <span class="hljs-selector-tag">-keyalg</span> <span class="hljs-selector-tag">RSA</span> <span class="hljs-selector-tag">-storepass</span> <span class="hljs-selector-tag">changeit</span> <span class="hljs-selector-tag">-keystore</span> <span class="hljs-selector-tag">c</span>:\<span class="hljs-selector-tag">Keys</span>\<span class="hljs-selector-class">.keystore</span> <span class="hljs-selector-tag">-validity</span> 36000</code></span></pre>


<h4 class="wp-block-heading">參數說明</h4>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>參數</th><th>說明</th></tr></thead><tbody><tr><td><code>-genkey</code></td><td>產生金鑰組</td></tr><tr><td><code>-alias tomcat</code></td><td>憑證別名，可自訂</td></tr><tr><td><code>-keyalg RSA</code></td><td>加密演算法，標準RSA</td></tr><tr><td><code>-storepass changeit</code></td><td><strong>金鑰儲存庫密碼</strong>（務必記住，後續設定Tomcat會用到）</td></tr><tr><td><code>-keystore c:\Keys\.keystore</code></td><td>憑證檔案輸出路徑</td></tr><tr><td><code>-validity 36000</code></td><td>憑證有效期限（單位：天）</td></tr></tbody></table></figure>



<h5 class="wp-block-heading">互動輸入資訊</h5>



<p class="wp-block-paragraph">執行指令後依序輸入：</p>



<ol class="wp-block-list">
<li>名字與姓氏：輸入網域名稱（練習環境可隨意填寫）</li>



<li>組織單位、組織名稱、城市、省份、國家代碼（cn）</li>



<li>確認資訊輸入 <code>y</code></li>



<li>金鑰密碼：<strong>直接按Enter，和金鑰庫密碼維持一致</strong></li>
</ol>



<h5 class="wp-block-heading">檢視憑證指令</h5>


<pre class="wp-block-code"><span><code class="hljs language-php">keytool -<span class="hljs-keyword">list</span> -keystore <span class="hljs-string">"C:\Keys\.keystore"</span></code></span></pre>


<p class="wp-block-paragraph">輸入密碼，正常顯示資訊就代表憑證產生成功。</p>



<h4 class="wp-block-heading">Tomcat server.xml 設定SSL連接器</h4>



<ol class="wp-block-list">
<li>打開 <code>Tomcat/conf/server.xml</code></li>



<li>找到被註解的SSL Connector，取消註解，修改憑證路徑與密碼</li>
</ol>


<pre class="wp-block-code"><span><code class="hljs language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Connector</span> <span class="hljs-attr">port</span>=<span class="hljs-string">"8443"</span> <span class="hljs-attr">protocol</span>=<span class="hljs-string">"HTTP/1.1"</span> <span class="hljs-attr">SSLEnabled</span>=<span class="hljs-string">"true"</span>
    <span class="hljs-attr">maxThreads</span>=<span class="hljs-string">"150"</span> <span class="hljs-attr">scheme</span>=<span class="hljs-string">"https"</span> <span class="hljs-attr">secure</span>=<span class="hljs-string">"true"</span>
    <span class="hljs-attr">clientAuth</span>=<span class="hljs-string">"false"</span> <span class="hljs-attr">sslProtocol</span>=<span class="hljs-string">"TLS"</span>
    <span class="hljs-attr">keystoreFile</span>=<span class="hljs-string">"C:\Keys\.keystore"</span>
    <span class="hljs-attr">keystorePass</span>=<span class="hljs-string">"changeit"</span> /&gt;</span></code></span></pre>


<h5 class="wp-block-heading">參數解釋</h5>



<ul class="wp-block-list">
<li><code>port="8443"</code>：Tomcat預設HTTPS連接埠（標準HTTPS是443，若要改用443要注意連接埠佔用與權限）</li>



<li><code>keystoreFile</code>：剛才產生的憑證檔完整絕對路徑</li>



<li><code>keystorePass</code>：前面keytool設定的金鑰庫密碼</li>



<li><code>clientAuth="false"</code>：不需要用戶端憑證（練習環境固定設false）</li>
</ul>



<h4 class="wp-block-heading">驗證方式</h4>



<p class="wp-block-paragraph">啟動Tomcat，瀏覽器開啟網址：<br><code>https://127.0.0.1:8443</code></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">自簽憑證在瀏覽器會顯示「不安全」屬正常現象；正式上線環境必須購買合法CA憑證。</p>
</blockquote>



<h3 class="wp-block-heading">CAS 5.0+ 安裝</h3>



<h5 class="wp-block-heading">1、取得安裝套件</h5>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">CAS 5.0+ 捨棄傳統 <code>war + Tomcat</code> 的部署模式，改以SpringBoot為基礎，<strong>提供獨立可執行Jar，不需要額外安裝Tomcat</strong></p>
</blockquote>



<ol class="wp-block-list">
<li>CAS伺服器（Server）</li>
</ol>



<p class="wp-block-paragraph"><strong>透過CAS Initializr線上產生部署套件</strong><br>https://casinitializr.apereo.org</p>



<h5 class="wp-block-heading">2、CAS伺服器部署流程</h5>



<ol class="wp-block-list">
<li>開啟 CAS Initializr</li>
</ol>



<ul class="wp-block-list">
<li>選擇 CAS Version：<code>7.0.x</code>（最新穩定版）</li>



<li>勾選基礎模組：<code>Core / Web / SSL</code></li>



<li>產生並下載 <code>cas.war</code>（或是直接取得獨立執行檔 <code>cas.jar</code>）</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">兩種封裝模式擇一使用：</p>



<ul class="wp-block-list">
<li>模式A（建議）：<strong>Standalone（獨立Jar）</strong>，內建Tomcat，下載即可執行</li>



<li>模式B：傳統War套件，可部署在外掛Tomcat（不建議）</li>
</ul>
</blockquote>



<ol start="2" class="wp-block-list">
<li>使用【獨立Jar模式】部署（主流方案）<br>1）下載取得 <code>cas.jar</code><br>2）建立設定目錄 <code>./etc/cas/config</code>，新增設定檔 <code>cas.properties</code><br>3）啟動指令（必須Java17以上環境）</li>
</ol>


<pre class="wp-block-code"><span><code class="hljs language-css"><span class="hljs-selector-tag">java</span> <span class="hljs-selector-tag">-jar</span> <span class="hljs-selector-tag">cas</span><span class="hljs-selector-class">.jar</span></code></span></pre>


<ol start="3" class="wp-block-list">
<li>連接埠與HTTPS說明<br>內建Tomcat預設連接埠：<strong>8443（HTTPS）</strong><br>新版本預設強制開啟HTTPS，規則與舊版保持一致。</li>
</ol>



<h5 class="wp-block-heading">3、存取位址</h5>


<pre class="wp-block-code"><span><code class="hljs language-javascript">https:<span class="hljs-comment">//127.0.0.1:8443/cas</span></code></span></pre>


<p class="wp-block-paragraph">安裝</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.foxdevelop.com/zh-tw/2026/08/06/%e5%ae%89%e8%a3%9d/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>介紹</title>
		<link>https://www.foxdevelop.com/zh-tw/2026/08/06/%e4%bb%8b%e7%b4%b9/</link>
					<comments>https://www.foxdevelop.com/zh-tw/2026/08/06/%e4%bb%8b%e7%b4%b9/#respond</comments>
		
		<dc:creator><![CDATA[jack]]></dc:creator>
		<pubDate>Thu, 06 Aug 2026 07:35:39 +0000</pubDate>
				<category><![CDATA[CAS 教學]]></category>
		<guid isPermaLink="false">https://www.foxdevelop.com/?p=7787</guid>

					<description><![CDATA[觀念 1. CAS CAS（Central Authenti ...]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">觀念</h3>



<h4 class="wp-block-heading">1. CAS</h4>



<p class="wp-block-paragraph"><strong>CAS（Central Authentication Service，中央認證服務）</strong><br>由耶魯大學發起的開源 <strong>Web SSO（單一簽入）</strong> 實作框架。</p>



<h4 class="wp-block-heading">2. SSO（單一簽入）</h4>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">將多個網站應用的身分登入驗證統一至單一入口完成。</p>



<ul class="wp-block-list">
<li>特性：各應用透過 Web 通訊協定（HTTPS）互相溝通，具備<strong>全域唯一登入入口</strong></li>



<li>淺白解釋：同一個瀏覽器只要在認證中心登入一次，存取所有信任的網站就不用重複登入</li>
</ul>
</blockquote>



<h4 class="wp-block-heading">3. SSO 體系的三大角色</h4>



<ol class="wp-block-list">
<li>User：終端使用者（瀏覽器）</li>



<li>Web 應用程式（多個業務系統）</li>



<li>SSO 認證中心（唯一）</li>
</ol>



<h4 class="wp-block-heading">4. SSO 三大核心原則</h4>



<ol class="wp-block-list">
<li>所有帳號登入動作<strong>統一在 SSO 認證中心執行</strong>；</li>



<li>認證中心提供機制，通知各個 Web 應用程式目前使用者是否已經完成認證；</li>



<li>認證中心必須和所有業務 Web 應用程式預先建立信任關係。</li>
</ol>



<h5 class="wp-block-heading">兩大核心元件</h5>



<h4 class="wp-block-heading">CAS Server（認證伺服器端）</h4>



<ul class="wp-block-list">
<li>獨立部署的 Web 程式，也就是<strong>唯一的認證中心</strong></li>



<li>職責：接收帳號密碼、驗證使用者身分；簽發票據（Ticket）、管理全域會議 Cookie(TGC)</li>
</ul>



<h4 class="wp-block-heading">CAS Client（用戶端，內嵌於各業務系統）</h4>



<ul class="wp-block-list">
<li>部署在各個業務 Web 應用程式內，一般以過濾器 Filter 的形式實作</li>



<li>職責：攔截受保護資源的請求；使用者尚未登入時，自動將瀏覽器重新導向至 CAS Server 登入頁面</li>
</ul>



<h4 class="wp-block-heading">運作流程</h4>



<ol class="wp-block-list">
<li><strong>使用者存取業務系統資源</strong> → CAS Client 攔截請求，發現請求中沒有 <code>Service Ticket</code></li>



<li>Client 將瀏覽器<strong>重新導向</strong>到 CAS Server 登入位址，並攜帶當前業務系統位址（Service）</li>



<li>使用者在 CAS 伺服器端輸入帳號密碼完成登入認證
<ul class="wp-block-list">
<li>登入成功：CAS Server 在瀏覽器寫入 <strong>TGC（Ticket Granting Cookie）全域會議 Cookie</strong></li>



<li>產生一次性票據：<strong>Service Ticket（ST）</strong></li>
</ul>
</li>



<li>CAS Server 再次重新導向瀏覽器，回到業務系統位址，URL 參數帶上 <code>Ticket=xxx</code></li>



<li><strong>業務系統的 CAS Client 在後端發起伺服器請求</strong>，帶上 Service 位址與 Ticket，向 CAS Server 驗證票據是否合法</li>



<li>CAS Server 確認票據有效，回傳使用者身分資訊（使用者名稱等）</li>



<li>驗證通過，業務系統建立本機會議，使用者就可以正常瀏覽頁面</li>
</ol>



<p class="wp-block-paragraph"> <strong>TGC 的作用</strong>：只要瀏覽器保留 TGC Cookie，之後存取其他接入 CAS 的系統時，就不會彈出登入頁，自動完成單一簽入。</p>



<p class="wp-block-paragraph">介紹</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.foxdevelop.com/zh-tw/2026/08/06/%e4%bb%8b%e7%b4%b9/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
