I have a Java application and I want that each user have the possibility to change own password via application.
This is my code:
public void changePassword()
{
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("LDAPS://X.Y.Z.T/");
contextSource.setBase("DC=example,DC=com");
contextSource.setUserDn("[email protected]");
contextSource.setPassword("oldpass");
contextSource.afterPropertiesSet();
LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
byte[] li_byOldpass = encodePassword("oldpass");
byte[] li_byNewpass = encodePassword("newpass");
Attribute oldattr = new BasicAttribute("unicodePwd", li_byOldpass);
Attribute newattr = new BasicAttribute("unicodePwd", li_byNewpass);
ModificationItem olditem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, oldattr);
ModificationItem newitem = new ModificationItem(DirContext.ADD_ATTRIBUTE, newattr);
ModificationItem repitem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, newattr);
ModificationItem[] mods = new ModificationItem[2];
mods[0] = olditem;
mods[1] = newitem;
try
{
ldapTemplate.modifyAttributes("CN=Name Surname,OU=Office,DC=example,DC=com", new ModificationItem[] { repitem });
}catch(Exception e)
{
System.out.println("Error in changing password on Active Directory: " + e.getMessage() );
}
}
Unfortunately it doesn't work, and this is the errore that i get:
[LDAP: error code 32 - 0000208D: NameErr: DSID-0310020A, problem 2001 (NO_OBJECT), data 0, best match of:'DC=example,DC=com'];
Any help will be appreciate
Thanks