Ändern Sie das Active Directory -Passwort über Spring LDAPJava

Java-Forum
Anonymous
 Ändern Sie das Active Directory -Passwort über Spring LDAP

Post by Anonymous »

Ich habe eine Java -Anwendung und ich möchte, dass jeder Benutzer die Möglichkeit hat, das eigene Passwort über die Anwendung zu ändern.

Code: Select all

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 von: 'dc = Beispiel, dc = com']; < /strong> < /p>



Jede Hilfe wird zu schätzen wissen < /p>

Danke < /P.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post