Question

I am using Apache LDAP API to set new attribute: userPassword in Oracle Internet Directory. I want to set this password with SHA encryption method. I currently have following code:

Attribute userPasswordAttribute = new DefaultAttribute("userPassword", "password"));
ModifyRequest modifyRequest = new ModifyRequestImpl();
modifyRequest.setName(dn);
modifyRequest.add(userPasswordAttribute);
ModifyResponse response = connection.modify(modifyRequest);

However this adds SSHA encrypted password along with some other attributes which I do not want (authpassword;oid). I have seen that there a class called EncryptionMethod in LDAP API but how to use it in my code?

Was it helpful?

Solution

Try this

String newPassword = "password";
modifyRequest.replace("userPassword", PasswordUtil.createStoragePassword(
                            newPassword.getBytes(), LdapSecurityConstants.HASH_METHOD_SHA));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top