alen3
Messages postés49Date d'inscriptionmercredi 4 janvier 2012StatutMembreDernière intervention24 novembre 2012
-
1 mai 2012 à 10:11
5ou5a2012
Messages postés14Date d'inscriptionmercredi 22 décembre 2010StatutMembreDernière intervention23 juillet 2012
-
23 juil. 2012 à 14:33
salut,
je veux faire une class java qui va résuperer les utilisateurs depuis LDAP
et afficher en consoles les SN et mail
j'arrive à insérer un utilisateurs dans LDAP mais comme je dis je veux accéder à LDAP en mode lecture et parcourir tous les utilisateurs qui sont sous arborescence
com
example
le code d'insertion d'un nouveaux utilisateurs est :
import java.util.Hashtable;
import java.util.Properties;
import java.util.jar.Attributes;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
public class LdaTest{
public static void main(String[] args) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,"uid=admin,ou=system"); // specify the username
env.put(Context.SECURITY_CREDENTIALS,"secret");// specify the password
// TODO code application logic here
// entry's DN
String entryDN = "uid=newUser,dc=example,dc=com";
// entry's attributes
Attribute cn = new BasicAttribute("cn", "crestianao2");
Attribute sn = new BasicAttribute("sn", "ronaldino2");
Attribute mail = new BasicAttribute("mail", "crestiano2@yahoo.com");
Attribute phone = new BasicAttribute("telephoneNumber", "+1 222 333");
Attribute givenName = new BasicAttribute("givenName", "ronaldo");
Attribute userpassword = new BasicAttribute("userpassword", "crestiano");
Attribute oc = new BasicAttribute("objectClass");
oc.add("top");
oc.add("person");
oc.add("organizationalPerson");
oc.add("inetOrgPerson");
DirContext ctx = null;
try {
// get a handle to an Initial DirContext
ctx = new InitialDirContext(env);
// build the entry
BasicAttributes entry = new BasicAttributes();
entry.put(cn);
entry.put(givenName);
entry.put(sn);
entry.put(mail);
entry.put(phone);
entry.put(userpassword);
entry.put(oc);
entry.put(oc);
// Add the entry
ctx.createSubcontext(entryDN, entry);
// System.out.println( "AddUser: added entry " + entryDN + ".");
} catch (NamingException e) {
System.err.println("AddUser: error adding entry." + e);
}
}
}
5ou5a2012
Messages postés14Date d'inscriptionmercredi 22 décembre 2010StatutMembreDernière intervention23 juillet 2012 23 juil. 2012 à 14:33
Bonjour,
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,"uid=admin,ou=system"); // specify the username
env.put(Context.SECURITY_CREDENTIALS,"secret");// specify the password
DirContext contex= new InitialDirContext(env);
Au fait,je veux écrire ça dans un fichier de configuration standard(xml) et je veux créer une méthode qui fait appel à ce fichier pour établir la cnx
Merci d'avance,