CAS(3)数据库验证用户之无密码加密

修改Cas Server下的cas项目的配置文件cas/WEB-INF/deployerConfigContext.xml:

1、

删除以下配置(该配置为Cas Server默认的账号密码):

1
2
3
4
5
6
7
<bean id="primaryAuthenticationHandler" class="org.jasig.cas.authentication.AcceptUsersAuthenticationHandler">
<property name="users">
<map>
<entry key="casuser" value="Mellon"/>
</map>
</property>
</bean>

2、

添加以下配置(分别有MySQL所在服务器ip、MySQL账号、密码,检索Cas用户登录密码的SQL语句):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://192.168.100.6:3336/cas?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull"
p:user="root"
p:password="123456"
p:initialPoolSize="6"
p:minPoolSize="6"
p:maxPoolSize="18"
p:maxIdleTimeExcessConnections="120"
p:checkoutTimeout="10000"
p:acquireIncrement="6"
p:acquireRetryAttempts="5"
p:acquireRetryDelay="2000"
p:idleConnectionTestPeriod="30"
p:preferredTestQuery="select 1" />

<bean id="dbAuthHandler" class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"
p:dataSource-ref="dataSource"
p:sql="select password from user where username=?" />

3、

修改以下配置:

1
2
3
4
5
6
7
8
9
<bean id="authenticationManager" class="org.jasig.cas.authentication.PolicyBasedAuthenticationManager">
<constructor-arg>
<map>
<entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" />
<entry key-ref="dbAuthHandler" value-ref="primaryPrincipalResolver" />
</map>
</constructor-arg>
...
</bean>

4、

向MySQL插入账号密码:

1
insert into cas.user values("root","12345");

5、

启动tomcat。输入Cas Server地址:http://127.0.0.1:8080/cas,输入MySQL数据库中存储的账号root密码root,登录成功则说明配置成功。