1

これは、LDAP サーバーに AD 情報を照会する最初の試みです。LDAPサーバーにクエリを実行しようとしているときに、取得しようとしているのは次のとおりです。

表示名が「sav」で始まり、電子メール アドレスがあり、userAccountControl 属性が 512 である 500 レコードの countlimit を持つすべてのアクティブな従業員を取得しようとしています。私が遭遇している問題は、8 レコードしか取得できないことです。合計。文字通り、少なくとも 10 件のレコードを取得する必要があります。

検索で取得されなかった 2 つのレコードを個別に検索しましたが、それぞれにメール アドレスと userAccountControl の値が 512 ありました。したがって、これらの 2 つのレコードが欠落している理由がわかりません。

構文で何か間違ったことをしたと確信していますが、それが何であるかを見つけることができません。任意のヘルプ/指示をいただければ幸いです。ありがとうございました。

グーグルで検索した後、SEARCH FILTER を次のように定義しました。

String searchFilter = "(&(objectClass=user)(displayname="+displayname+"*"+")(mail=*)(userAccountControl=512))";

以下の完全な方法を参照してください。

public List<String> getAutocompleteEmpRecordsList(String displayname, LdapContext ctx) {
    List<String> activeEmpAttributes = new ArrayList<String>();
    Attributes attrs = null;
    int count = 0;
    int empEmailAddrLen = 0;
    try {
        SearchControls constraints = new SearchControls();
        constraints.setCountLimit(500);          
        constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
        String[] attrIDs = {"displayname", "mail", "userAccountControl"};
        constraints.setReturningAttributes(attrIDs);
        String searchFilter = "(&(objectClass=user)(displayname="+displayname+"*"+")(mail=*)(userAccountControl=512))";
        NamingEnumeration answer = ctx.search("OU=Standard,OU=Users,DC=xxx,DC=org", searchFilter, constraints);
        if (answer != null) {
            while (answer.hasMore()) {
                attrs = ((SearchResult) answer.next()).getAttributes();
                if (attrs.get("displayname") != null) {
                    int empNameLen = attrs.get("displayname").toString().length();
                    activeEmpAttributes.add(attrs.get("displayname").toString().substring(13, empNameLen));
                }
                count++;
                ctx.close();
            }
        }
        else {
            throw new Exception("Invalid User");
        }
        System.out.println("activeEmpAttributes: " + activeEmpAttributes);
        System.out.println("count: " + activeEmpAttributes.size());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return activeEmpAttributes;
}
4

3 に答える 3

0

displayname属性と属性を混同している可能性がありcnます。

Windows サーバーには、フィルターをテストできる LDIDIFDE.EXE というコマンド ライン ツールがあります。

ldifde -f datas.ldf -d "OU=Standard,OU=THR Users,DC=txhealth,DC=org" -r "(&(objectClass=user)(displayname=sav*)(mail=*)(userAccountControl=512))"
ldifde -f datas.ldf -d "OU=Standard,OU=THR Users,DC=txhealth,DC=org" -r "(&(objectClass=user)(cn=sav*)(mail=*)(userAccountControl=512))"

ユーザーとコンピューターの MMC では、フィルターをテストすることもできます。

ユーザーとコンピューターの Active-Directory を開始します。

ユーザーとコンピューターのアクティブ ディレクトリ

登録済みリクエストの右ボタン:

新しいリクエスト

パーソナライズ検索を選択すると、一般的な属性のヘルパー タブが表示されます。

共通属性のヘルパー タブ

技術属性のパーソナライズされたタブを選択できます

技術属性のパーソナライズされたタブ

結果の LDAP フィルターをコピーしてテストできます (ダブルは必要ありません(& 1 つで十分です):

結果の LDAP フィルタ

于 2011-10-20T03:49:11.083 に答える
0

除外された 2 人のユーザーの userAccountControl、displayName、およびメールの値を投稿できますか?

タプルインデックスを追加すると、displayNameの内側の検索がはるかに高速に実行されます。

于 2011-10-21T02:05:48.367 に答える
0

無料の AD ツールをダウンロードして必要なすべての AD を表示したところ、データに問題はないことがわかりましたが、すべてのユーザーが保存されている OU が 1 つだけではないため、必要なすべての OU にヒットしていませんでした。 .

その結果、さらにグーグルで調べた後、Oracle サイトで LDAP に関するページを見つけ、LDAPContext を DirContext に変更して、接続がディレクトリ内で検索を行うようにし、このコンテキストの REFERRAL を使用して値を「フォロー」に設定しました。部分検索例外。

他の初心者が同じ問題に遭遇した場合に備えて、調査結果を投稿すると思いました。

私が行った変更にマイナス面がある場合は、お知らせください。よろしく。

これが私の修正されたコードです:

public List<String> getAutocompleteEmpRecordsList(String displayname, DirContext ctx) {
    List<String> activeEmpAttributes = new ArrayList<String>();
    Attributes attrs = null;
    int count = 0;
    int empEmailAddrLen = 0;
    try {
        SearchControls constraints = new SearchControls();
        constraints.setCountLimit(500); 
        constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
        String[] attrIDs = {"displayname", "mail", "userAccountControl"};
        constraints.setReturningAttributes(attrIDs);
        String searchFilter = "(&(objectClass=user)(displayname="+displayname.trim()+"*"+")(mail=*)(userAccountControl=512))";
        NamingEnumeration answer = ctx.search("DC=xxx,DC=org", searchFilter, constraints);
        if (answer != null) {
            while (answer.hasMore()) {
                attrs = ((SearchResult) answer.next()).getAttributes();
                if (attrs.get("displayname") != null) {
                    int empNameLen = attrs.get("displayname").toString().length();
                    activeEmpAttributes.add(attrs.get("displayname").toString().substring(13, empNameLen));
                }
                count++;
                ctx.close();
            }
        }
        else {
            throw new Exception("Invalid User");
        }
        System.out.println("activeEmpAttributes: " + activeEmpAttributes);
        System.out.println("count: " + activeEmpAttributes.size());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return activeEmpAttributes;
}

とにかくありがとう。

于 2011-10-21T10:05:23.033 に答える