【问题标题】:how to define DN for ldif file if DC is not provided while configuring with spring boot如果在使用 Spring Boot 配置时未提供 DC,如何为 ldif 文件定义 DN
【发布时间】:2019-10-19 12:27:58
【问题描述】:

我正在使用带有 spring boot 的嵌入式 ldap 服务器来测试我的 ldif 文件及其凭据,但是我发现我的 ldif 文件格式与普通 ldif 有点不同,因为 dc 不是私有的,在 dn 内部只给出了 o。

我已经为上述 ldif 格式尝试了不同的配置,但它仍然显示 Bad Credentials 屏幕,但它与其他 ldif 文件一起工作正常。

ldif 文件

# id=00000001
dn: o=COMPANY
objectClass: organization
structuralObjectClass: organization
o: COMPANY
entryCSN: 20130409162114.626166Z#000000#000#000000
entryUUID: 3e7f8668-357d-1032-8a6b-c5bcf7f703f0
creatorsName: cn=Manager,o=COMPANY
createTimestamp: 20130409162114Z
modifiersName: cn=Manager,o=COMPANY
modifyTimestamp: 20130409162114Z
contextCSN: 20130702105648.506150Z#000000#000#000000
contextCSN: 20191018052018.692119Z#000000#001#000000
contextCSN: 20191018044350.858888Z#000000#002#000000
contextCSN: 20191018053729.621549Z#000000#003#000000

# id=00000002
dn: ou=department,o=COMPANY
objectClass: organizationalUnit
structuralObjectClass: organizationalUnit
ou: department
entryCSN: 20130409162455.623488Z#000000#000#000000
entryUUID: c2390a06-357d-1032-8a6c-c5bcf7f703f0
creatorsName: cn=Manager,o=COMPANY
createTimestamp: 20130409162455Z
modifiersName: cn=Manager,o=COMPANY
modifyTimestamp: 20130409162455Z

网络安全配置

@Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .ldapAuthentication()
                .userDnPatterns("uid={0},ou=department")
                .contextSource()
                    .url("ldap://localhost:8389/o=COMPANY")
                    .and()
                .passwordCompare()
                    .passwordEncoder(new LdapShaPasswordEncoder())
                    .passwordAttribute("userPassword");
}

application.properties

spring.ldap.embedded.base-dn= o=COMPANY
spring.ldap.embedded.ldif=classpath:ldap-server-2.ldif
spring.ldap.embedded.port= 8389
spring.ldap.embedded.validation.enabled=false

在配置完以上所有细节后,应用程序运行良好,我得到了身份验证屏幕,但是在正确的凭据之后发生事件,我得到了 Bad Credentials 屏幕。 我不知道有什么问题,是 ldif 的 dn 名称还是什么?

请提供您宝贵的建议。提前致谢!

【问题讨论】:

    标签: spring-boot ldap openldap spring-ldap spring-security-ldap


    【解决方案1】:

    o=COMPANY 作为根条目而不是使用 DC 本身不是问题。

    您的 ldif 似乎正确,但此处显示的内容不包含任何用户条目(仅id=00000001id=00000002)。

    因此,根据userDnPatterns("uid={0},ou=department"),用户条目应包含在ou=department 中,因此在您的ldif 文件中定义之后,例如。 :

    # id=00000003
    dn: uid=test,ou=department,o=COMPANY
    objectClass: inetOrgPerson
    objectClass: organizationalPerson
    objectClass: person
    objectClass: top
    uid: test
    mail: test@domain.com
    cn: Firstname Lastname
    givenName: Firstname
    sn: Lastname
    

    此外,大多数服务器不接受匿名绑定,身份验证请求本身可能需要绑定到服务器才能搜索给定条目并测试其凭据,只需在 WebSecurityConfig 的 @ 中添加 managerDn()managerPassword() 987654329@方法:

    .contextSource()
      .url('ldap://localhost:8389/o=COMPANY')
      .managerDn('admin')
      .managerPassword('password')
      .and()
    ...
    

    您也可以在 application.properties 中设置这些 ContextSource 参数:

    spring.ldap.embedded.credential.username= uid=admin
    spring.ldap.embedded.credential.password= password
    

    【讨论】:

    • 谢谢@Eric 我犯了和你说的一样的错误,我没有关注 ldif 文件中的用户数据。现在,它工作正常。感谢您的帮助!
    猜你喜欢
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    • 1970-01-01
    • 1970-01-01
    • 2019-07-12
    • 1970-01-01
    • 2020-05-15
    相关资源
    最近更新 更多