简体   繁体   English

Java LDAP密码身份验证

[英]Java LDAP password authentication

The below search term seems to return match if a user simply exists in the active directory: 如果用户只是存在于活动目录中,则下面的搜索词似乎返回匹配:

NamingEnumeration<SearchResult> ne = dirContext.search(
                        baseDN,
                        userObjectQuery,
                        new String[] { userName },
                        SearchControls)

The userObjectQuery is like userObjectQuery=(&(sAMAccountName=%u)(objectclass=user)) userObjectQuery类似于userObjectQuery=(&(sAMAccountName=%u)(objectclass=user))

Where %u above will be substituted by the username. 上面的%u将被用户名替换。

How do I make sure that the users password also matches and only then return true? 如何确保用户密码也匹配,然后才返回true?

Once you find the user using your search code, you can get the user's full DN with getNameInNamespace() 一旦您找到使用搜索代码的用户,您就可以使用getNameInNamespace()获取用户的完整DN

Then you can bind as that full DN and password to authenticate. 然后,您可以绑定为完整的DN和密码进行身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM