zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

Apereo CAS(四)MongoDB作为服务注册的存储

MongoDB注册存储服务 作为 CAS Apereo
2023-06-13 09:14:46 时间

可以以不同的方式保存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