CAS-SERVER的默認驗證規則:只要用戶名和密碼相同就認證經過(僅僅用於測試,生成環境須要根據實際狀況修改),輸入admin/admin 點擊登陸,就能夠看到登陸成功的頁面 java
這裏使用JDK生成的證書,正式環境需購買專業提供商的證書
web
用JDK自帶的keytool工具生成證書: 瀏覽器
keytool -genkey -alias xiaokaceng -keyalg RSA -keystore d :/cas/xiaokaceng
注意:127.0.0.1==sso.xiaokaceng.com 在C:\Windows\System32\drivers\etc\hosts配置,只能輸入域名不能輸入IP tomcat
keytool -export -file d:/cas/xiaokaceng.crt -alias xiaoka ceng -keystore d:/cas/xiaokaceng
證書導出完成,可提供JDK使用 session
keytool -import -keystore D:\JavaDev\jdk1.7\jre\lib\secur ity\cacerts -file d:\cas\xiaokaceng.crt -alias xiaokaceng
特別提示: app
keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect
那麼請輸入密碼:changeit webapp
啓用Tomcat的SSL,開啓83和87的註釋,配置keystoreFile和keystorePass jsp
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="D:/cas/xiaokaceng" keystorePass="123456"/>
注意:keystoreFile和keystorePass有大小寫之分 工具
CAS-Client 下載地址:http://downloads.jasig.org/cas-clients/,解壓並拷貝相應jar 測試
修改web.xml
<!-- ======================== 單點登陸開始 ======================== --> <!-- 用於單點退出,該過濾器用於實現單點登出功能,可選配置--> <listener> <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class> </listener> <!-- 該過濾器用於實現單點登出功能,可選配置。 --> <filter> <filter-name>CAS Single Sign Out Filter</filter-name> <filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class> </filter> <filter-mapping> <filter-name>CAS Single Sign Out Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>CAS Filter</filter-name> <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class> <init-param> <param-name>casServerLoginUrl</param-name> <param-value>https://sso.xiaokaceng.com:8443/cas/login</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://localhost:18080</param-value> </init-param> </filter> <filter-mapping> <filter-name>CAS Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 該過濾器負責對Ticket的校驗工做,必須啓用它 --> <filter> <filter-name>CAS Validation Filter</filter-name> <filter-class> org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class> <init-param> <param-name>casServerUrlPrefix</param-name> <param-value>https://sso.xiaokaceng.com:8443/cas</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://localhost:18080</param-value> </init-param> </filter> <filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 該過濾器負責實現HttpServletRequest請求的包裹, 好比容許開發者經過HttpServletRequest的getRemoteUser()方法得到SSO登陸用戶的登陸名,可選配置。 --> <filter> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <filter-class> org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class> </filter> <filter-mapping> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 該過濾器使得開發者能夠經過org.jasig.cas.client.util.AssertionHolder來獲取用戶的登陸名。 好比AssertionHolder.getAssertion().getPrincipal().getName()。 --> <filter> <filter-name>CAS Assertion Thread Local Filter</filter-name> <filter-class>org.jasig.cas.client.util.AssertionThreadLocalFilter</filter-class> </filter> <filter-mapping> <filter-name>CAS Assertion Thread Local Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- ======================== 單點登陸結束 ======================== -->
測試驗證,訪問http://localhost:18080/examples/servlets/servlet/HelloWorldExample
退出連接爲:https://sso.xiaokaceng.com:8443/cas/logout