CAS6.1 配置连接数据库,以及修改自定义的密码验证(SpringSecurity)
一、cas 配置数据库1、在build.gradle中引入jardependencies {// Other CAS dependencies/modules may be listed here...// compile "org.apereo.cas:cas-server-support-json-service-registry:${casServerVersion}"compile "or
·
一、cas 配置数据库
1、在build.gradle中引入jar
dependencies {
// Other CAS dependencies/modules may be listed here...
// compile "org.apereo.cas:cas-server-support-json-service-registry:${casServerVersion}"
compile "org.apereo.cas:cas-server-webapp-init:${casServerVersion}"
compile "org.apereo.cas:cas-server-support-json-service-registry:${casServerVersion}"
compile "org.apereo.cas:cas-server-support-jdbc:${casServerVersion}"
compile "org.apereo.cas:cas-server-support-jdbc-drivers:${casServerVersion}"
compile "mysql:mysql-connector-java:8.0.22"
}
2、修改application.properties
在里面写如下内容
将cas.authn.accept.users、cas.authn.accept.name注释掉
# cas.authn.accept.users=casuser::Mellon
# cas.authn.accept.name=Static Credentials
cas.authn.jdbc.query[0].url=jdbc:mysql://127.0.0.1:3306/oppo_vivo_timmer?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
cas.authn.jdbc.query[0].user=root
cas.authn.jdbc.query[0].password=
cas.authn.jdbc.query[0].sql=select password from sys_user where user_name= ?
cas.authn.jdbc.query[0].fieldPassword=password
cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver
cas.authn.jdbc.query[0].passwordEncoder.type=DEFAULT
cas.authn.jdbc.query[0].passwordEncoder.characterEncoding=UTF-8
cas.authn.jdbc.query[0].passwordEncoder.encodingAlgorithm=MD5
此时这种情况,如果你的数据库密码是使用的MD5加密的(没有加盐),此时你就可以访问了。
二、修改PasswordEncoder
但是由于我的系统使用的SpringSecurity,密码加密的方式为SHA-256 +随机盐+密钥对密码进行加密,因此我需要修改cas源码
我数据库密码的形式
1、在src下创建文件夹、包、class
class内容
package com.adconcepts;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
/**
* @Auther: xuchangcheng
* @Date: 2021/8/20 10:06
* @Description:
*/
public class MyPasswordEncode implements PasswordEncoder {
/**
* 生成BCryptPasswordEncoder密码
* @param rawPassword
* @return
*/
@Override
public String encode(CharSequence rawPassword) {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
return passwordEncoder.encode(rawPassword);
}
/**
* 判断密码是否相同
* @param rawPassword
* @param encodedPassword
* @return
*/
@Override
public boolean matches(CharSequence rawPassword, String encodedPassword) {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
return passwordEncoder.matches(rawPassword, encodedPassword);
}
}
2、修改application.properties
将type指定为我重写的class
cas.authn.jdbc.query[0].url=jdbc:mysql://127.0.0.1:3306/oppo_vivo_timmer?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
cas.authn.jdbc.query[0].user=root
cas.authn.jdbc.query[0].password=
cas.authn.jdbc.query[0].sql=select password from sys_user where user_name= ?
cas.authn.jdbc.query[0].fieldPassword=password
cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver
cas.authn.jdbc.query[0].passwordEncoder.type=com.adconcepts.MyPasswordEncode
cas.authn.jdbc.query[0].passwordEncoder.characterEncoding=UTF-8
# cas.authn.jdbc.query[0].passwordEncoder.encodingAlgorithm=MD5
更多推荐
已为社区贡献3条内容
所有评论(0)