java - 如何从 java 对 Active Directory 进行用户身份验证?

标签 java spring authentication active-directory

我需要通过 java 对 Active Directory 进行用户身份验证。为了了解幕后发生的事情,我从这里开始使用 openldap docker 实例和 spring 教程: https://spring.io/guides/gs/authenticating-ldap/

我从许多调试 session 中了解到,Spring 从 ldap 检索密码属性并将其与散列用户密码进行比较,或者它只是通过 uid 和散列密码过滤用户,如果存在条目,则密码是正确的。

好的,听起来不错。现在我正尝试对 Active Directory 执行同样的操作。问题是,当我从中检索用户时,它给了我许多属性,但它没有给我任何看起来像散列密码的属性。因此,也许 Active Directory 不允许获取密码属性,我应该按此属性过滤用户。但我不知道它的名字,也不知道从哪里得到它。

所以我的问题是: 1.我理解的一切都正确吗? 2. 我是否需要仅通过 uid 和哈希密码过滤用户? 3. 如果第二个是正确的,那么用户过滤的查询是什么? 4.如果第二个不正确,那么我理解错了什么?我应该如何从java针对Active Directory对用户进行身份验证?

最佳答案

我将继续使用 Active Directory 的绑定(bind)身份验证方法。我过去曾使用过这种方法,对于 Active Directory(或 ADAM)没有任何问题。在绑定(bind)场景中,您只需使用用户提供的用户名和密码,并允许 LDAP 实例执行比较(身份验证)。以下是 Spring 文档的引用部分:

18.3.2 Using Bind Authentication

This is the most common LDAP authentication scenario.

This simple example would obtain the DN for the user by substituting the user login name in the supplied pattern and attempting to bind as that user with the login password. This is OK if all your users are stored under a single node in the directory. If instead you wished to configure an LDAP search filter to locate the user, you could use the following:

If used with the server definition above, this would perform a search under the DN ou=people,dc=springframework,dc=org using the value of the user-search-filter attribute as a filter. Again the user login name is substituted for the parameter in the filter name. If user-search-base isn't supplied, the search will be performed from the root.

您可能需要阅读有关 LDAP 身份验证的内容(Spring 3.x 文档中的第 18 章)。可能还有其他您认为有用的信息。

关于java - 如何从 java 对 Active Directory 进行用户身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43121073/

相关文章:

java - 使用 Apache FOP Java 库将 FO 转换为 PDF/a

java - 只从 Tableview 中删除,而不是从 observableList 中删除

java - 在 Swing 应用程序中嵌入 JFXPanel 在添加/删除时失败

spring - 防止网页上出现Spring错误

spring - 创建maven项目时如何选择过滤器编号?

javascript - 在数组内的对象中搜索

java - WSDL 客户端身份验证和多个证书

asp.net-mvc - 在Asp.net Core中openid connect登录后运行代码

java - 为什么要使用 getInstance

java - 使用 Web 服务客户端 JAXB 生成的类作为 JPA 实体