通过 LDAPTemplate 在 Spring 中查询 LDAP 组 - 需要授权以及如何授权?

问题描述 投票:0回答:1

我正在开发一个 Spring Boot 应用程序,它可以连接到 LDAP 服务器以进行身份验证和某些(有限的)查询目的。

现在,身份验证和我需要的查询可以与 Spring 嵌入式 LDAP 服务器、BindAuthenticator 和 org.springframework.ldap.core.LdapTemplate 一起使用。我需要获取所有组,我用这段代码成功完成了:

    *List<String> groups =  ldapTemplate.search(
        query().where("objectclass").is("groupOfNames"),
        (AttributesMapper<String>) attributes -> attributes.get("cn").get().toString()
    );*

最后,我的问题:

我还没有访问我客户的 LDAP 服务器的权限。如果我连接到“现实生活中”的 LDAP 服务器,我可能无法在没有凭据的情况下查询它,对吗?否则,任何人只要知道 url 和端口就可以查询 LDAP 服务器。一般或什至一般使用 LdapTemplate 或 Spring 时如何传递这些凭据?我似乎找不到关于这个话题的任何东西。

谢谢!

active-directory ldap ldap-query spring-ldap spring-security-ldap
1个回答
0
投票

身份验证在 LDAP bind 步骤执行。常见的绑定机制是简单绑定和 SASL 绑定。如果您想使用 Kerberos 等,则使用后者。

当然,这完全取决于您要连接的 LDAP 服务器的能力及其支持的 LDAP 协议和 SASL 机制。您可以通过对不需要客户端身份验证的服务器 DIT 库(或 Active Directory 中的 RootDSE)发出搜索操作来获取此信息。例如,如果在 Linux 上使用 openldap-clients,

$ ldapsearch -x -H ldap://domain -b "" -s base

这里:

  • -x
    代表匿名绑定
  • -H
    ldap 或 AD 域
  • -b
    指定DIT根作为搜索基础(ldap搜索的起点)
  • -s
    指定搜索范围为“base”(限制搜索到根条目)

它将返回一个包含很多属性的条目,但相关的是:

  • supportedSASLMechanisms
    :服务器支持 LDAP 绑定的 SASL 机制
  • supportedLDAPVersion
    :服务器支持的LDAP协议版本。现在大多数常见的实现都支持 LDAPv3。 LDAPv2 是较旧的协议。

来源:

  1. DIT 和 LDAP 根 DSE
  2. LDAP 绑定操作

我不熟悉 Spring,所以这是一般的 ldap 建议。 Spring ldap 应该有更多关于其 ldap 绑定 API 以及如何使用各种身份验证机制的具体信息。

© www.soinside.com 2019 - 2024. All rights reserved.