【问题标题】:How to connect with an external/online LDAP server using Spring Boot?如何使用 Spring Boot 连接外部/在线 LDAP 服务器?
【发布时间】:2018-02-02 16:43:20
【问题描述】:

我正在尝试在我的 Spring Boot 应用程序中集成基于 LDAP 的登录。

作为第一步,我正在尝试使用此 LDAP 服务器 (http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/)。

但是,我无法成功连接服务器并收到此错误。

nested exception is javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]

我在配置类中使用此信息。

authenticationManagerBuilder.ldapAuthentication()
            .contextSource().url("ldap://ldap.forumsys.com:389/dc=example,dc=com")
            .managerDn("cn=read-only-admin,dc=example,dc=com").managerPassword("password")
            .and()
            .userSearchBase("ou=mathematicians")
            .groupSearchBase("ou=mathematicians")
            .userSearchFilter("(cn={0})");

这是我的这个项目的 application.properties 文件。

spring.ldap.urls=ldap.forumsys.com:389
spring.ldap.base=cn=read-only-admin,dc=example,dc=com
spring.ldap.password=password

任何人都可以使用 LDAP 服务器为 Spring Boot 应用程序提供工作配置吗?

【问题讨论】:

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


    【解决方案1】:

    当我从 LDAP 服务器收到此错误代码时。

    LDAP: error code 49 - Invalid Credentials
    

    问题在于我发送到 LDAP 服务器以打开通信通道的信息。因此,当我将请求更改为不同的对象时,它就开始工作了。

    这是我们需要从 Spring 发送到 LDAP 服务器的正确请求。

    authenticationManagerBuilder
                    .ldapAuthentication()
                    .userDetailsContextMapper(inetOrgPersonContextMapper())
                    .userSearchFilter("(uid={0})")
                    .userSearchBase("dc=example,dc=com")
                    .groupSearchBase("ou=mathematicians,dc=example,dc=com")
                    .groupSearchFilter("cn={0}")
                    .contextSource()
                    .url("ldap://ldap.forumsys.com")
                    .port(389)
                    .managerDn("cn=read-only-admin,dc=example,dc=com")
                    .managerPassword("password");
    

    【讨论】:

      【解决方案2】:

      使用下面的应用程序属性。

          ldap.enabled = true
      
      ####### LDAP TEST##############
      ldap.urls= ldap://ldap.forumsys.com:389/
      ldap.base.dn= dc=example,dc=com
      ldap.username= cn=read-only-admin,dc=example,dc=com
      ldap.password= password
      ldap.user.dn.pattern = uid={0}
      

      【讨论】:

        【解决方案3】:

        这是正确的配置:

        authenticationManagerBuilder
                     .ldapAuthentication()
                     .userSearchFilter("(uid={0})")
                     .userSearchBase("dc=example,dc=com")
                     .groupSearchFilter("uniqueMember={0}")
                     .groupSearchBase("ou=mathematicians,dc=example,dc=com")
                     .userDnPatterns("uid={0}")
                     .contextSource()
                     .url("ldap://ldap.forumsys.com:389")
                     .managerDn("cn=read-only-admin,dc=example,dc=com")
                     .managerPassword("password");
        

        【讨论】:

          猜你喜欢
          • 2018-04-13
          • 2020-02-08
          • 2021-09-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-07-18
          • 2022-10-04
          • 2015-11-06
          相关资源
          最近更新 更多