体验cas server
前期準(zhǔn)備:
cas-server-3.4.10-release.zip
tomcat6
mysql
?
解壓cas-server-3.4.10-release.zip\cas-server-3.4.10\modules\cas-server-webapp-3.4.10.war并改名為 cas.war,然后放到tomcat webapp目錄下,啟動tomcat
訪問:?https://localhost:8443/cas/login
?
?
用戶名密碼: admin admin
提示單點登錄成功
?
?
上面是最基本的單點登錄,用戶名和密碼是寫死在配置文件中,那么我們?nèi)绾问褂肑DBC呢?
?
打開cas\WEB-INF\deployerConfigContext.xml
其中92行的<bean class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" />就是簡單的用戶名密碼驗證,在實際中是用不到的。刪掉他。
然后添加JDBC的支持:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> ? ?<property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property> ? ?<property name="url"><value>jdbc:mysql://localhost:3306/cas_demo</value></property> ? ?<property name="username"><value>root</value></property> ? ?<property name="password"><value>123456</value></property> </bean> ? ? <bean id="MD5PasswordEncoder" class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder"> ? ? <constructor-arg index="0"> ? ? ? ? <value>MD5</value> ? ? </constructor-arg> </bean> ? <bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"> ? ? <property name="dataSource" ref="dataSource"></property> ? ? <property name="sql" value="select password from user where login_name=?"></property> ? ? <property name="passwordEncoder" ref="MD5PasswordEncoder"></property> </bean> |
有spring基礎(chǔ)的一般都能看懂。?
然后復(fù)制cas-server-3.4.10-release.zip\cas-server-3.4.10\modules下的cas-server-support-jdbc-3.4.10.jar以及mysql數(shù)據(jù)庫的mysql.jar到cas/WEB-INF/lib目錄下
要注意的是,org.jasig.cas.authentication.handler.DefaultPasswordEncoder加密后的字符串是小寫的32位MD5密鑰。
?
?
重新進行l(wèi)ogin與logout發(fā)現(xiàn)又成功了
?
?
?
服務(wù)器是配置成功了,可是你的web項目怎么集成單點登錄功能呢?
?
下載cas-client-3.2.1-release.zip
然后解壓出cas-client-3.2.1-release.zip\cas-client-3.2.1\modules下的cas-client-core-3.2.1.jar,放入你的web項目lib目錄中
?
假設(shè)我有這么一個項目:
現(xiàn)在,我要做的就是修改web.xml
?
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ????xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" ????xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" ????id="WebApp_ID" version="3.0"> ????<display-name>cas_client_demo</display-name> ? ????<!-- 用于單點退出,該過濾器用于實現(xiàn)單點登出功能,可選配置 --> ????<listener> ????????<listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class> ????</listener> ? ????<!-- 該過濾器用于實現(xiàn)單點登出功能,可選配置。 --> ????<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> ? ????<!-- 該過濾器負責(zé)用戶的認證工作,必須啟用它 --> ????<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://localhost:8443/cas/login</param-value> ????????</init-param> ????????<init-param> ????????????<!--這里的server是服務(wù)端的IP --> ????????????<param-name>serverName</param-name> ????????????<param-value>http://localhost:8888/</param-value> ????????</init-param> ????</filter> ????<filter-mapping> ????????<filter-name>CASFilter</filter-name> ????????<url-pattern>/*</url-pattern> ????</filter-mapping> ? ????<!-- 該過濾器負責(zé)對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://localhost:8443/cas</param-value> ????????</init-param> ????????<init-param> ????????????<param-name>serverName</param-name> ????????????<param-value>http://localhost:8888/</param-value> ????????</init-param> ????</filter> ????<filter-mapping> ????????<filter-name>CAS Validation Filter</filter-name> ????????<url-pattern>/*</url-pattern> ????</filter-mapping> ? ????<!-- 該過濾器負責(zé)實現(xiàn)HttpServletRequest請求的包裹, 比如允許開發(fā)者通過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> ? ????<!-- 該過濾器使得開發(fā)者可以通過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> ? ????<!-- ======================== 單點登錄結(jié)束 ======================== --> ? ????<welcome-file-list> ????????<welcome-file>index.html</welcome-file> ????????<welcome-file>index.htm</welcome-file> ????????<welcome-file>index.jsp</welcome-file> ????????<welcome-file>default.html</welcome-file> ????????<welcome-file>default.htm</welcome-file> ????????<welcome-file>default.jsp</welcome-file> ????</welcome-file-list> </web-app> |
?
?
當(dāng)你啟動web程序的時候,就會自動跳轉(zhuǎn)到登錄頁面,登錄成功后跳轉(zhuǎn)到你原先web頁面
?
?
可能遇到的問題:
?
錯誤:
java.security.cert.CertificateException: No name matching localhost found
原因:
keystore里沒有名字為localhost的信息
解決方法:
使用keytool創(chuàng)建public-private keypair時,你的姓名應(yīng)該設(shè)置成localhost
?
?
?
錯誤:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
原因:
jre中沒有導(dǎo)入相關(guān)證書
解決方法:
向tomcat使用的JRE中導(dǎo)入習(xí)慣證書
首先導(dǎo)出證書:
keytool -export -file d:/tomcat6.crt -alias tomcat6 |
其中tomcat6為你自己創(chuàng)建的key name
其次,導(dǎo)入證書
keytool -import -keystore d:\jdk1.6\jre\lib\security\cacerts -file D:/tomcat6.crt -alias tomcat6 |
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/dycg/archive/2013/04/04/2999012.html
總結(jié)
以上是生活随笔為你收集整理的体验cas server的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 勋华压片糖果是什么
- 下一篇: SetForceGroundWindow