0

Id を使用して LDAP Active Directory からユーザー情報を取得したいと考えています。接続して取得しようとしているコードは次のとおりです。

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 の対応する値を返しません。

上記のフィルターに問題はありますか?周りの提案をいただければ幸いです。

4

1 に答える 1

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());
}
于 2011-11-09T05:09:00.167 に答える