2011-11-08 10 views
0

IDを使用してLDAP Active Directoryからユーザー情報を取得したいとします。 ここにコードを接続して取得しようとしています。IDを使用してLDAPアクティブディレクトリからデータを取得していますか?

SearchControls ctls = new SearchControls(); 
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); 
NamingEnumeration results = ctx.search("DC=erieinsurance,DC=com", "(&(objectCategory=user)(name{0}))", 
        new Object[]{Id}, // filter arguments 
       ctls); // search controls 
      } 
if (results.hasMoreElements()) { 

} 

givennameとsnの対応する値は返されません。

上記のフィルタに問題はありますか? ご意見はお寄せいただければ幸いです。

答えて

0

JNDIを使用しているようです。ここで

が小さいサンプルは、返信用

//Create the initial directory context 
LdapContext ctx = new InitialLdapContext(env,null); 

//Create the search controls 
SearchControls ctls = new SearchControls(); 

//Specify the attributes to return 
String returnedAtts[]={"distinguishedName","CN","sAMAccountName"}; 
ctls.setReturningAttributes(returnedAtts); 

//Specify the search scope 
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); 

//specify the LDAP search filter 
String searchFilter = "(&(objectClass=user)(sAMAccountName="+ theUserToCheck +"))"; 

//Specify the Base for the search 
String searchBase = "DC=erieinsurance,DC=com"; 

//initialize counter to total the results 
int totalResults = 0; 

//Search for objects using the filter 
NamingEnumeration answer = ctx.search(searchBase, searchFilter, ctls); 

//Loop through the search results 
while (answer.hasMoreElements()) { 
    SearchResult sr = (SearchResult)answer.next(); 
    totalResults++; 
    System.out.println(totalResults + ". " + sr.getName().toString()); 
} 
+0

おかげで...はい、私たちは、JNDIを使用しています。検索パラメータIDが別のパラメータにマップされたので、今度は 'CN'にマップされています..そのため、作業中です... –

+0

"theUserToCheck"はLDAPフィルタインジェクションに脆弱です。誰かがtheUserToCheck = "*)(otherAttr = otherValue" –

関連する問題