Authentication 使用电子邮件和密码验证LDAP中的用户
我不熟悉LDAP API。我能够连接到LDAP服务器并搜索用户。如何使用未绑定的LDAP API使用电子邮件/密码对用户进行身份验证 我在LDAP中没有看到任何使用电子邮件和密码对用户进行身份验证的身份验证 是否可以使用电子邮件和密码对用户进行身份验证 我正在做什么来验证下面给出的用户Authentication 使用电子邮件和密码验证LDAP中的用户,authentication,ldap,unboundid-ldap-sdk,Authentication,Ldap,Unboundid Ldap Sdk,我不熟悉LDAP API。我能够连接到LDAP服务器并搜索用户。如何使用未绑定的LDAP API使用电子邮件/密码对用户进行身份验证 我在LDAP中没有看到任何使用电子邮件和密码对用户进行身份验证的身份验证 是否可以使用电子邮件和密码对用户进行身份验证 我正在做什么来验证下面给出的用户 在用户目录下搜索并匹配电子邮件并查找他的DN 基于连接用户的DN,如果连接成功,则对用户进行身份验证,或者在连接过程中出现执行选项,则用户未进行身份验证 是否有正确的方法对用户进行身份验证?您必须执行两个步骤 使
是否有正确的方法对用户进行身份验证?您必须执行两个步骤
false
)。此代码假定baseObject为dc=example,dc=com,需要进行子树搜索,并且具有电子邮件地址的属性具有别名mail。该代码还假设存在一个bindDN和bindPassword,该bindDN和bindPassword具有足够的访问权限来搜索具有电子邮件地址的用户。它搜索的电子邮件地址假定为babs。jensen@example.com.
例外情况始终被忽略
String baseObject = "dc=example,dc=com";
String bindDN = "dn-with-permission-to-search";
String bindPassword = "password-of-dn-with-permission-to-search";
// Exceptions ignored.
LDAPConnection ldapConnection =
new LDAPConnection(hostname,port,bindDN,bindPassword);
String emailAddress = "babs.jensen@example.com";
String filterText = String.format("mail=%s",emailAddress);
SearchRequest searchRequest = new SearchRequest(baseObject,
SearchScope.SUB,filterText,"1.1");
SearchResult searchResult = ldapConnection.search(searchRequest);
boolean authenticated = false;
if(searchResult.getEntryCount() == 1)
{
// There is one entry with that email address
SearchResultEntry entry = searchResult.getSearchEntries().get(0);
// Create a BIND request to authenticate. The password has
// has to come from someplace outside this code
BindRequest bindRequest =
new SimpleBindRequest(entry.getDN(),password);
ldapConnection.bind(bindRequest);
authenticated = true;
}
else if(searchResult.getEntryCount() > 1)
{
// more than one entry matches the search parameters
}
else if(searchResult.getEntryCount() == 0)
{
// no entries matched the search parameters
}