【问题标题】:Spring-boot LDAP - Property 'userDn' not setSpring-boot LDAP - 未设置属性'userDn'
【发布时间】:2020-11-03 21:56:42
【问题描述】:

我正在运行一个 Spring-boot 应用程序,它通过我们的内部 LDAP 使用 spring-security-ldap 对用户进行身份验证。

默认情况下它以匿名方式与 LDAP 绑定。

Property 'userDn' not set - anonymous context will be used for read-write operations

但我希望第一个绑定使用当前用户名。

我应该在哪里指定 userDn 属性?

感谢您的建议

【问题讨论】:

  • 通常,userDn 来自用户名输入。代码应将用户名解析为 DN,并使用该 DN + 密码输入进行身份验证(绑定)。
  • 有没有办法验证 userDn 是否已正确归档?

标签: spring-boot ldap spring-ldap


【解决方案1】:

我不是最了解 Spring-boot 的人,更不用说 LDAP。 也就是说,您的 LDAP 配置属性应该在您的 application.properties 文件中提及并命名为 spring.ldap.*。 它们在文档here 中有所提及。

在初始化您的身份验证提供程序时,您可以传递重要的属性,例如 Base DN(搜索的根)和过滤器,使用:

.userSearchBase("ou=<your users container>").userSearchFilter("(uid={0})")

您的搜索过滤器很可能是uid={0}cn={0}

【讨论】:

  • 这不回答他为什么会得到那个错误。
【解决方案2】:

在使用 spring ldap 时,您可能从网上的许多教程开始,但其中主要使用嵌入式 ldap 服务器;嵌入式服务器使用 ldif 文件,不需要管理员凭据。

当连接到外部 ldap 服务器时,您需要通过 managerDn 方法指定 userDn 设置它。这里是sn-p的代码

protected void configure(AuthenticationManagerBuilder auth) throws Exception {
       auth.ldapAuthentication().contextSource().managerDn("uid=admin,ou=system")
        .managerPassword("secret")
.......
}

显然,您还需要提供所有其他信息,如 url、端口等(以及 mvreijn 告诉的 userSearchBase)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-31
    • 2020-08-21
    • 2021-03-06
    • 2017-10-20
    • 2017-07-02
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    相关资源
    最近更新 更多