Spring boot SpringBoot+Spring安全性+LDAP登录,无UID

Spring boot SpringBoot+Spring安全性+LDAP登录,无UID,spring-boot,spring-security,ldap,spring-ldap,Spring Boot,Spring Security,Ldap,Spring Ldap,我是LDAP新手,我正试图弄清楚如何将spring安全性与LDAP一起用于登录。我阅读的所有示例/指南/教程都使用UID作为登录表单。我没有液体 结构如下: 在这里,我试图用MAIL替换UID,但它不起作用。 错误: 我希望有人知道如何在没有UID的情况下添加登录名,提前谢谢。将其放入答案中,因为它现在涉及代码块,这些代码块与注释不兼容 正如上面在评论中所讨论的,您的问题是Spring使用LdapTemplate进行LDAP访问,这使用LDAP搜索进行所有身份验证调用。搜索LDAP通常需要一个

我是LDAP新手,我正试图弄清楚如何将spring安全性与LDAP一起用于登录。我阅读的所有示例/指南/教程都使用UID作为登录表单。我没有液体

结构如下:

在这里,我试图用MAIL替换UID,但它不起作用。 错误:


我希望有人知道如何在没有UID的情况下添加登录名,提前谢谢。

将其放入答案中,因为它现在涉及代码块,这些代码块与注释不兼容

正如上面在评论中所讨论的,您的问题是Spring使用LdapTemplate进行LDAP访问,这使用LDAP搜索进行所有身份验证调用。搜索LDAP通常需要一个管理员帐户,SpringLDAP类称为managerDn。此managerDN通常在创建LDAP上下文源时设置。在您的情况下,设置它的方法由contextSource builder提供,设置如下:

auth.ldapAuthentication()
        .userDnPatterns("mail={0},ou=group")
        .groupSearchBase("ou=group")
        .contextSource()

        .managerDN("your admin account's Distinguished Name (DN)")
        .managerPassword("password associated with your admin account")

        .url("ldap://localhost:8389/dc=ad,dc=company,dc=com")
        .and()
        .passwordCompare()
        .passwordEncoder(new LdapShaPasswordEncoder())
        .passwordAttribute("userPassword");

TLDR可能重复:在尝试搜索之前,您可能需要使用管理员帐户绑定到LDAP,因为Spring LDAP在后台进行身份验证搜索。我有权使用我的帐户进行搜索,但我没有访问管理员帐户的权限。。。编辑:假设我收到了一个管理员帐户,我应该在哪里以及如何进行绑定?为了更好的可读性,将其放入答案中
Reason: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C0907C2, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v2580]; remaining name 'mail=erik.zs@mail.com, '
auth.ldapAuthentication()
        .userDnPatterns("mail={0},ou=group")
        .groupSearchBase("ou=group")
        .contextSource()

        .managerDN("your admin account's Distinguished Name (DN)")
        .managerPassword("password associated with your admin account")

        .url("ldap://localhost:8389/dc=ad,dc=company,dc=com")
        .and()
        .passwordCompare()
        .passwordEncoder(new LdapShaPasswordEncoder())
        .passwordAttribute("userPassword");