Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-32

LDAP: InitialDirContext.search() method doesn't accecpt url included name parameter

    XMLWordPrintable

Details

    • Bug
    • Resolution: Obsolete
    • Minor
    • None
    • 6.1.0.GA
    • Security
    • Compatibility/Configuration
    • Workaround Exists
    • Hide

      To workaround the issue:
      Change the line:
      String base = "ldap://192.168.0.1:389/dc=sample,dc=com";

      To
      String base = "dc=sample,dc=com";

      By removing url part, search() method will work with the name string.

      Show
      To workaround the issue: Change the line: String base = "ldap://192.168.0.1:389/dc=sample,dc=com"; To String base = "dc=sample,dc=com"; By removing url part, search() method will work with the name string.
    • Hide

      How reproducible:

      The source code snippet below can be used to reproduce this issue:

      =============================================================
      Hashtable env = new Hashtable();
      env.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory");
      env.put("java.naming.security.authentication", "simple");
      env.put("java.naming.ldap.version", "3");
      env.put("java.naming.referral", "ignore");
      env.put("java.naming.ldap.derefAliases", "never");
      env.put("java.naming.provider.url", "ldap://192.168.0.1:389");
      env.put("java.naming.factory.url.pkgs", "org.jboss.as.naming.interfaces:org.jboss.ejb.client.naming");

      SearchControls ctl = null;
      String attrArr[] = new String[1];
      attrArr[0] = "objectclass";
      ctl = new SearchControls(2, 0L, 0, attrArr, false, false);

      String base = "ldap://192.168.0.1:389/dc=sample,dc=com";
      String filter = "(uid=sample@sample.com)";

      NamingEnumeration nenum = null;
      DirContext ictx = null;

      try

      { ictx = new InitialDirContext(env); nenum = ictx.search(base, filter, ctl); // <====== issue occurs on this line return "SUCCESS"; }

      catch(NamingException ne1)

      { ne1.printStackTrace(); }

      =============================================================

      Actual results:

      Below exception will be thrown:
      09:31:57,377 ERROR [stderr] (http-/192.168.0.2:8080-1) javax.naming.InvalidNameException: ldap:: [LDAP: error code 34 - Invalid DN Syntax]; remaining name 'ldap://192.168.0.1:389/dc=sample,dc=com'
      09:31:57,377 ERROR [stderr] (http-/192.168.0.2:8080-1) at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
      09:31:57,378 ERROR [stderr] (http-/192.168.0.2:8080-1) at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
      09:31:57,378 ERROR [stderr] (http-/192.168.0.2:8080-1) at com.sun.jndi.ldap.LdapCtx.c_lookup(Unknown Source)
      09:31:57,378 ERROR [stderr] (http-/192.168.0.2:8080-1) at com.sun.jndi.toolkit.ctx.ComponentContext.c_resolveIntermediate_nns(Unknown Source)
      09:31:57,378 ERROR [stderr] (http-/192.168.0.2:8080-1) at com.sun.jndi.toolkit.ctx.AtomicContext.c_resolveIntermediate_nns(Unknown Source)

      To workaround the issue:
      Change the line:
      String base = "ldap://192.168.0.1:389/dc=sample,dc=com";

      To
      String base = "dc=sample,dc=com";

      By removing url part, search() method will work with the name string.

      Expected results:

      NamingEnumeration object returned, even if using "ldap://192.168.0.1:389/dc=sample,dc=com" as name parameter.

      Show
      How reproducible: The source code snippet below can be used to reproduce this issue: ============================================================= Hashtable env = new Hashtable(); env.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory"); env.put("java.naming.security.authentication", "simple"); env.put("java.naming.ldap.version", "3"); env.put("java.naming.referral", "ignore"); env.put("java.naming.ldap.derefAliases", "never"); env.put("java.naming.provider.url", "ldap://192.168.0.1:389"); env.put("java.naming.factory.url.pkgs", "org.jboss.as.naming.interfaces:org.jboss.ejb.client.naming"); SearchControls ctl = null; String attrArr[] = new String [1] ; attrArr [0] = "objectclass"; ctl = new SearchControls(2, 0L, 0, attrArr, false, false); String base = "ldap://192.168.0.1:389/dc=sample,dc=com"; String filter = "(uid=sample@sample.com)"; NamingEnumeration nenum = null; DirContext ictx = null; try { ictx = new InitialDirContext(env); nenum = ictx.search(base, filter, ctl); // <====== issue occurs on this line return "SUCCESS"; } catch(NamingException ne1) { ne1.printStackTrace(); } ============================================================= Actual results: Below exception will be thrown: 09:31:57,377 ERROR [stderr] (http-/192.168.0.2:8080-1) javax.naming.InvalidNameException: ldap:: [LDAP: error code 34 - Invalid DN Syntax] ; remaining name 'ldap://192.168.0.1:389/dc=sample,dc=com' 09:31:57,377 ERROR [stderr] (http-/192.168.0.2:8080-1) at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source) 09:31:57,378 ERROR [stderr] (http-/192.168.0.2:8080-1) at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source) 09:31:57,378 ERROR [stderr] (http-/192.168.0.2:8080-1) at com.sun.jndi.ldap.LdapCtx.c_lookup(Unknown Source) 09:31:57,378 ERROR [stderr] (http-/192.168.0.2:8080-1) at com.sun.jndi.toolkit.ctx.ComponentContext.c_resolveIntermediate_nns(Unknown Source) 09:31:57,378 ERROR [stderr] (http-/192.168.0.2:8080-1) at com.sun.jndi.toolkit.ctx.AtomicContext.c_resolveIntermediate_nns(Unknown Source) To workaround the issue: Change the line: String base = "ldap://192.168.0.1:389/dc=sample,dc=com"; To String base = "dc=sample,dc=com"; By removing url part, search() method will work with the name string. Expected results: NamingEnumeration object returned, even if using "ldap://192.168.0.1:389/dc=sample,dc=com" as name parameter.

    Description

      Description of problem:

      When trying to use InitialDirContext.search(String name, String filter, SearchControls cons) method to search LDAP server, if the first "name" parameter includes url and port number, an javax.naming.InvalidNameException exception will be thrown. This issue only happens in EAP 6, same source code works fine in either EAP 5 or as standalone Java client.

      Additional info:

      From the official "The JNDI Tutorial", names with url should be supported.
      http://docs.oracle.com/javase/jndi/tutorial/ldap/misc/url.html

      Attachments

        Activity

          People

            Unassigned Unassigned
            rhn-support-lywang Lyle Wang (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: