简体   繁体   English

具有多个参数的DirContext搜索数组

[英]DirContext search array with multiple parameters

I'm trying to search in a LDAP server all the users that have some profiles. 我正在尝试在LDAP服务器中搜索具有某些配置文件的所有用户。 So far I'm able to get all the users with a profile, but I'm unable to do the same with multiples roles. 到目前为止,我可以为所有用户提供个人资料,但是我无法对多个角色执行相同的操作。 So the following code works 所以以下代码有效

[...]
filterExpr = "(&(objectclass=person)(memberOf={0}))";
String rol = "myRol";
Object parameters[] ={rol};
context.search(distinguishedName, filterExpr, parameters, controls);

but the following code does not 但以下代码不

filterExpr = "(&(objectclass=person)(memberOf={0}))";
String rol = "myRol";
String roles[] = {rol};
Object parameters[] ={roles};
context.search(distinguishedName, filterExpr, parameters, controls);

It also doesn't work if there are more than one rol in the array. 如果阵列中的角色不止一个,则它也不起作用。 What am I doing wrong? 我究竟做错了什么?

The object array can only contain list of strings or array of bytes. 对象数组只能包含字符串列表或字节数组。 Remaining else will be converted to string. 其余的将转换为字符串。 In your second example the first object is array of strings. 在第二个示例中,第一个对象是字符串数组。 Most likely the array reference will be converted to string and filter will be made out of it. 最有可能将数组引用转换为字符串,并从中进行过滤。

Have a look at the api, it says, 看一下它的api,

"Objects that are neither a String nor a byte[] are converted to their string form via Object.toString() and then the rules for String apply." “既不是String也不是byte []的对象将通过Object.toString()转换为其字符串形式,然后适用String的规则。”

Your ldap query should be like, 您的ldap查询应该像

filterExpr = "(&(objectclass=person)(|(memberOf={0})(memberOf={1})(memberOf={2})))";
String rol1 = "myRol1";
String rol2 = "myRol2";
String rol3 = "myRol3";
Object parameters[] ={rol1, rol2, rol3);
context.search(distinguishedName, filterExpr, parameters, controls);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM