在 Active Directory 中查找具有 networkID 的用户所需的搜索过滤器

Search Filter needed to find a user with networkID in Active Directory

2019 年 5 月 28 日更新

我正在使用 org.springframework.security.ldap.authentication.ad 中的 ActiveDirectoryLdapAuthenticationProvider,并且 searchForUser 方法能够通过电子邮件找到用户。

我正在使用默认 searchFilter(&(objectClass=user)(userPrincipalName={0}))

但是,如果将 networkID 作为用户名提供,则无法使用。所以:

employee@PublicCompanyEmail.com 工作正常

employee_AD_username@internaldomain.com 无效

感谢任何关于它的想法!

呵呵,您遇到了 eUPN 与 iUPN 的问题。您的公司使用 UPN 后缀,为存储在 userPrincipalName 字段中的每个用户创建一个具有虚拟企业 UPN 的虚拟域。一旦隐式 UPN(Kerberos 主体)被企业级覆盖,你就倒霉了。

你可能想要考虑一些比一遍又一遍地用用户名和密码唠叨你的用户更好的东西......至少在 Tomcat 如果你可以忍受 [=11],你可以拥有 this =] 在 Spring 安全性中。

先了解一些术语

安全客户经理 (SAM) 姓名

  The networkID you use to login to the network.

用户主体名称 (UPN)

 It may be Implicit UPN (iUPN) or Explicit UPN (eUPN).

 An example for iUPN would be: networkID@internalDomain.com

 An example for eUPN would be: employee_name@companyName.com

 eUPN may be defined by network administrator.

 In my case, the UPN we're using in our AD is actually an eUPN.

搜索过滤器语法

 This is query language for AD.

 We used it to define the filter while searching for objects in AD.

 {0}-occurrence means full username with domain in it. If the domain is defined in LDAP configuration then Spring Security checks if it's present in the entered username to login. If not, then it'll be added.

 {1}-occurrence means whatever entered as username. So, Spring won't do any modification on the provided username.

如果想不提供域名也能登录,需要在LDAP配置中定义域

ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(
            "domain",...);

那么如果它是电子邮件地址中使用的域,则此过滤器:

(&(objectClass=user)(userPrincipalName={0}))

将查找有和没有域名的用户。

那么如果配置的域是internal-domain,这个过滤器:

(&(objectClass=user)(sAMAccountName={1}))

如果提供的用户名是没有doamin的networkID,将找到用户。

如果您没有为 LDAP 配置定义域并在实例化对象时将其保留为空,那么您应该能够搜索出现 {1} 次的 UPN 和 sam -account,但您必须提供登录时 networkID 和 email-username 的域。