2

バインド操作後に Active Directory サーバーで検索を実行するコードがあります。バインディングに LDAP プロトコルを使用しており、コードは次のようになります。

    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");

    env.put(Context.SECURITY_AUTHENTICATION, "none");
    env.put("com.sun.jndi.ldap.read.timeout", "9000");
    env.put("com.sun.jndi.ldap.connect.timeout", "9000");

            env.put(Context.PROVIDER_URL, "ldap://" + "nec.jp");
            DirContext ctx = new InitialDirContext(env);
            NamingEnumeration<SearchResult> answer = ctx.search(
                        searchBase, searchFilter, searchCtls);
        if (answer.hasMore())
           {
                    env.put(Context.SECURITY_PRINCIPAL, principalNameres);
                    env.put(Context.SECURITY_CREDENTIALS, userPasswd);
                    env.put(Context.SECURITY_AUTHENTICATION, "simple");
                    final DirContext ctxForSerachedResult = new InitialDirContext(
                            env);
                    ctxForSerachedResult.close();

          }

ここでの問題は、匿名ログイン ユーザーで検索を実行するための AD サーバーの構成にあります。

これまでの理解によると、以下に示す手順を実行することで匿名を有効にすることができます。

を。DsHeuristics 属性値を変更して、匿名 LDAP 操作を有効にします。

b. ディレクトリを読み取るためのアクセス許可を提供します。

参照リンク:

以下の画像に示すように、LDP.exe バインドを使用して匿名ログインで Active Directory 設定を承認しようとしましたが、成功しました。

しかし、検索操作はまだ期待どおりに機能していません。

どこが間違っているのか教えてください。

4

2 に答える 2

1

あなたは明らかにあなたの部分的な断片だけを示しており、あなたは機能していないものを共有していません。

何を期待していますか。

匿名バインドではない場合でも役立つ可能性のあるJNDIのサンプルがあります。

于 2013-01-08T10:36:33.357 に答える
1

回答が遅れて投稿して申し訳ありません..以下に示すコードの変更はうまくいきました:)

       DirContext ctx = new InitialDirContext(env);

            final NamingEnumeration<SearchResult> answer = ctx.search(
                    searchBase, searchFilter, searchCtls);
            if (answer.hasMore()) {
                /*
                 * Retrieving providerUrl and principal from the answer
                 * returned after search
                 */
                if (bindAlgoValue.equals(BINDANONYMOUS)) {
                    env.put(Context.SECURITY_AUTHENTICATION, BINDSIMPLE);
                }
                final SearchResult res = answer.next();
                final String principalName = res.getNameInNamespace();
                final String providerUrl = res.getName();
                if (!res.isRelative()) {
                    env.put(Context.PROVIDER_URL, providerUrl);
                }
                env.put(Context.SECURITY_PRINCIPAL, principalName);
                env.put(Context.SECURITY_CREDENTIALS, userPasswd);
                ctx = new InitialDirContext(env);
                ctx.close();
                return true;
                // Code Fix End for BUG ID #1304
            }
于 2013-09-11T04:57:20.127 に答える