sso demo mysql ( cas )
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sso demo mysql ( cas )相关的知识,希望对你有一定的参考价值。
基本配置 参考之前得随笔 http://www.cnblogs.com/rocky-fang/p/5354947.html
1. tomcat-cas 修改配置
1.1 在D:\test\sso\tomcat-cas\webapps\cas\WEB-INF下 找到deployerConfigContext.xml ,修改如下:
注释掉
<!-- <bean id="primaryAuthenticationHandler" class="org.jasig.cas.authentication.AcceptUsersAuthenticationHandler"> <property name="users"> <map> <entry key="casuser" value="Mellon"/> </map> </property> </bean> -->
增加
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" p:driverClass="com.mysql.jdbc.Driver" p:jdbcUrl="jdbc:mysql://127.0.0.1:3306/cas?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull" p:user="root" p:password="root" /> <!-- Define the encode method--> <!--<bean id="passwordEncoder" class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder" autowire="byName"> <constructor-arg value="MD5"/> </bean> --> <bean id="passwordEncoder" class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder" c:encodingAlgorithm="MD5" p:characterEncoding="UTF-8" /> <bean id="dbAuthHandler" class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler" p:dataSource-ref="dataSource" p:sql="select password from user where name=? and used=1" p:passwordEncoder-ref="passwordEncoder"/>
修改
<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" /> <!--改为--><entry key-ref="dbAuthHandler" value-ref="primaryPrincipalResolver" /> <!--注释掉<entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />--> </map> </constructor-arg>
1.2 创建数据库 建表 插入数据
CREATE DATABASE /*!32312 IF NOT EXISTS*/`cas` /*!40100 DEFAULT CHARACTER SET gbk */;
USE `cas`;
/*Table structure for table `user` */
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`used` tinyint(2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=gbk;
/*Data for the table `user` */
insert into `user`(`id`,`name`,`password`,`used`) values (1,‘casuser‘,‘9414f9301cdb492b4dcd83f8c711d8bb‘,1);
1.3 加入jar包
2. 测试
访问 https://demo.cdv.com:8443/cas/login
使用 casuser + Mellon 登录
成功, 此时验证是从数据库查询的密码比较而来。
以上是关于sso demo mysql ( cas )的主要内容,如果未能解决你的问题,请参考以下文章
SSO单点系列:CAS4.0 CAS整合SpringMVC+MyBatis实现数据库校验(04)
SSO之CAS框架扩展 改动CAS源代码实现与ESS动态password验证对接
CAS SSO研究二:cas_server通过查询数据库验证用户名密码正确性