ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

Apereo CAS 基于 LDAP 的代理认证(Surrogate Authentication)存储配置指南

Apereo CAS 基于 LDAP 的代理认证(Surrogate Authentication)存储配置指南 后端认证鉴权单点登录【免费下载链接】casApereo CAS - Identity Single Sign On for all earthlings and beyond.项目地址https://gitcode.com/gh_mirrors/ca/cas点击查看免费下载导读代理认证Surrogate Authentication又称身份模拟/代登录允许一个主账号如管理员在未持有目标用户密码的情况下以目标用户身份完成登录。Apereo CAS 支持将代理账号的授权数据存放在 LDAP 中本文围绕 Surrogate-Authentication-Storage-LDAP.md 展开系统讲解如何在 WAR overlay 中引入 LDAP 支持模块、配置 LDAP 连接与三条核心搜索过滤器授权、验证、成员检索并结合仓库源码说明底层判定逻辑读完即可在真实 LDAP 目录上落地管理员代登录场景。一、模块引入在 WAR overlay 中添加依赖LDAP 代理认证支持由独立模块cas-server-support-surrogate-authentication-ldap提供。在基于 CAS 官方 WAR overlay 的构建中向build.gradle的依赖区添加implementation org.apereo.cas:cas-server-support-surrogate-authentication-ldap:${project.cas.version}该模块在仓库中的完整位置为 support/cas-server-support-surrogate-authentication-ldap其中包含核心实现类、自动配置类以及集成测试与 LDIF 测试数据。二、工作原理概述从源码看LDAP 代理认证的完整授权链路由 SurrogateLdapAuthenticationService 实现其整体流程分三个阶段成员检索列出可模拟账号用search-filter默认参数占位符{user}定位主用户在 LDAP 中的条目读取该条目上的member-attribute-name属性将属性的每个值用member-attribute-value-regex正则匹配提取出当前主用户被允许模拟的账号列表。授权判定是否可以模拟某个账号当用户实际发起代理登录时用surrogate-search-filter执行搜索过滤器可引用{user}主用户与{surrogate}被模拟账号两个占位符只要返回了结果条目且被模拟账号通过存在性校验即判定授权通过。被模拟账号存在性校验通过可选的surrogate-validation-filter占位符{surrogate}确认被模拟账号确实存在于 LDAP 中避免模拟一个不存在或已禁用的账号。2.1 自动装配与激活条件模块通过 CasSurrogateLdapAuthenticationAutoConfiguration 完成自动配置。该配置类的启用需要满足两个条件特性开关ConditionalOnFeatureEnabled(feature SurrogateAuthentication, module ldap)即代理认证特性开启且模块为ldap连接配置BeanCondition.on(cas.authn.surrogate.ldap[0].ldap-url)即必须配置至少一个 LDAP 源否则ldapSurrogateAuthenticationServiceBean 不会创建。满足条件后会注册一个SurrogateAuthenticationServiceBeanBean 名ldapSurrogateAuthenticationService供上层代理认证 Webflow 调用。服务构造时会基于cas.authn.surrogate.ldap列表逐个创建LdapConnectionFactory连接池并在容器销毁时统一关闭见destroy()方法。三、完整配置示例可直接复制以下是集成测试SurrogateLdapAuthenticationServiceTests中使用的真实可用配置可在cas.properties中按需修改# LDAP 源 0 cas.authn.surrogate.ldap[0].ldap-urlldap://localhost:10389 cas.authn.surrogate.ldap[0].base-dnousurrogates,dcexample,dcorg cas.authn.surrogate.ldap[0].bind-dncnDirectory Manager cas.authn.surrogate.ldap[0].bind-credentialpassword # 授权过滤器判断主用户是否被允许模拟某个账号 cas.authn.surrogate.ldap[0].surrogate-search-filteremployeeType{surrogate} # 被模拟账号存在性验证过滤器 cas.authn.surrogate.ldap[0].surrogate-validation-filtercn{surrogate} # 成员检索定位主用户条目读取其属性值并正则筛选可模拟账号 cas.authn.surrogate.ldap[0].search-filtercn{user} cas.authn.surrogate.ldap[0].member-attribute-namemail cas.authn.surrogate.ldap[0].member-attribute-value-regex\\wexample.org|\\*3.1 属性说明上述参数在 SurrogateLdapAuthenticationProperties 中定义继承自AbstractLdapSearchProperties因此也支持该基类提供的 LDAP 连接池、超时、TLS 等常规参数。各参数语义如下配置项必填说明surrogate-search-filter是授权搜索过滤器用于判定主用户是否被授权模拟给定账号。可在过滤器中通过{user}引用主用户名、{surrogate}引用被模拟账号。示例((uid{user})(xyzMemberOfactAs:{surrogate}))。该过滤器必须引用{surrogate}参数否则无法限定可模拟账号会被日志记录为错误并忽略。member-attribute-name是主用户 LDAP 条目上用于标记其可模拟账号的属性名如mail、employeeType该属性的所有值都会与下面的正则做匹配。member-attribute-value-regex是对属性值进行匹配的正则表达式必须至少包含一个捕获组匹配成功后第 1 个捕获组的值即为被授权可模拟的账号名。若没有捕获组则取整个匹配值。surrogate-validation-filter否可选的被模拟账号存在性验证过滤器占位符为{surrogate}。未配置时默认认为被模拟账号存在跳过校验。示例((uid{surrogate})(authorizedTRUE))。3.2 多 LDAP 源配置配置为索引数组即可同时挂接多个 LDAP 源cas.authn.surrogate.ldap[0].ldap-urlldap://ldap1.example.org:389 cas.authn.surrogate.ldap[0].base-dnousurrogates,dcexample,dcorg cas.authn.surrogate.ldap[0].surrogate-search-filter((uid{user})(actAs{surrogate})) cas.authn.surrogate.ldap[0].surrogate-validation-filteruid{surrogate} cas.authn.surrogate.ldap[0].search-filtercn{user} cas.authn.surrogate.ldap[0].member-attribute-namememberOf cas.authn.surrogate.ldap[0].member-attribute-value-regexcn(\\w),ousurrogates cas.authn.surrogate.ldap[1].ldap-urlldap://ldap2.example.org:389 cas.authn.surrogate.ldap[1].base-dnousurrogates,dcexample,dcorg cas.authn.surrogate.ldap[1].surrogate-search-filteremployeeType{surrogate} cas.authn.surrogate.ldap[1].surrogate-validation-filtercn{surrogate} cas.authn.surrogate.ldap[1].search-filtercn{user} cas.authn.surrogate.ldap[1].member-attribute-namemail cas.authn.surrogate.ldap[1].member-attribute-value-regex\\wexample.org|\\*从源码结构看canImpersonateInternal与getImpersonationAccounts都会遍历全部 LDAP 源任一源返回结果即放行而doesSurrogateAccountExistInLdap也会在所有源中校验被模拟账号的存在性只要任一源能找到即通过。四、源码级流程解析4.1 列出可模拟账号getImpersonationAccounts对应 SurrogateLdapAuthenticationService.java#L90-L136。逻辑为用search-filter与{user}构造 LDAP 搜索过滤器定位主用户条目若搜索结果为空直接返回空列表读取该条目上member-attribute-name指定的属性属性不存在或值为空则返回空列表用member-attribute-value-regex构造正则对每个属性值做matches匹配若有捕获组则取group(1)否则取完整匹配值结果排序后返回。4.2 授权判定canImpersonateInternal对应 SurrogateLdapAuthenticationService.java#L63-L88。逻辑为遍历所有 LDAP 源检查surrogate-search-filter是否包含第 1 个{surrogate}参数SURROGATE_FILTER_PARAMETER_INDEX 1。若过滤器中根本没有{surrogate}占位符说明该过滤器无法限定可模拟账号直接记录错误并跳过该源用{user}主用户 ID与{surrogate}被模拟账号构造搜索过滤器在base-dn下执行搜索带分页page-size若返回结果条目且doesSurrogateAccountExistInLdap(surrogate)通过存在性校验则判定授权成功。4.3 被模拟账号存在性校验doesSurrogateAccountExistInLdap对应 SurrogateLdapAuthenticationService.java#L138-L163。逻辑为若surrogate-validation-filter未配置空白直接返回true即跳过校验否则用{surrogate}占位符构造验证过滤器在所有 LDAP 源中搜索任一源返回结果条目即视为存在。4.4 通配账号isWildcardedAccount在基类判定之外还会额外调用doesSurrogateAccountExistInLdap(surrogate)确保通配符如配置中member-attribute-value-regex含*展开出的每个账号都真实存在于 LDAP。五、LDAP 数据模型与测试数据参考仓库在 support/cas-server-support-surrogate-authentication-ldap/src/test/resources/ldif 提供了可直接对照的 LDIF 样例ldap-surrogates-ou.ldif创建代理账号所在的组织单元如ousurrogates,dcexample,dcorgldap-surrogate.ldif创建具体用户条目例如dn: cn$user,ousurrogates,dcexample,dcorg objectClass: organizationalRole objectClass: inetOrgPerson objectClass: person objectClass: account cn: $user userPassword: 123456 mail: $userexample.org sn: CAS uid: $user employeeType: banderson注意其中employeeType与mail两个属性正是配置中surrogate-search-filter与member-attribute-name所引用的字段employeeType: banderson表示该用户可模拟banderson而mail: *则表示通配可模拟任意满足正则\wexample.org的账号。测试中还包含nomail无 mail 属性与bandersonemployeeType: nothing等反例用于验证无属性值即不可模拟的边界行为。六、集成测试验证仓库中的 SurrogateLdapAuthenticationServiceTests标注Tag(LdapRepository)需本机 10389 端口存在 LDAP 服务覆盖了两类关键场景单 LDAP 源verifyUserDisabled验证banderson、nomail等未授权/无属性用户调用getImpersonationAccounts返回空列表多 LDAP 源verifyImpersonationWithSurrogateValidatedByDifferentLdapSource验证授权条目在某一个 LDAP 源、被模拟账号存在性由另一个 LDAP 源确认的跨源场景也能正确授权——这正是 4.2 与 4.3 遍历所有 LDAP 源设计的用意所在。七、注意事项与最佳实践surrogate-search-filter必须包含{surrogate}占位符否则 CAS 会输出does not refer to the [surrogate] parameter错误并忽略该过滤器导致授权永远无法通过member-attribute-value-regex建议使用带捕获组的正则如cn(\w),ousurrogates否则会取整个属性值作为账号名若 LDAP 数据量较大可合理设置page-size分页参数AbstractLdapSearchProperties提供控制搜索结果规模若需要验证被模拟账号存在且处于可用状态务必配置surrogate-validation-filter否则默认跳过存在性校验被模拟账号的登录完成后CAS 审计日志中会记录主用户与代理身份便于事后追溯。至此从模块引入、LDAP 数据建模到三条过滤器的语义与底层执行逻辑均已覆盖可直接在 overlay 中按 3.1 的属性表落地生产配置并参照第 5、6 节的 LDIF 样例与测试用例自建验证环境。赞分享后端认证鉴权单点登录【免费下载链接】casApereo CAS - Identity Single Sign On for all earthlings and beyond.项目地址https://gitcode.com/gh_mirrors/ca/cas点击查看免费下载相关推荐Apereo CAS 静态代理认证Simple Surrogate Authentication配置与实现原理Apereo CAS 静态代理认证Simple Surrogate Authentication配置与实现原理 代理认证Surrogate Authent后端认证鉴权单点登录Windows安卓应用安装器5分钟快速上手指南Windows安卓应用安装器5分钟快速上手指南 在Windows电脑上直接运行安卓应用这听起来像是未来科技但现在已经成为现实。APK安装器正是这样一个革命后端认证鉴权单点登录Apereo CAS 基于 JDBC 的 Surrogate代理认证存储配置、SQL 查询与源码实现Apereo CAS 基于 JDBC 的 Surrogate代理认证存储配置、SQL 查询与源码实现 导读 本文围绕 Apereo CAS 的 JDBC后端认证鉴权单点登录上一篇如何快速掌握窗口尺寸强制调整终极免费工具WindowResizer使用指南下一篇LifeOS 中 create_pattern 模式实战把任意 LLM Prompt 一键重构为结构化 Fabric 模式创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表