Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Change Ldap Password

843785Mar 3 2009 — edited Mar 4 2009
Hi

I am very new to Java and check out a view topic on sun related to ldap connections. And I must say it works 100%, but I am trying to change a password on ldap and I am getting the following Errors
Problem resetting password: javax.naming.NamingException: [LDAP: error code 1 - 000020D6: SvcErr: DSID-031006CC, problem 5012 (DIR_ERROR), data 0


I have tried to follow topic http://forums.sun.com/thread.jspa?threadID=5191879 but I seems to get lost

I have attached my code

package beans;
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.ldap.*;
import javax.naming.directory.*;

import java.io.*;

public class Setpass {
public static void main (String[] args)
{


String adminName = "adminname";
String adminPassword = "adminpassword";
String userName = "CN=Anthonio Booysen";
String oldPassword = "oldpassword";
String newPassword = "testtesttest";
//String searchBase = "DC=company,DC=net";


try {

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,"LDAP://dc2.company.net:389" );
env.put(Context.SECURITY_AUTHENTICATION,"DIGEST-MD5"); //No other SALS worked with me
env.put(Context.SECURITY_PRINCIPAL,adminName);
env.put(Context.SECURITY_CREDENTIALS,adminPassword);


// Create the initial directory context
DirContext ctx = new InitialDirContext(env);


//Replace the "unicdodePwd" attribute with a new value
//Password must be both Unicode and a quoted string
String oldQuotedPassword = "\"" + oldPassword + "\"";
byte[] oldUnicodePassword = oldQuotedPassword.getBytes("UTF-16LE");
String newQuotedPassword = "\"" + newPassword + "\"";
byte[] newUnicodePassword = newQuotedPassword.getBytes("UTF-16LE");


mods[0] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("unicodePwd", oldUnicodePassword));
mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("unicodePwd", newUnicodePassword));



// Perform the update

ctx.modifyAttributes(userName, mods);



System.out.println("Reset Password for: " + userName);
ctx.close();

}
catch (NamingException e) {
System.out.println("Problem resetting password: " + e);



}
catch (UnsupportedEncodingException e) {
System.out.println("Problem encoding password: " + e);
}

}


}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 1 2009
Added on Mar 3 2009
1 comment
410 views