时间:2021-07-01 10:21:17 帮助过:2人阅读
下面提供加密类 com.cux.cas.CuxPasswordEncoder 源码
加密类需实现Cas认证的加密接口
依赖jar包为:cas-server-core-3.4.8.jar 、spring-security-core-3.0.5.RELEASE.jar, 这两个jar包在 /cas/WEB-INF/lib下都有
package com.cux.cas; import org.jasig.cas.authentication.handler.PasswordEncoder; import org.springframework.security.authentication.encoding.ShaPasswordEncoder; public class CuxPasswordEncoder implements PasswordEncoder { @Override public String encode(String args) { ShaPasswordEncoder encoder = new ShaPasswordEncoder(); encoder.setEncodeHashAsBase64(true); return encoder.encodePassword(args, null); } }
将上面的java类编译并打成jar包放到 /cas/WEB-INF/lib,再重启tomcat即完成整个配置过程,用户可以使用用户名、邮箱、手机三种方式登录。
附:Cas自带MD5密码加密类,位于 /cas/WEB-INF/lib/cas-server-core-3.5.2.jar
<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.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" /> --> <bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"> <property name="dataSource" ref="dataSource" /> <property name="sql" value="select encrpted_pwd from cas_user_credential where enable_flag = ‘Y‘ and lower(user_name) = lower(?)" /> <property name="passwordEncoder" ref="Md5PasswordEncoder"/> </bean>
Cas 数据源之Mysql
标签: