File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Blatant Advertising and the fly likes Connectionto Acitve directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Blatant Advertising
Bookmark "Connectionto Acitve directory" Watch "Connectionto Acitve directory" New topic

Connectionto Acitve directory

Rachana R

Joined: Oct 31, 2008
Posts: 3
Hello All,

I am using the following class for connection to AD.

public class ADTestConnection {

public static void main(String[] args) {

Hashtable environment = new Hashtable();
String myPassword = "set00wave";

environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
// environment.put(Context.PROVIDER_URL, "ldap://" + myActiveDirectoryServer + ":389");//389

environment.put(Context.SECURITY_AUTHENTICATION, "simple");
// environment.put(Context.SECURITY_PRINCIPAL, "CN=" + myUser + ",CN=Users,DC=" + myDomain + ",DC=COM");

environment.put(Context.SECURITY_CREDENTIALS, "mypassword");
DirContext context = new InitialDirContext(environment);
System.out.println("Connection Successful!!");
catch (NamingException e)


After exectuion I am getting the following error -

javax.naming.ServiceUnavailableException: [url] socket closed
at com.sun.jndi.ldap.Connection.readReply(
at com.sun.jndi.ldap.LdapClient.ldapBind(
at com.sun.jndi.ldap.LdapClient.authenticate(
at com.sun.jndi.ldap.LdapCtx.connect(
at com.sun.jndi.ldap.LdapCtx.<init>(
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(
at javax.naming.spi.NamingManager.getInitialContext(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.init(
at javax.naming.InitialContext.<init>(
at com.geam.ADTestConnection.main(
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
It's probably because you're not telling it which server to connect to.

I agree. Here's the link:
subject: Connectionto Acitve directory
jQuery in Action, 3rd edition