部署环境:Windows10+JDK11+Tomcat9+MySql8(8.1.15)
1、下载Server端:https://github.com/apereo/cas-overlay-template/tree/6.1
2、解压 cas-overlay-template-6.1.zip
3、用 IntelliJ IDEA 打开 解压后的项目
4、修改 build.gradle 文件,添加 阿里云的maven仓库和数据库认证相关包
//在 repositories 节点下
maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
//在 dependencies 节点下
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.15" //注意自己的mysql版本
5、修改配置文件,以满足本地的环境。
(1)获取 resource 目录,执行 gradlew.bat explodeWar 命令,在 build 目录下会生成一个 cas-resources 目录,然后将其中的文件复制到 src/main/resources 目录中(没有则手动创建目录)。
(2)修改 resource 目录中的 application.properties 文件,添加及修改以下配置信息
#取消静态配置
#cas.authn.accept.users=casuser::Mellon
#cas.authn.accept.name=Static Credentials
#以下为本地的数据库配置信息
cas.authn.jdbc.query[0].url=jdbc:mysql://localhost:3306/db01?serverTimezone=UTC&allowMultiQueries=true
cas.authn.jdbc.query[0].user=root
cas.authn.jdbc.query[0].password=xxxxxx
cas.authn.jdbc.query[0].sql=select password from users where username= ?
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
#设置安全为false
cas.tgc.secure=false
#开启识别json文件,默认false
cas.serviceRegistry.initFromJson=true
(3)修改 resources/services 目录下的 HTTPSandIMAPS-10000001.json 文件,在 serviceId 节点中添加一个 http
{
"@class": "org.apereo.cas.services.RegexRegisteredService",
"serviceId": "^(https|http|imaps)://.*",
"name": "HTTPS and IMAPS",
"id": 10000001,
"description": "This service definition authorizes all application urls that support HTTPS and IMAPS protocols.",
"evaluationOrder": 10000
}
6、执行 gradlew.bat build 命令后,在 build/libs 目录会生成一个 cas.war 包。
7、最后将就生成的 cas.war 包放到 tomcat 的 webapp 中,启动运行并测试。
最后祝成功!