3.關於CAS SSO單點登入客戶端環境搭建原始碼分析
阿新 • • 發佈:2021-10-08
1.準備兩個個全新的tomcat8,用來作為sso單點登入的客戶端,如下:
2.修改server.xml檔案(因為考慮到埠衝突,所以將裡面的埠全部改掉)
需要原始碼
其中apache-tomcat-client1-8082的埠改成了8082
其中apache-tomcat-client2-8083的埠改成了8083
apache-tomcat-client1-8082新增:
1 2 3 |
<hostname= "sso1.jeesz.cn" appbase= "webapps" unpackwars= "true" autodeploy= "true" >
apache-tomcat-client1- 8083 新增:
<hostname= "sso2.jeesz.cn" appbase= "webapps" unpackwars= "true" autodeploy= "true" ></hostname= "sso2.jeesz.cn" appbase= "webapps" ></hostname= "sso1.jeesz.cn" appbase= "webapps" >
|
3.建立兩個web工程,sso1,sso2,配置web.xml檔案如下(這裡只以sso1為例,sso2的配置可以在專案中檢視):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
<listener>
<listener- class >org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener- class >
</listener>
<filter>
<filter-name>CASSingleSignOutFilter</filter-name>
<filter- class >org.jasig.cas.client.session.SingleSignOutFilter</filter- class >
</filter>
<filter-mapping>
<filter-name>CASSingleSignOutFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>CASFilter</filter-name>
<filter- class >org.jasig.cas.client.authentication.AuthenticationFilter</filter- class >
<init-param>
<param-name>casServerLoginUrl</param-name>
<param-value>https: //jeesz.cn:8443/cas/login</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http: //sso1.jeesz.cn:8082</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CASFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>CASValidationFilter</filter-name>
<filter- class >
org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter- class >
<init-param>
<param-name>casServerUrlPrefix</param-name>
<param-value>https: //jeesz.cn:8443/cas</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http: //sso1.jeesz.cn:8082</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CASValidationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>CASHttpServletRequestWrapperFilter</filter-name>
<filter- class >
org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter- class >
</filter>
<filter-mapping>
<filter-name>CASHttpServletRequestWrapperFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>CASAssertionThreadLocalFilter</filter-name>
<filter- class >org.jasig.cas.client.util.AssertionThreadLocalFilter</filter- class >
</filter>
<filter-mapping>
<filter-name>CASAssertionThreadLocalFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
|
注意標紅色的區域
4.將sso1、sso2兩個專案分別打成war包匯入到兩個tomcat中,分別啟動執行,
此時訪問:http://sso1.jeesz.cn:8082/sso1會出現一個異常,我們截圖用來記錄錯誤
這個錯誤很明顯,我們需要配置當前容器支援http,找到cas專案下的HTTPSandIMAPS-10000001.json檔案,路徑為:\WEB-INF\classes\services,裡面增加http協議支援。
5.重啟sso的服務端,再次訪問http://sso1.jeesz.cn:8082/sso1(成功跳轉)
6.其中sso2的客戶端,訪問http://sso2.jeesz.cn:8083/sso2(成功跳轉)
7.反覆用預設賬號測試登入登出,訪問sso1,sso2應用,可以確認只需要登入一次