- Posts: 2
- Thank you received: 0
JAVA and LDAP
- influencia
- Topic Author
- Offline
- New Member
Less
More
18 years 9 months ago #12867
by influencia
JAVA and LDAP was created by influencia
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"));
}
}
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"));
}
}
18 years 9 months ago #12877
by drizzle
Replied by drizzle on topic Re: JAVA and LDAP
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
Drew
- influencia
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
18 years 9 months ago #12881
by influencia
Replied by influencia on topic Post
I post to an active directory. i develop with eclipse.
Problem : The connection bind , but on the level of research I cannot.
Problem : The connection bind , but on the level of research I cannot.
Time to create page: 0.118 seconds