Cas 添加数据验证并且加密

3 篇文章 0 订阅

修改application.properties 文件 添加如下代码

cas.authn.jdbc.query[0].url=jdbc:mysql://182.61.10.117:3306/shiro?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false        
cas.authn.jdbc.query[0].user=root
cas.authn.jdbc.query[0].password=Xiongliang2012@
cas.authn.jdbc.query[0].sql=select * from users where username=?
cas.authn.jdbc.query[0].fieldPassword=password
cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver

 

 

添加pom 文件 数据库连接jar

<dependency>
    <groupId>org.apereo.cas</groupId>
    <artifactId>cas-server-support-jdbc-drivers</artifactId>
    <version>5.3.10</version>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>org.apereo.cas</groupId>
    <artifactId>cas-server-support-jdbc</artifactId>
    <version>${cas.version}</version>
</dependency>

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>6.0.6</version>
</dependency>
#数据库连接
#cas.authn.jdbc.query[0].url=jdbc:mysql://182.61.10.117:3306/shiro?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
#cas.authn.jdbc.query[0].user=root
#cas.authn.jdbc.query[0].password=Xiongliang2012@
#cas.authn.jdbc.query[0].sql=select * from users where username=?
#cas.authn.jdbc.query[0].fieldPassword=password
#cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver


#采取Md5,SHA 加密
#cas.authn.jdbc.query[0].passwordEncoder.type=DEFAULT
#cas.authn.jdbc.query[0].passwordEncoder.characterEncoding=UTF-8
#MD5加密策略
#cas.authn.jdbc.query[0].passwordEncoder.encodingAlgorithm=MD5


#盐值加密

#加密迭代次数
cas.authn.jdbc.encode[0].numberOfIterations=1024
#该列名的值可替代上面的值,但对密码加密时必须取该值进行处理
cas.authn.jdbc.encode[0].numberOfIterationsFieldName=
#盐值固定列
cas.authn.jdbc.encode[0].saltFieldName=username
#静态盐值
cas.authn.jdbc.encode[0].staticSalt=.
cas.authn.jdbc.encode[0].sql=select * from users where username=?
#对处理盐值后的算法
cas.authn.jdbc.encode[0].algorithmName=MD5
cas.authn.jdbc.encode[0].passwordFieldName=password
cas.authn.jdbc.encode[0].expiredFieldName=expired
cas.authn.jdbc.encode[0].disabledFieldName=disabled
#数据库连接
cas.authn.jdbc.encode[0].url=jdbc:mysql://182.61.10.117:3306/shiro?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
cas.authn.jdbc.encode[0].dialect=org.hibernate.dialect.MySQL5Dialect
cas.authn.jdbc.encode[0].driverClass=com.mysql.jdbc.Driver
cas.authn.jdbc.encode[0].user=root
cas.authn.jdbc.encode[0].password=Xiongliang2012@

2.加密之后的密码

public class Test {

    private static String staticSalt = ".";
    private static  String algorithmName = "MD5";
    private static String encodedPassword = "123456";
    private static String dynaSalt = "zhang";

    public static void main(String[] args) {
        ConfigurableHashService hashService = new DefaultHashService();
        hashService.setPrivateSalt(ByteSource.Util.bytes(staticSalt));
        hashService.setHashAlgorithmName(algorithmName);
        hashService.setHashIterations(1024);
        HashRequest request = new HashRequest.Builder()
                .setSalt(dynaSalt)
                .setSource(encodedPassword)
                .build();
        String res =  hashService.computeHash(request).toHex();
        System.out.println(res);

    }
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值