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
| public void ajout() {
Hashtable<String, String> env =new Hashtable<String, String>();
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, "cn=Manager,dc=my-domain,dc=com");
env.put(Context.SECURITY_CREDENTIALS, "secret");
BasicAttributes attrs =new BasicAttributes("cn","P11");
BasicAttribute att0= new BasicAttribute("objectClass","top");
BasicAttribute att1= new BasicAttribute("sn","nomdefamille");
BasicAttribute att2= new BasicAttribute("mail","inconnu@gmail.com");
BasicAttribute att3= new BasicAttribute("givenName","prenom");
BasicAttribute att4= new BasicAttribute("postalCode","69699");
BasicAttribute att5= new BasicAttribute("homePhone","05696969");
BasicAttribute att6= new BasicAttribute("mobile","07696969");
BasicAttribute att7= new BasicAttribute("userPassword","secret");
att0.add("inetOrgPerson");
attrs.put(att0);
attrs.put(att1);
attrs.put(att2);
attrs.put(att3);
attrs.put(att4);
attrs.put(att5);
attrs.put(att6);
attrs.put(att7);
try {
DirContext ctx = new InitialDirContext(env);
ctx.createSubcontext("cn=P11,ou=Personne,o=Entreprise,dc=my-domain,dc=com",attrs);
System.out.println("Ajout psartek");
} catch (NamingException e) {
System.err.println("Erreur de co");
e.printStackTrace();
} |
Partager