| Author |
NoInitialContextException
|
John Eric Hamacher
Ranch Hand
Joined: Apr 25, 2007
Posts: 230
|
|
Hello: I get the following stack trace: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247) at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284) at javax.naming.directory.InitialDirContext.getURLOrDefaultInitDirCtx(InitialDirContext.java:87) at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:210) at com.enetrix.sis.jaas.LDAPLoginModule.validate(LDAPLoginModule.java:387) at com.enetrix.sis.jaas.LDAPLoginModule.login(LDAPLoginModule.java:132) . . . Here is my code: DirContext authContext = null; Hashtable authEnv = new Hashtable(); String dn = user; authEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); authEnv.put(Context.PROVIDER_URL, "ldap://192.168.132.20:389"); authEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); authEnv.put(Context.SECURITY_PRINCIPAL, dn); authEnv.put(Context.SECURITY_CREDENTIALS, password); try { authContext = new InitialDirContext(authEnv); if (debug) { logger.debug("LDAP authentication passed."); } authContext.close(); } catch (AuthenticationException authEx) { if (debug) { logger.debug("LDAP authentication failed."); } throw new LoginException("Invalid Username or Password"); } catch (NamingException namEx) { if (debug) { logger.debug("JNDI error"); } throw new LoginException("JNDI error"); } Attributes matchAttrs = new BasicAttributes(true); matchAttrs.put(new BasicAttribute("samAccountName", dn)); // ERROR OCCURS HERE: NamingEnumeration answer = authContext.search("DC=Enetrix", matchAttrs); while (answer.hasMore()) { SearchResult sr = (SearchResult)answer.next(); System.out.println(">>>" + sr.getName()); } Any ideas?
|
 |
John Eric Hamacher
Ranch Hand
Joined: Apr 25, 2007
Posts: 230
|
|
|
Never mind. I was closing my context!
|
 |
 |
|
|
subject: NoInitialContextException
|
|
|