该加密方法为Cas Server自动将用户输入的密码进行MD5加密后,MD5密文与数据库对应账号的密码对比。
修改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 20 21 22 23 24 <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&characterEncoding=UTF-8&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 ="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 username=?" p:passwordEncoder-ref ="passwordEncoder" />
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 ("admin" ,MD5 ("admin" ));
5、 启动tomcat。输入Cas Server地址:http://127.0.0.1:8080/cas,输入MySQL中的账号admin密码admin,登录成功则说明配置成功。