Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6201615

LDAP Service Provider does not parse LDAP names with escape characters ('\') properly.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Duplicate
    • Affects Version/s: 1.4.2
    • Fix Version/s: None
    • Component/s: core-libs

      Description

      2004/11/30 18:00 ###@###.### --
      If a LDAP entry has a DN with a sequence of escape characters, calls to search() from javax.naming.directory.InitialDirContext do not return the correct number of '\' characters. For example, if we have an entry like "cn=A:\\TestA", the name of the binding in that name space will appear "A:\\\TestA". If the entry RDN contains three '\' characters, the binding name will contain two extra '\'s. It seems that for N proper '\' characters in a RDN, there will be N - 1 '\' characters in the binding name. The problem may lie in the name parser.

      Below is the test program (also attached to this bug).

      ------------------------------------------------------------
      import com.sun.jndi.ldap.LdapName; // for v1.4.2 and v1.5.0
      import java.util.*;
      import javax.naming.*;
      import javax.naming.directory.*;
      //import javax.naming.ldap.LdapName; // for v1.5.0 only

      public class SearchTest {
          public static void main(String[] argumentList) throws NamingException {
              Attribute attribute = null;
      Hashtable environment = new Hashtable();
              InitialDirContext initialContext = null;
              NamingEnumeration attributeEnumeration = null;
              NamingEnumeration attributesEnumeration = null;
              NamingEnumeration bindingsEnumeration = null;
              NamingEnumeration resultsEnumeration = null;
              SearchResult result = null;

              environment.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.sun.jndi.ldap.LdapCtxFactory");
              environment.put(Context.PROVIDER_URL,
                "ldap://sb150-a.aus.sun.com:389/o=testRoot");
              environment.put(Context.SECURITY_PRINCIPAL,
                "cn=Directory Manager");
              environment.put(Context.SECURITY_CREDENTIALS,
                "dirmanager");

              initialContext = new InitialDirContext(environment);

              if (argumentList.length > 0 && argumentList[0].compareToIgnoreCase("add") == 0) {
                  Attributes attrs = new BasicAttributes();
                  Name oracle = new LdapName("cn=O:\\\\Oracle,cn=OracleContext");

                  attrs.put(new BasicAttribute("objectClass", "top"));
                  attrs.put(new BasicAttribute("objectClass", "person"));
                  attrs.put(new BasicAttribute("cn", "O:\\\\Oracle"));
                  attrs.put(new BasicAttribute("sn", "O:\\\\Oracle"));

                  initialContext.createSubcontext(oracle, attrs);

                  System.out.println("\nsuccessfully added cn=O:\\\\Oracle!\n");
              }

              for (bindingsEnumeration = initialContext.listBindings("cn=OracleContext"); bindingsEnumeration.hasMoreElements(); ) {
                  System.out.println("binding: " + ((Binding)bindingsEnumeration.nextElement()).toString());
              }
              System.out.println();
              bindingsEnumeration.close();

              for (resultsEnumeration = initialContext.search("cn=OracleContext", "cn=*", null); resultsEnumeration.hasMoreElements(); ) {
                  result = (SearchResult)resultsEnumeration.nextElement();

                  System.out.println(" [search found name: " + result.getName() + "]");

                  for (attributesEnumeration = (result.getAttributes()).getAll(); attributesEnumeration.hasMoreElements(); ) {
                      attribute = (Attribute)attributesEnumeration.nextElement();

                      for (attributeEnumeration = attribute.getAll(); attributeEnumeration.hasMoreElements(); ) {
                          System.out.println("\t" + attribute.getID() + " : " + attributeEnumeration.nextElement());
                      }
                      attributeEnumeration.close();
                  }
                  attributesEnumeration.close();
              }
              System.out.println();
              resultsEnumeration.close();

              initialContext.close();
          }
      }
      ------------------------------------------------------------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sseligmasunw Scott Seligman (Inactive)
              Reporter:
              jhjohnst Jian Johnston (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: