Search code examples
javaldapjndi

Java, LDAP, ADAM - How do I create a container with a forward slash in the name


I am having trouble writing some Java code, which will create a container/folder in ADAM, where the container name and distinughed name contain a forward slash.
e.g.
cn=test/test
dn=CN=test/test,CN=TestStore,DC=MyCompany,DC=COM

LdapContext _ctx = getNewContext(valid_userName, valid_userName, valid_userName);
  // uses InitialLdapContext under the hood 

String containerDN = "dn=CN=test/test,CN=TestStore,DC=MyCompany,DC=COM"
_ctx.createSubcontext(containerDN, attrs); // assume attrs is valid javax.naming.directory.Attributes

I am struggling to escpae the forward slash from the Java String object, and yet allow the InitialLdapContext to create the container with the name.

FRom the ADAM Adsi Edit application, I can create folders with forward slashes, so I presume the process can be done from code as well.

Many thanks in advance ...


Solution

  • Re-reading the JavaDocs API for LDAPContext, and DirContext ... an overloaded method createSubContext() offers:

    public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException
    

    the Name interface, concrete class CompositeName handles the escaping/un-escaping of special characters for me ...

    many thanks JRL !