1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| public class Create_User {
public void Create(String classFourni, String urlAD, String typeSecu, String userDN, String mdp, DirContext dc){
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, classFourni);
env.put(Context.PROVIDER_URL, urlAD);
env.put(Context.SECURITY_AUTHENTICATION, typeSecu);
env.put(Context.SECURITY_PRINCIPAL, userDN);
env.put(Context.SECURITY_CREDENTIALS, mdp);
try {
// Create the initial directory context
dc = new InitialDirContext(env);
// Prepare l'objet à créer
Attributes newAttributes = new BasicAttributes(true);
Attribute att = new BasicAttribute("description");
att.add(new BasicAttribute("objectClass", "User"));
att.add(new BasicAttribute("distinguishedName", userDN));
att.add(new BasicAttribute("givenName", "Guy"));
att.add(new BasicAttribute("sn", "Thomas"));
att.add(new BasicAttribute("userPrincipalName", "Guy@recb1.org"));
att.add(new BasicAttribute("sAMAccountName", "Guyt"));
newAttributes.put(att);
// Creation de l'objet
dc.bind("ou=user, dc=toto, dc=com", att);
// Fermeture du contexte
dc.close();
}
catch (Exception e) {
System.out.println("Erreur de création \n" + " Informations :" + e);
e.printStackTrace();
System.exit(-1);
}
}
} |
Partager