简单测试用的CAS Server搭建

开发一个接入cas的网站时,需要本地开启一个cas server方便测试,发现网上的资料都比较旧,官方文档也比较杂

Docker部署

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
version: '3'

services:
casserver:
image: apereo/cas
container_name: casserver
environment:
- SERVER_SSL_ENABLED=false
- SERVER_PORT=8080
ports:
- "8081:8080" # 8080是内部端口
volumes:
- ./cas:/etc/cas
restart: unless-stopped

cas/services/HTTP.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"@class": "org.apereo.cas.services.CasRegisteredService",
"serviceId": "^http://localhost:8080/.*",
"name": "HTTP",
"id": 10000001,
"description": "本地测试服务",
"evaluationOrder": 10,
"attributeReleasePolicy": {
"@class": "org.apereo.cas.services.ReturnAllAttributeReleasePolicy"
},
"accessStrategy": {
"@class": "org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy",
"enabled": true,
"ssoEnabled": true
}
}

cas/config/cas.properties

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# cas/config/cas.properties
cas.authn.accept.users=YOUR_USERNAME::YOUR_PASSWD
cas.tgc.secure=false
cas.warningCookie.secure=false

# 设置services配置文件路径
cas.service-registry.core.init-from-json=true
cas.service-registry.json.location=file:/etc/cas/services

# 关闭SSL验证
server.ssl.enabled=false
cas.monitor.endpoints.enabled=true

# 设置HTTP服务器
cas.server.httpPort=8080
server.port=8080

# 修改服务器名称为HTTP
cas.server.name=http://localhost:8080
cas.server.prefix=${cas.server.name}/cas

# 允许HTTP协议的服务注册
cas.serviceRegistry.initFromJson=true

效果图

可能遇到的问题

笔者在本地部署没有遇到问题,但在服务器上部署出现了莫名其妙的docker架构不匹配的错误。简单指定docker镜像为较老的版本即可,例如 7.1.0-SNAPSHOT