Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

NoInitialContextException

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind. I was closing my context!
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic