2011-10-19 23 views
1

これは私のLDAPサーバーにAD情報を照会しようとする最初の試みです。私のLDAP構文が検索フィルターに間違っています

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

私の検索では検索されなかった2つのレコードに対して別々の検索を行い、それぞれに電子メールアドレスとuserAccountControlの値が512であったため、2つのレコードが欠落している理由はわかりません。

私は文法に間違ったことをしていますが、それが何であるかはわかりません。どのようなヘルプ/指示をいただければ幸いです。ありがとうございました。あなたがdisplayname属性とcn属性混乱するかもしれ

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; 
} 
+0

search()オーバーロードを調べても別のsearchArgsが必要になりますが、フィルタは '(&(objectClass = user)(displayname = {0} *)(mail = *) userAccountControl = 512)) '' {0}は最初のsearchArgを参照します。 – EJP

答えて

0

:下の私の完全な方法をご参照ください

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

:私のように検索フィルタを定義したグーグルの後

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-ディレクトリ:

User and computer Active-Directory

登録要求を右ブトン:

New request

検索をパーソナライズを選択し、あなたは共通の属性のためのヘルパーのタブを持っています:

helper tab for common attributes

あなたは二重の(& 1を必要としない(技術属性

personalized tab for technical attributes

あなたは結果のLDAPフィルタをコピー専用テストすることができるためにパーソナライズされたタブを選択することができます)は十分です:

Resulting LDAP filter

+0

返信いただきありがとうございます。しかし私は自分の問題を見つけ出し、同じ問題に遭遇する可能性がある他の人のために上に投稿しました。 – Melinda

0

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

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

+0

返信いただきありがとうございます。しかし私は自分の問題を見つけ出し、同じ問題に遭遇する可能性がある他の人のために上に投稿しました。 – Melinda

0

無料のADツールをダウンロードして、私が必要としていたすべてのADを表示しました。データが問題ではないことがわかりましたが、私は必要なすべてのOUを打っていませんでした。ユーザーが保存されます。

これで、もう少しグーグルで検索した後、LDAPに関するOracleサイトのページが見つかりました。このコンテキストのREFERRALを使用するだけでなく、ディレクトリ内の検索を行うためにLDAPContextをDirContextに変更し、 PartialSearchExceptionを回避します。

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

私が行った変更に欠点がある場合は、教えてください。よろしく。

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; 
} 

とにかく感謝:

は、ここに私の修正されたコードです。

関連する問題