You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Keycloak 21.0.1与LDAP用户同步失败问题求助

问题排查与解决方案

核心问题分析

从错误日志可直接定位问题:

ERROR [org.keycloak.storage.ldap.LDAPStorageProviderFactory] (executor-thread-4) Failed during import user from LDAP: org.keycloak.models.ModelException: User returned from LDAP has null username! Check configuration of your LDAP mappings. Mapped username LDAP attribute: uid, user DN: uid=nogroup,dc=example,dc=com, attributes from LDAP: {mail=[nogroup@ldap.forumsys.com], sn=[Group], cn=[No Group]}

Keycloak将username映射到LDAP的uid属性,但同步时获取到了非用户条目(uid=nogroup,dc=example,dc=com),该条目无uid属性,导致同步失败。同时查询范围包含大量非用户对象,造成20条同步失败。


具体修复步骤

1. 缩小LDAP用户查询范围

forumsys免费测试LDAP的用户全部存储在ou=people,dc=example,dc=com组织单元下,当前配置的查询基准DN可能为根目录dc=example,dc=com,导致查询到组、非用户条目。

  • 进入Keycloak的LDAP配置页面,将Users DN修改为:ou=people,dc=example,dc=com

2. 严格用户过滤条件

添加对象类过滤,确保只查询用户类型的LDAP条目:

  • 将用户过滤条件设置为:(objectClass=inetOrgPerson)
    forumsys的用户条目均使用inetOrgPerson对象类,此规则会自动排除组、角色等非用户对象。

3. 验证属性映射

确认Keycloak中username对应的LDAP属性为uid(forumsys测试用户的uid属性均存在,例如einstein、newton等用户),无需修改此映射。


测试验证

调整配置后,先执行测试LDAP连接,验证是否能正确获取用户列表,再执行用户同步操作,即可解决0新增、全部失败的问题。

内容的提问来源于stack exchange,提问作者srinivas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 13:17:20