Authentication 使用电子邮件和密码验证LDAP中的用户

Authentication 使用电子邮件和密码验证LDAP中的用户,authentication,ldap,unboundid-ldap-sdk,Authentication,Ldap,Unboundid Ldap Sdk,我不熟悉LDAP API。我能够连接到LDAP服务器并搜索用户。如何使用未绑定的LDAP API使用电子邮件/密码对用户进行身份验证 我在LDAP中没有看到任何使用电子邮件和密码对用户进行身份验证的身份验证 是否可以使用电子邮件和密码对用户进行身份验证 我正在做什么来验证下面给出的用户 在用户目录下搜索并匹配电子邮件并查找他的DN 基于连接用户的DN,如果连接成功,则对用户进行身份验证,或者在连接过程中出现执行选项,则用户未进行身份验证 是否有正确的方法对用户进行身份验证?您必须执行两个步骤 使

我不熟悉LDAP API。我能够连接到LDAP服务器并搜索用户。如何使用未绑定的LDAP API使用电子邮件/密码对用户进行身份验证

我在LDAP中没有看到任何使用电子邮件和密码对用户进行身份验证的身份验证

是否可以使用电子邮件和密码对用户进行身份验证

我正在做什么来验证下面给出的用户

  • 在用户目录下搜索并匹配电子邮件并查找他的DN

  • 基于连接用户的DN,如果连接成功,则对用户进行身份验证,或者在连接过程中出现执行选项,则用户未进行身份验证


  • 是否有正确的方法对用户进行身份验证?

    您必须执行两个步骤

  • 使用管理登录,在目录中搜索用户
  • 使用该用户的DN和他提供的密码,尝试绑定
  • 如果其中一个未成功,则说明标识或密码不正确。

    使用,这段简单的代码将搜索条目。如果有一个
    条目具有已知的电子邮件地址,请使用该DN绑定(密码必须来自其他地方)。如果有多个条目与搜索参数匹配,或者如果没有条目与搜索参数匹配,则不会发生任何情况(authenticated is
    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
    }