title: Java - Could not set password in Active Directory for new accounts (bug)
body: <p>I'm creating new user accounts in the AD LDAP using java and spring.
  For this task is required that the password attribute is set. I'm following all the known rules in AD: the <em>unicodePwd</em> attribute is sent through SSL connection, in UTF-16LE format using quotes around the password. </p>
  
  <p>I've tried almost everything for days. No exceptions are thrown when the process run. When I check the new user account using Apache Directory, it displays a timestamp for the password creation (attribute <em>pwdLastSet</em>). So, the password exists (?). 
  But the worst part is that I cannot authenticate any user that I create, but I can change the password for the users that already exist using the same code. And this users can authenticate with the new pasword (very rare).</p>
  
  <p>I suspect I'm missing some attributes when I create the new user.</p>
  
  <p>Also, the <em>badPwdCount</em> attribute never increments (it remains 0) when I try to programatically authenticate a new user using the password I previously set. But this attribute actually increments If I try to authenticate with any other password value (this is very extrange but is happening).</p>
  
  <p>These are the attributes I set:</p>
  
  <ul>
  <li>initials</li>
  <li>displayName</li>
  <li>description</li>
  <li>sAMAccountName</li>
  <li>ipPhone</li>
  <li>postalCode</li>
  <li>sn </li>
  <li>physicalDeliveryOfficeName</li>
  <li>employeeID</li>
  <li>co</li>
  <li>streetAddress</li>
  <li>st</li>
  <li>userPrincipalName</li>
  <li>title</li>
  <li>department</li>
  <li>company</li>
  <li>objectCategory</li>
  <li>memberOf</li>
  </ul>
  
  <p>This is the code that sets the password </p>
  
  <pre><code>public void setPass(Exchange ex) throws UnsupportedEncodingException, NoSuchAlgorithmException {
              final String PASS = '"' + "Nuevo.password1" + '"';          
              String dn = (String) ex.getIn().getHeader("dn");
              byte[] quotedBytes = PASS.getBytes("UTF-16LE");
              LdapTemplate ldap = (LdapTemplate) ex.getContext().getRegistry().lookup("ldapWrite") ;
              Attribute pass = new BasicAttribute("unicodePwd", quotedBytes);
              ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, pass);
              ldap.modifyAttributes(dn, new ModificationItem[] { item });
  
          }
  </code></pre>
  
  <p>This is the spring configuration for the LDAP bean.</p>
  
  <pre><code>&lt;bean class="org.springframework.ldap.core.support.LdapContextSource" id="ctxSource"&gt;
      &lt;property name="url" value="ldaps://10.228.193.134:636" /&gt;
      &lt;property name="userDn" value="CN=Integración AGS,OU=Usuarios,OU=Cuentas de Servicio,OU=Regionales,DC=dssatuat,DC=sat,DC=gob,DC=mx" /&gt;
      &lt;property name="password" value="Octubre.14" /&gt;
  &lt;/bean&gt;
  
  &lt;bean class="org.springframework.ldap.core.LdapTemplate" id="ldapWrite"&gt;
      &lt;constructor-arg ref="ctxSource" /&gt;
  &lt;/bean&gt;
  </code></pre>