CAS (1) —— Mac下配置CAS到Tomcat(服务端)(转)
tomcat版本: tomcat-8.0.29
jdk版本: jdk1.8.0_65
cas版本: cas4.1.2
cas-client-3.4.1
參考來源:
CAS實現單點登錄(SSO)經典完整教程
CAS 4.0 配置開發手冊
cas客戶端應用實現
使用 CAS 在 Tomcat 中實現單點登錄
Tomcat (1) —— Mac下配置Tomcat Https/SSL
【高可用HA】Apache (2) —— Mac下安裝多個Apache Tomcat實例
目標架構
下載
首先登陸jasig網站http://downloads.jasig.org/,下載相應的cas版本。
由于網站只提供源碼包而不提供發布包,所以需要自己下載來編譯。
cas會為不同的客戶端消費者提供client包,這里我們選擇java-client作為演示。
先編譯服務端
cas-server-webapp Richard$ mvn clean install -Dmaven.test.skip然后在target下找到相應的war包"cas-server-webapp-4.1.2.war"
配置
服務端
-
簡單設置
參照以下文章為Tomcat配置好Https
Tomcat (1) —— Mac下配置Tomcat Https/SSL
【高可用HA】Apache (2) —— Mac下安裝多個Apache Tomcat實例
然后我們將打好的war包部署再Tomcat上
修改登陸的提示文字"./servers/cluster/tomcat/node-c/webapps/cas/WEB-INF/view/jsp/default/ui/casLoginView.jsp"(為以后的集群環境測試做準備)
然后通過https訪問node-c
https://sso.hoau.com:8433/cas/login打開文件"deployerConfigContext.xml"查看CAS相關的配置:
* 初始默認狀態下,CAS 通過配置的文件里的用戶名密碼登陸 casuser/Mellon
嘗試登陸
-
利用數據庫來驗證
需要的依賴:
cas-server-support-jdbc-4.1.2.jar mysql-connector-java-5.1.37.jarMySQL:
在本地的MySQL中創建新的數據庫并新建表app_user作為驗證用戶的目標數據庫
修改 deployerConfigContext.xml:
將bean "primaryAuthenticationHandler"注釋掉
<!-- by Richard <bean id="primaryAuthenticationHandler"class="org.jasig.cas.authentication.AcceptUsersAuthenticationHandler"><property name="users"><map><entry key="casuser" value="Mellon"/></map></property> </bean> -->增加數據庫dataSource
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/hoau-dev"></property> <property name="username" value="root"></property> <property name="password" value="Root123"></property> </bean>增加PasswordEncoder
<bean id="myPasswordEncoder"class="org.jasig.cas.authentication.handler.PlainTextPasswordEncoder"/>*注意 此處的Encoder必須,有的論壇文章可能會使用"DefaultPasswordEncoder",因為我們示例中的密碼數據并沒有使用加密,所以我們這里用"PlainTextPasswordEncoder"
<bean id="myPasswordEncoder" class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder"> <constructor-arg index="0"> <value>MD5</value> </constructor-arg> </bean>增加DB的""
<bean id="dbAuthHandler" class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"><property name="sql" value="select password from app_user where username=?" /> <property name="dataSource" ref="dataSource" /> <property name="passwordEncoder" ref="myPasswordEncoder"/> </bean>最后回頭查看"authenticationManager"的參數
由于我們已經將配置文件的用戶驗證方式"primaryAuthenticationHandler"修改成了DB的驗證方式"dbAuthHandler",所以我們需要修改"primaryPrincipalResolver"的參數
<bean id="authenticationManager" class="org.jasig.cas.authentication.PolicyBasedAuthenticationManager"> <constructor-arg> <map> <!-- | IMPORTANT | Every handler requires a unique name. | If more than one instance of the same handler class is configured, you must explicitly | set its name to something other than its default name (typically the simple class name). --> <entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" /> <!-- Richard change primaryPrincipalResolver <entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" /> --> <entry key-ref="dbAuthHandler" value-ref="primaryPrincipalResolver" /> </map> </constructor-arg>測試
嘗試訪問
https://sso.hoau.com:8433/cas并使用我們在數據庫里面預埋的數據"test01/psw01"登陸
結束
http://www.cnblogs.com/richaaaard/p/5045276.html
?
總結
以上是生活随笔為你收集整理的CAS (1) —— Mac下配置CAS到Tomcat(服务端)(转)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: redis之(十一)redis实现缓存的
- 下一篇: HashSet,TreeSet和Link