CentOS安装CAS 5.3.4服务端

1、安装jdk1.8

https://www.cnblogs.com/kgdxpr/p/6824093.html

2、安装tomcat8

3、安装maven

https://www.cnblogs.com/kgdxpr/p/9849856.html

4、下载cas-overlay

https://github.com/apereo/cas-overlay-template/tree/5.3

百度地址:https://pan.baidu.com/s/11xHLsGiUplmARRdI4PRtCA

解压cas-overlay-template-5.3.zip

进入cas-overlay-template-5.3目录

执行:mvn clean package

将生成的cas目录复制到tomcat下

5、利用maven为cas下载连接数据库的依赖包

pom.xml内容如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>fxma</groupId>
    <artifactId>Word2Html</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Word2Html</name>
    <url>http://maven.apache.org</url>

<dependencies>
        <dependency>
            <groupId>org.apereo.cas</groupId>
            <artifactId>cas-server-support-jdbc-drivers</artifactId>
            <version>${cas.version}</version>
        </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>8.0.12</version>
        </dependency>

    </dependencies>

    <properties>
        <cas.version>5.3.4</cas.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <mysql.driver.version>8.0.12</mysql.driver.version>
    </properties>
</project>

mvn -f pom.xml dependency:copy-dependencies

将下载的jar包复制到cas的lib目录下

设置cas的配置文件application.properties

将默认的静态用户名和密码配置注释掉

#cas.authn.accept.users=casuser::Mellon

增加如下内容:

#配置数据库连接
cas.authn.jdbc.query[0].url=jdbc:mysql://127.0.0.1:3306/dsideal_db?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
#数据库用户名
cas.authn.jdbc.query[0].user=root
#数据库密码
cas.authn.jdbc.query[0].password=123456
#mysql驱动
cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver

#添加jdbc认证
cas.authn.jdbc.query[0].sql=SELECT * FROM login WHERE login_name =?
#哪个字段作为密码字段
cas.authn.jdbc.query[0].fieldPassword=login_password
#哪个字段作为过期字段 0:未过期  1:已过期
cas.authn.jdbc.query[0].fieldExpired=expired
#哪个字段作为是否可用字段 0:未禁用  1:已禁用
cas.authn.jdbc.query[0].fieldDisabled=disabled

注:如上配置为明文密码

增加密码MD5加密配置

修改配置文件application.properties增加如下内容:

#配置加密策略
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加密为32位小写

增加对密码加盐处理

在上面的配置的基础上,增加如下代码,可以共存:

#数据库连接
cas.authn.jdbc.encode[0].driverClass=com.mysql.cj.jdbc.Driver
cas.authn.jdbc.encode[0].url=jdbc:mysql://127.0.0.1:3306/dsideal_db?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
cas.authn.jdbc.encode[0].user=root
cas.authn.jdbc.encode[0].password=123456
#加密迭代次数
cas.authn.jdbc.encode[0].numberOfIterations=2
#该列名的值可替代上面的值,但对密码加密时必须取该值进行处理
cas.authn.jdbc.encode[0].numberOfIterationsFieldName=
#动态盐值用的字段
cas.authn.jdbc.encode[0].saltFieldName=login_name
#静态盐值
cas.authn.jdbc.encode[0].staticSalt=654321
cas.authn.jdbc.encode[0].sql=SELECT * FROM t_sys_loginperson WHERE login_name =?
#对处理盐值后的算法
cas.authn.jdbc.encode[0].algorithmName=MD5
#哪个字段作为密码字段
cas.authn.jdbc.encode[0].passwordFieldName=login_password
#哪个字段作为过期字段 0:未过期  1:已过期
cas.authn.jdbc.encode[0].expiredFieldName=expired
#哪个字段作为是否可用字段 0:未禁用  1:已禁用
cas.authn.jdbc.encode[0].disabledFieldName=disabled

java密码加盐代码:

public static void main(String[] args) {
        //静态盐值
        String staticSalt = "654321";
        //加密算法
        String algorithmName = "MD5";
        //密码明文
        String encodedPassword = "123";
        //动态盐值,就是登录名
        String dynaSalt = "admin_en"; 
        
        ConfigurableHashService hashService = new DefaultHashService();
        hashService.setPrivateSalt(ByteSource.Util.bytes(staticSalt));
        hashService.setHashAlgorithmName(algorithmName);
        hashService.setHashIterations(2);
        HashRequest request = new HashRequest.Builder()
                .setSalt(dynaSalt)
                .setSource(encodedPassword)
                .build();
        String res =  hashService.computeHash(request).toHex();
        System.out.println(res);
    }

 所需的jar包的pom.xml

<dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-core</artifactId>
    <version>1.3.2</version>
</dependency>

 jar包百度地址:https://pan.baidu.com/s/1oqrOOm6p1ti-EHLrkeRDsQ

项目下载:https://pan.baidu.com/s/1-DujChC3BjhtDaUq0xw6WA

原文地址:https://www.cnblogs.com/kgdxpr/p/9854657.html