File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Connection To Active Directory Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Connection To Active Directory Error" Watch "Connection To Active Directory Error" New topic

Connection To Active Directory Error

Rachana R

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

I am trying to connect to Active Directory thru the foll. code -

public class ADTestConnection {

public static void main(String[] args) {

Hashtable environment = new Hashtable();

environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

environment.put(Context.PROVIDER_URL, "ldap://HOST:9278/OU=***,DC=***,DC=**");
environment.put(Context.SECURITY_AUTHENTICATION, "simple");

environment.put(Context.SECURITY_PRINCIPAL, "TEST\\Administrator");

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


and I am getting the following error -

javax.naming.ServiceUnavailableException: host:9278; 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(

When I use port 389 I am able to connect successfully.

Please help me with your inputs regarding the same.

Thanks in Advance.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Welcome to JavaRanch!

We're pleased to have you here with us here on the ranch, but there are a few rules that need to be followed. One is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. Initials are OK for the first and middle names but not the last. You can change it here
[ November 07, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Rachana R

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

Please provide your inputs on the same as this is urgent for me.


I agree. Here's the link:
subject: Connection To Active Directory Error
It's not a secret anymore!