Apereo CAS 使用MongoDB作为Service注册的存储

可以以不同的方式保存 Servcie 的注册信息,参考这里获得完整列表:https://apereo.github.io/cas/6.5.x/services/Service-Management.html#storage。
这里只记录下如何设置 MongoDB 作为存储端,官方文档:https://apereo.github.io/cas/6.5.x/services/MongoDb-Service-Management.html。

1. 添加依赖

implementation "org.apereo.cas:cas-server-support-mongo-service-registry"

2. 设置

cas.service-registry.mongo.client-uri=mongodb://casdb_user:password@localhost:27017/cas_db
cas.service-registry.mongo.collection=cas_serviceregistry

3. 服务注册初始化

参数 cas.service-registry.core.init-from-json 用于控制在 CAS 系统启动时对发现的 json 格式的服务注册信息是否导入到对应的后端存储。默认为 true,这样启动时会把用 json 文件定义的服务注册信息写入到后端存储,这里是 cas_db 的 cas_serviceregistry collection。
开发初期可以使用 json 的方式调试,然后通过 init-from-json=true 把数据导入 DB 之后,再设置 init-from-json 为 false。

4. 设置 CAS-Management 使用 MongoDB 作为服务注册信息源。

CAS Management 应用之前通过下面的信息找到注册的服务数据,使用 MongoDDB 作为存储后,需要在 cas-management 的 build.gradle 中添加依赖:

implementation "org.apereo.cas:cas-server-support-mongo-service-registry"

同时 删除掉 cas.service-registry.json.location 的设置,并把把 cas-server 中关于 cas.service-registry.mongo 的配置 copy 过来。
cas.service-registry.mongo.client-uri=mongodb://casdb_user:password@localhost:27017/cas_db
cas.service-registry.mongo.collection=cas_serviceregistry

5. 通过 WebUI 注册一个新的 CAS Service。

通过 Web 界面添加一个新的 CAS Client 之后,查看 MongoDB 的 cas_serviceregistry collection,可以看到一个新的 document 数据被成功创建出来。



Reference:
[1]: https://apereo.github.io/cas/6.5.x/services/AutoInitialization-Service-Management.html