The attached code demonstrates how a lookup using an invalid name (The VERY-BROKEN segment should be obvious) returns a result
instead of throwing an exception:
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
class LDAPTest
{
public static void main(String[] args)
{
// Identify service provider to use
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "
ldap://localhost:10389/");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
env.put(Context.SECURITY_CREDENTIALS, "secret");
try
{
// Create the initial directory context
DirContext ctx = new InitialDirContext(env);
DirContext ctx2 = (DirContext)ctx.lookup("ou=loadedLdifFiles,VERY-BROKEN=configuration,ou=system");
NamingEnumeration ne = ctx2.list("");
while (ne.hasMoreElements())
{
NameClassPair pair = (NameClassPair)ne.nextElement();
System.out.println("pair: "+pair.getName()+" == "+pair.getClassName());
}
ctx2.close();
ctx.close();
}
catch (NamingException e)
{
System.err.println("Exception: " + e);
e.printStackTrace();
}
}
}
Exception: javax.naming.NameNotFoundException: [LDAP: error code 32 - failed on search operation]; remaining name 'ou=loadedLdifFiles,VERY-BROKEN=configuration,ou=system'
The same is true for name "VERY-BROKEN=configuration,ou=system". For valid names (like "ou=system", the program prints out the entries below the given entry.
Do you use a special configuration, which is necessary to observe the problem?