This discussion is archived
3 Replies Latest reply: Mar 11, 2013 2:34 PM by EJP RSS

Saving the password of a user in active directory using java

996011 Newbie
Currently Being Moderated
Hello, i am trying to use java to build a class that creates a user in Active directory 2012.But the problem is that when the user is created the password is not being saved.

Can anybody help on this knowing that i tried to save in the fields userPassword and unicodePwd.

Thanks.
  • 1. Re: Saving the password of a user in active directory using java
    EJP Guru
    Currently Being Moderated
    You tried how? With what code?
  • 2. Re: Saving the password of a user in active directory using java
    996011 Newbie
    Currently Being Moderated
    DirContext ctx = new InitialDirContext(pr);
              BasicAttributes entry = new BasicAttributes(true);
              String entryDN = "cn=CharbelHad,ou=test users,dc=test,dc=dev";
              Attribute cn = new BasicAttribute("cn", "ChHad");
              Attribute street = (new BasicAttribute("streetAddress", "Ach"));
              Attribute loginPreW2k = (new BasicAttribute("sAMAccountName", "ChlHad@test.dev"));
              Attribute login = (new BasicAttribute("userPrincipalName", "ChlHad@test.dev"));
              Attribute sn = (new BasicAttribute("sn", "Chl"));
              Attribute pwd = new BasicAttribute("unicodePwd", "\"Ch@341\"".getBytes("UTF-8"));
    Attribute userAccountControl = new BasicAttribute("userAccountControl", "512");
              Attribute oc = new BasicAttribute("objectClass");
              oc.add("top");
              oc.add("person");
              oc.add("organizationalPerson");
              oc.add("user");
              // build the entry
              entry.put(cn);
              entry.put(street);
              entry.put(sn);
              entry.put(userAccountControl);
              entry.put(pwd);
              entry.put(login);
              entry.put(loginPreW2k);
              entry.put(oc);
              ctx.createSubcontext(entryDN, entry);
  • 3. Re: Saving the password of a user in active directory using java
    EJP Guru
    Currently Being Moderated
    What's in 'pr'? You need to be using SSL to change password attributes in AD.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points