Hello!
After some new tries, finally I got it work. I had to do some change of code:
Code:
public List<ADUser> searchUser(String searchBase, String attribute, String searchValue){
AndFilter andFilter = new AndFilter();
andFilter.and(new EqualsFilter("objectclass","person"));
andFilter.and(new EqualsFilter(config.getProperty(attribute),searchValue));
log.debug("LDAP Query " + andFilter.encode());
@SuppressWarnings("unchecked")
List<ADUser> result = ldapTemplate.search(searchBase, andFilter.encode(), new ADUserAttributeMapper());
return result;
}
public boolean resetPassword(ADUser user, String password) {
try {
ModificationItem repitem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("unicodepwd", encodePassword(password)) );
/**
* This is a workaround for the springldap base problem.
* If a AD base is defined in the springldap.xml file it is not possible to
* use the complete distinguished name because this includes the base of the AD.
* Therefore it is necessary to remove the base from the dinstinguished name.
* This is done in the following lines
*/
try {
String dn[] = user.getDistinguishedName().split(",DC");
// "cn=Max Mustermann,ou=Internal,ou=Users,ou=myOrgan"
ldapTemplate.modifyAttributes(dn[0], new ModificationItem[] { repitem });
return true;
}
catch(ArrayIndexOutOfBoundsException e ) {
log.error("Domain controller split did not work, dn size is null!", e);
return false;
}
}
catch ( Exception e ) {
log.error( "changePassword()", e);
return false;
}
}