JND InvalidSearchFilterException-如何在LDAP中搜索规范名称?

时间:2019-05-15 12:31:11

标签: java powershell

我正在尝试通过JND将Active Directory中设置的电子邮件地址检索为指定的规范名称。我之前尝试过使用其他参数(例如sAMAccountName,主体名称或邮件)进行相同的过程,但这一次,它不起作用。

initializeLDAP();
String searchFilter = "(&(objectClass=user)(canonicalName=" + name + "))";
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String returnedAttributes[] = { "mail" };
searchControls.setReturningAttributes(returnedAttributes);
NamingEnumeration<SearchResult> results = ctx.search(ldapSearchBase, searchFilter, searchControls);
SearchResult searchResult = null;
searchResult = results.nextElement();

if (searchResult.getAttributes().get("mail") != null
                    && searchResult.getAttributes().get("mail").get() != null) {
    logger.info("mail to canonical name {} is {}", name,
    searchResult.getAttributes().get("mail").get());
                mail = (String) 

searchResult.getAttributes().get("mail").get();
   ...}

在此行NamingEnumeration<SearchResult> results = ctx.search(ldapSearchBase, searchFilter, searchControls);上出现以下异常

javax.naming.directory.InvalidSearchFilterException: [LDAP: error code 18 - 0000216B: AtrErr: DSID-031404E3, #1:
    0: 0000216B: DSID-031404E3, problem 1004 (WRONG_MATCH_OPER), data 0, Att 90394 (canonicalName)

我宁愿搜索其他参数,但不幸的是,规范名称是我从powershell脚本输出中获得的所有名称。那么还有另一种搜索方式吗?

1 个答案:

答案 0 :(得分:0)

没关系。

我读到规范名称是一个组合属性,因此也不可搜索。 我在最后一个var sampleArray = [ ["100,101,102"], ["200,201,202"], ["300,301,302"] ]; sampleArray = sampleArray.flat(); var newArray = []; sampleArray.forEach(data=>newArray.push(...data.split(","))); console.log(newArray)之后剪切了规范的名称字符串,并用它来搜索/,它很好用。