我正在运行一个 Spring-boot 应用程序,它通过我们的内部 LDAP 使用 spring-security-ldap 对用户进行身份验证。
默认情况下它与 LDAP 匿名绑定。
Property 'userDn' not set - anonymous context will be used for read-write operations
但我希望第一个绑定使用当前用户名。
我应该在哪里指定 userDn 属性?
谢谢您的建议
使用 spring ldap 时,您可能从网上的许多教程开始,但其中主要使用嵌入式 ldap 服务器;嵌入式服务器使用 ldif 文件,不需要管理员凭据。
连接到外部 LDAP 服务器时,您需要通过 managerDn 方法指定 userDn 设置。这是代码片段
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication().contextSource().managerDn("uid=admin,ou=system")
.managerPassword("secret")
.......
}
显然你还需要提供所有其他信息,如 url、端口等(以及像 mvreijn 告诉的 userSearchBase)。
我不是对 Spring-boot 最了解的人,更不是对 LDAP 最了解的人。 也就是说,您的 LDAP 配置属性应该在您的
application.properties
文件中提及并命名为 spring.ldap.*
。
它们在文档here中提到。
初始化身份验证提供程序时,您可以使用以下方法传递重要属性,例如基本 DN(搜索根)和过滤器:
.userSearchBase("ou=<your users container>").userSearchFilter("(uid={0})")
您的搜索过滤器很可能是
uid={0}
或 cn={0}
。