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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown


Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.getURLOrDefaultInitCtx(
at com.enetrix.sis.jaas.LDAPLoginModule.validate(
at com.enetrix.sis.jaas.LDAPLoginModule.login(
. . .

Here is my code:

DirContext authContext = null;

Hashtable authEnv = new Hashtable();
String dn = user;

authEnv.put(Context.PROVIDER_URL, "ldap://";);
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.");
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));

NamingEnumeration answer ="DC=Enetrix", matchAttrs);

while (answer.hasMore()) {
SearchResult sr = (SearchResult);
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