• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LDAP server Access Error in java

 
Divya Mehrotra
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to access ldap server from java. I am giving following properties :-

Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.PROVIDER_URL, "ldap://morganstanley.com:/");

//My ldap server is using SASL security authentication mechanism.
env.put(Context.SECURITY_AUTHENTICATION,"sasl_mech");

env.putContext.SECURITY_PRINCIPAL,"cn=Manager,ou=People,o=organizationalunit"); // specify the username

env.put(Context.SECURITY_CREDENTIALS,"morganstanley"); // specify the password

try
{
// Create initial context

DirContext ctx = new InitialDirContext(env);
//Specify the attributes to match
Attributes matchAttrs = new BasicAttributes(true);
//ignore case
matchAttrs.put(new BasicAttribute("ou", "People"));
//Search for objects that have those matching attributes
NamingEnumeration answer = ctx.search("ou=users", matchAttrs);
//Print the answer
ldap.printSearchEnumeration(answer,ctx);

//Close the context when we're done
ctx.close();
}

But I am getting the following exception at runtime in the following line
DirContext ctx = new InitialDirContext(env);


javax.naming.CommunicationException: morganstanley.com:389. Root exception is java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:331)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:196)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.connect(Socket.java:428)
at java.net.Socket.<init>(Socket.java:335)
at java.net.Socket.<init>(Socket.java:150)
at com.sun.jndi.ldap.Connection.createSocket(Connection.java:376)
at com.sun.jndi.ldap.Connection.<init>(Connection.java:211)
at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:136)
at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1685)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2616)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:307)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:190)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:208)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:151)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:81)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:675)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:257)
at javax.naming.InitialContext.init(InitialContext.java:233)
at javax.naming.InitialContext.<init>(InitialContext.java:209)
at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:94)
at com.user.ldap.main(ldap.java:45) // This is my class name.


Please help me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic