users@glassfish.java.net

LDAP errors under GF_v3, works fine in v2

From: John Wetherill <John.Wetherill_at_Sun.COM>
Date: Sat, 06 Sep 2008 05:09:35 -0700

I have a trivial servlet that runs fine in tomcat and GlassFish v2 but
crashes in v3 with a javax.naming.NotInContextException.


Here's the code in question:

   Hashtable ldapEnv = new Hashtable();
   ldapEnv.put(Context.SECURITY_PROTOCOL, "ssl");
   ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY,
"com.zzz.jndi.ldap.LdapCtxFactory");
   ldapEnv.put(Context.PROVIDER_URL, "ldap://ldap_server.zzz.com:636/");
   ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
   Attributes matchAttrs = new BasicAttributes(true);
   matchAttrs.put(new BasicAttribute("employeeNumber", "12345"));
   DirContext authLdapCtx = new InitialDirContext(ldapEnv);
// EXCEPTION OCCURS HERE:
   authLdapCtx.search("ou=people,dc=zzz,dc=com", matchAttrs);

Here's the exception:

javax.naming.NotContextException: Not an instance of DirContext
at javax.naming.directory.InitialDirContext.
     getURLOrDefaultInitDirCtx(InitialDirContext.java:92)
at javax.naming.directory.InitialDirContext.
     search(InitialDirContext.java:210)
at ConnectLdap.search(ConnectLdap.java:173)



The errors are occurring on GlassFish v3 on Mac OS X (v10.5.4) with
java version "1.6.0_04-dp". Works fine under GF v2 and tomcat.

I know gf3 is still not production-ready, but for a variety of reasons
I'd like to get my app running in it. Any hints on a workaround
appreciated.

Thanks,

John Wetherill