This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
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
It's not a secret anymore!