views:

23

answers:

1

I'm trying to search in a LDAP server all the users that have some profiles. 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?

A: 

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,

"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."

Your ldap query should be like,

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);
kalyan
I was hopping to avoid that, but it seems there is no other way. Thank you for your help!
Jose L Martinez-Avial