【问题标题】:LDAP Authentication queriesLDAP 身份验证查询
【发布时间】:2012-12-24 05:46:13
【问题描述】:
  1. 我在 Java LDAP 身份验证 (AD) 中遇到问题。我不明白这个 LDAP 身份验证是如何发生的

下面是代码,他们尝试使用用户名和密码获取包含 LDAP 服务器的所有详细信息的 InitialDirContext,如果它抛出基于返回代码决定的异常。

private void doSimpleAuthentication() {
        try {
            String hostURL = "ldap://" + hostName + ":" + port + "/";
            env.put(Context.PROVIDER_URL, hostURL);
            env.put(Context.SECURITY_AUTHENTICATION, "simple");

            String principal = userName + "@" + domain;

            // First connect to LDAP Server using Directory Manager credentials

            DirContext ctx = connectToDirServer(principal, password);
            returnCode = VALID_USER;

            if (warningPeriod >= 0) {
                String filter = "(sAMAccountName=" + userName + ")";
                SearchControls ctrl = new SearchControls();
                ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);
                NamingEnumeration results = ctx.search(baseDn, filter, ctrl);

                if (results != null && results.hasMoreElements()) {
                    SearchResult result = (SearchResult) results.next();
                    String attPrincipal = (result).getName() + "," + baseDn;

                    if ((!isPwdNeverExpires(result)) && isPasswordNearingExpiry(ctx, attPrincipal)) {
                        returnCode = PASSWORD_NEARING_EXPIRY;
                    }
                }
            }
            if (ctx != null) ctx.close();
        } catch (CommunicationException e) {
            errorMessage = e.getMessage();
            errorStackTrace = AgsUtil.convertToString(e);
            returnCode = SERVER_NOT_AVAILABLE;
        } catch (Exception e) {
            errorMessage = e.getMessage();
            errorStackTrace = AgsUtil.convertToString(e);
            returnCode = UNKNOWN_ERROR;
            if (errorMessage.indexOf("525") != -1 || errorMessage.indexOf("successful bind must be completed") != -1) {
                returnCode = USER_NOT_FOUND;
            } else if (errorMessage.indexOf("52e") != -1) {
                returnCode = INVALID_PASSWORD;
            } else if (errorMessage.indexOf("701") != -1 || errorMessage.indexOf("532") != -1 || errorMessage.indexOf("773") != -1) {
                returnCode = PASSWORD_EXPIRED;
            } else if (errorMessage.indexOf("533") != -1) {
                returnCode = USER_DISABLED;
            } else if (errorMessage.indexOf("775") != -1) {
                returnCode = USER_LOCKOUT;
            } else if (errorMessage.indexOf("530") != -1) {
                returnCode = LOGON_DENIED_AT_THIS_TIME;
            }
        }
    }
public DirContext connectToDirServer(String distinguishedName, String password) throws Exception {
        env.put(Context.SECURITY_PRINCIPAL, distinguishedName);
        env.put(Context.SECURITY_CREDENTIALS, password);
        return new InitialDirContext(env);
    }

2.我在客户处面临一个问题,如果在 LDAP(AD) 中找不到用户,它将返回状态代码为“INVALID_USERID_PASSWORD”而不是“USER_NOT_FOUND”。客户要求我提供以下信息

针对 ldap 服务器的应用程序的查询,或者换句话说,作为 ldap 查询传递的请求字符串是什么。 请参阅下面有关 LDAP 查询的一些信息。

您可以在此处参考示例的参考链接。

http://www.google.com/support/enterprise/static/postini/docs/admin/en/dss_admin/prep_ldap.html

如何继续,我没有找到有关如何使用这些查询的任何信息。使用上面的代码。

【问题讨论】:

    标签: java ldap


    【解决方案1】:

    当 BIND 请求中的条目不存在时,LDAP 目录服务器可能会以 invalid password 的结果代码进行响应。它可以防止攻击者知道条目是否存在。

    【讨论】:

    • 您好特里,在进一步调查问题后,我们发现客户已将服务器从 2003 升级到 2008 R2,这是唯一的变化,他们使用名为“NetScalar”的工具来测试 LDAP 查询在外部,它仍然返回为 USER_NOT_FOUND。当应用程序被使用时,它会抛出异常作为 INVALID USERID 密码。
    【解决方案2】:

    您可能需要以具有权利的人的身份进行绑定。

    我们在LDAP Wiki 上有一个样本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-03
      • 2011-09-23
      • 2017-01-09
      • 2015-05-06
      • 2018-05-31
      • 2015-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多