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();
}
}
------------------------------------------------------------
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();
}
}
------------------------------------------------------------
- duplicates
-
JDK-4894089 DN containing four backslashes in Java is retrieved with three backslashes
- Closed
- relates to
-
JDK-6201517 javax.naming.CompositeName and javax.naming.CompoundName handle escape character ('\') incorrectly.
- Closed