Hot Downloads

Welcome, Guest
Username: Password: Remember me

TOPIC: JAVA and LDAP

JAVA and LDAP 10 years 10 months ago #12867

Operating system: Windows XP
Problem: I want to connect to an LDAP.
Errors : Connexion passée
Exception in thread "main" Search......
y.moufak
answer
o=hcz.ma,uid=y.moufak
javax.naming.NamingException: [LDAP: error code 1 - 00000000: LdapErr: DSID-0C0905FF, comment: In order to perform
this operation a successful bind must be completed on the connection., data 0, vece

Code of aplication :

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.*;
public class LdapClient {
//Connéxion avec l'annuaire LDAP***********************************************************
private DirContext context;
public LdapClient() throws NamingException
{
context = getContext();
}
private DirContext getContext() throws NamingException
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://192.168.1.251/");
env.put(Context.SECURITY_AUTHENTICATION, "none");
System.out.println("Connexion passée");
return new InitialDirContext(env);
}
//Fin de Connéxion*************************************************************************

//Récupérer les informations d'un utilisateur**********************************************
public Attributes getUserAttributes(String username)
throws NamingException
{
System.out.println("Search......");
SearchControls ctls = new SearchControls();
String filter = "uid=" + username;
System.out.println(username);
NamingEnumeration answer;
System.out.println("answer");
String Name = "o=hcz.ma,uid=y.moufak";
System.out.println(Name);
answer = context.search(Name, filter, ctls);
System.out.println(filter);
System.out.println(answer);
while (answer != null && answer.hasMoreElements())
{
SearchResult sr = (SearchResult) answer.next();
return sr.getAttributes();
}
throw new RuntimeException();
}
//Fin de la récuperation*******************************************************************

public static void main(String[] args) throws NamingException
{
//String username = args[0];
//String password = args[1];
LdapClient ldap = new LdapClient();

System.out.println("User : " + ldap.getUserAttributes("y.moufak"));

}
}
The administrator has disabled public write access.

Re: JAVA and LDAP 10 years 10 months ago #12877

  • drizzle
  • drizzle's Avatar
  • Offline
  • Distinguished Member
  • Posts: 138
  • Karma: 0
From the output, it looks like you are not binding to your LDAP server. What java app are you using? What LDAP server are you using. They all speak differently. Are you binding to OpenLDAP, Fedora/Netscape Directory Server, eDirectory, Active Directory (which can really be a pain)?

Drew
The administrator has disabled public write access.

Post 10 years 10 months ago #12881

I post to an active directory. i develop with eclipse.
Problem : The connection bind , but on the level of research I cannot.
The administrator has disabled public write access.
Time to create page: 0.077 seconds

CCENT/CCNA

Cisco Routers

  • SSL WebVPN
  • Securing Routers
  • Policy Based Routing
  • Router on-a-Stick

VPN Security

  • Understand DMVPN
  • GRE/IPSec Configuration
  • Site-to-Site IPSec VPN
  • IPSec Modes

Cisco Help

  • VPN Client Windows 8
  • VPN Client Windows 7
  • CCP Display Problem
  • Cisco Support App.

Windows 2012

  • New Features
  • Licensing
  • Hyper-V / VDI
  • Install Hyper-V

Linux

  • File Permissions
  • Webmin
  • Groups - Users
  • Samba Setup