Hi there, I am trying Novell LDAP API to connect to Active directory. I
was able connect to AD over SSL and run Search to find users.I was also
able modify some attributes like DisplayName and Description etc. I am
trying to reset the password using attribute "unicodePwd" and getting
error -LDAPException: Unwilling To Perform (53) Unwilling To Perform
when used LDAPModification.REPLACE method. It looks like Active
Directory generates this error due to some restrictions . Is there any
thing I can change in code or active directory side ?

Below is the code.


-

import java.io.UnsupportedEncodingException;

import java.security.Security;

import com.novell.ldap.*;



public class SSLModifyPassword

{

public static void main( String[] args )

{

int ldapPort = LDAPConnection.DEFAULT_SSL_PORT;

int searchScope = LDAPConnection.SCOPE_ONE;

int ldapVersion = LDAPConnection.LDAP_V3;

String ldapHost ="xxx.xx.xx.xxx";

String loginDN = "CN=patest, CN=Users, DC=MADCTEST,DC=LOCAL";

String password = "password";

String ModifyDN = "CN=test1, CN=Users, DC=MADCTEST,DC=LOCAL";

String newpassword = "newpassword";

String currentpassword = "password";

String path = "C:\\Program
Files\\Java\\jdk1.7.0_01\\bin\\test1";

LDAPSocketFactory ssf;


try {

// connect to the server


Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider());



// Dynamically set the property that JSSE uses to identify


// the keystore that holds trusted root certificates


System.setProperty("javax.net.ssl.trustStore", path);



ssf = new LDAPJSSESecureSocketFactory();



// Set the socket factory as the default for all future
connections


LDAPConnection.setSocketFactory(ssf);



// Note: the socket factory can also be passed in as a
parameter


// to the constructor to set it for this connection only.


LDAPConnection lc = new LDAPConnection();



// connect to the server


lc.connect( ldapHost, ldapPort );



// authenticate to the server


lc.bind( ldapVersion, loginDN, password.getBytes("UTF8")
);



// at this point you are connected with a secure connection


System.out.println( "Successful SSL bind with server.");


String currentQuotedPassword = '"' + currentpassword +
'"';
byte[] currentnicodePassword =
currentQuotedPassword.getBytes("UTF8");

String newQuotedPassword = '"' + newpassword + '"';
byte[] newUnicodePassword =
newQuotedPassword.getBytes("UTF8");



LDAPAttribute attributePassword = new LDAPAttribute(
"unicodePwd",newUnicodePassword);
lc.modify( ModifyDN, new
LDAPModification(LDAPModification.REPLACE, attributePassword) );


System.out.println( "Successfully set the user's password" );



System.out.println("Your password has been modified.");


lc.disconnect();

}

catch( LDAPException e ) {

System.out.println( "Error: " + e.toString() );

}

catch( UnsupportedEncodingException e ) {

System.out.println( "Error: " + e.toString() );

}

System.exit(0);

}



}

-


--
prashantaphale
------------------------------------------------------------------------
prashantaphale's Profile: http://forums.novell.com/member.php?userid=129977
View this thread: http://forums.novell.com/showthread.php?t=458537