【发布时间】:2019-07-23 09:55:21
【问题描述】:
我想使用 SQL 中的“IN”运算符来编写 LDAP 查询。
例如:如果我有一个名为“NameList”的名称列表,我会编写以下 SQL 查询
SELECT * FROM TABLENAME WHERE NAME IN "NameList"
我该如何编写类似的 LDAP 查询?
public static final String[] LDAP_ATTRIBUTE_IDS = {"displayName"};
LdapContext ldapContext = new InitialLdapContext(env, null); \\env has all
\\connection details
List NameList = new ArrayList<String>();
NameList.add("ABC");
NameList.add("XYZ");
NameList.add("LMN");
NamingEnumeration namingEnumeration = ldapContext.search("",
"(&(objectCategory=person)(objectclass=user)(|(sAMAccountName=XYZ)(sAMAccountName=LMN)(sAMAccountName=ABC)))", getSearchControls());
Attributes attrs = ((SearchResult) namingEnumeration.next()).getAttributes();
String value = attrs.get(LDAP_ATTRIBUTE_IDS);
而不是使用“|”添加 XYZ、LMN 和 ABC运算符 我想知道 NameList 是否可以与“IN”运算符一起使用。
【问题讨论】:
标签: sql ldap spring-ldap ldap-query