Cas 添加数据验证并且加密

修改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);

    }
}

猜你喜欢

转载自blog.csdn.net/qq_38233650/article/details/89491272
Cas