一、CAS服務端搭建
1、下載下傳:https://github.com/apereo/cas/releases/tag/v4.0.0

2、下載下傳完後解壓cas-server-4.0.0-release.zip。在cas-server-4.0.0-release\cas-server-4.0.0\modules目錄下找到
cas-server-webapp-4.0.0.war。為友善通路,重命名為cas.war,放到tomcat的webapps下,啟動tomcat。
3、通路:http://localhost:8080/cas/login
4、輸入預設的使用者名:casuser 和密碼:Mellon。登入成功後會跳到登入成功的提示頁面
二、CAS服務端配置
1、修改端口。如果我們不希望用8080端口通路CAS, 可以修改端口。
(1)、修改tomcat的端口。打開tomcat 目錄 conf\server.xml 找到下面的配置
(2)、修改CAS配置檔案。修改cas的WEB-INF/cas.properties
server.name=http://localhost:8081
2、去除https認證
CAS預設使用的是https協定,如果使用https協定需要SSL安全證書(需向特定的機構申請和購買) 。修改配置,讓CAS使用http協定。
(1)、修改cas的WEB-INF/deployerConfigContext.xml
<bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"
p:httpClient-ref="httpClient"/>
這裡需要增加參數
p:requireSecure="false"
,requireSecure屬性意思為是否需要安全驗證,即https,false為不采用。
(2)、修改cas的/WEB-INF/spring-configuration/ticketGrantingTicketCookieGenerator.xml
<bean id="ticketGrantingTicketCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
p:cookieSecure="true"
p:cookieMaxAge="-1"
p:cookieName="CASTGC"
p:cookiePath="/cas" />
參數
p:cookieSecure="true"
,同理為https驗證相關,true為采用https驗證,false為不采用https驗證。
參數
p:cookieMaxAge="-1"
,是cookie的最大生命周期,-1為無生命周期,即隻在目前打開的視窗有效,關閉或重新打開其它視窗,仍會要求驗證。可以根據需要修改為大于0的數字,比如3600等,意思是在3600秒内,打開任意視窗,都不需要驗證。
(3)、修改cas的WEB-INF/spring-configuration/warnCookieGenerator.xml
<bean id="warnCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
p:cookieSecure="true"
p:cookieMaxAge="-1"
p:cookieName="CASPRIVACY"
p:cookiePath="/cas" />
和第(2)步一樣,修改cookieSecure改為false , cookieMaxAge改為3600
三、CAS用戶端搭建
1、用戶端工程1搭建