if you could please explain to me one piece of the following code that I don't quite understand I would be grateful:

What does (&(cn=*)({0}={1})) mean in the filter field?

I know that cn means search for the cn attribute and then ADD the result to ({0}={1}).

What is the meaning of ({0}={1})?

Here's the code:

try {
     // Create initial context
     ctx = new InitialDirContext(env);
     Attributes matchAttrs = new BasicAttributes(true);
     matchAttrs.put(new BasicAttribute(ldap_id_field, netid));

     String attlist[] = {ldap_email_field, ldap_givenname_field, 
            ldap_surname_field, ldap_phone_field};

    // look up attributes
      try {
      SearchControls ctls = new SearchControls();
     ctls.setReturningAttributes(attlist);
     NamingEnumeration answer = 
     ctx.search(ldap_search_context, "(&(cn=*)({0}={1}))", new Object[]  {ldap_id_field,netid},ctls);
     }
...
share|improve this question
up vote 1 down vote accepted

It looks wrong to me. All that filter does is find entries which have any CN and which match an attribute name/value pair specified as arguments to the search, in ldap_id_field and netid respectively. There is no 'adding' going on: the & means that both filter-expressions must match.

share|improve this answer
    
Yes, I see you are right. So, if the ldap_id_field is say uid and netid is user123, the search will look for attributes cn=* and will match {0}={1} for uid and user123 (that is, uid=user123). Is this correct? – Nick_K Jul 12 '13 at 9:54
    
I got it now. Thanx. You helped me understand. Accepted you answer – Nick_K Jul 12 '13 at 10:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.