try {
adminSession = this.service.getAdminSession();
} catch (Exception e) {
String msg = "An error occurred while retraining admin session.";
logger.error(msg, e);
throw new DirectoryServerException(msg, e);
}
if (adminSession != null) {
LdapPrincipal adminPrincipal = adminSession.getAuthenticatedPrincipal();
if (adminPrincipal != null) {
String passwordToStore = "{" + ConfigurationConstants.ADMIN_PASSWORD_ALGORITHM +
"}";
MessageDigest messageDigest;
try {
messageDigest = MessageDigest.getInstance(
ConfigurationConstants.ADMIN_PASSWORD_ALGORITHM);
} catch (NoSuchAlgorithmException e) {
throw new DirectoryServerException(
"Could not find digest algorithm - " +
ConfigurationConstants.ADMIN_PASSWORD_ALGORITHM);
}
messageDigest.update(password.getBytes());
byte[] bytes = messageDigest.digest();
String hash = Base64.encode(bytes);
passwordToStore = passwordToStore + hash;
adminPrincipal.setUserPassword(passwordToStore.getBytes());
InternalModifyDnRequest request = new ModifyDnRequestImpl(0);
EntryAttribute passwordAttribute = new DefaultServerAttribute(
getAttributeType("userPassword"));
passwordAttribute.add(passwordToStore.getBytes());
ServerModification serverModification =
new ServerModification(ModificationOperation.REPLACE_ATTRIBUTE,
passwordAttribute);
List<Modification> modifiedList = new ArrayList<Modification>();
modifiedList.add(serverModification);
try {
adminSession.modify(adminPrincipal.getClonedName(), modifiedList);
} catch (Exception e) {
String msg = "Failed changing connection user password.";
logger.error(msg, e);
throw new DirectoryServerException(msg, e);
}
} else {
String msg = "Could not retrieve admin principle. Failed changing connection " +
"user password.";
logger.error(msg);
throw new DirectoryServerException(msg);
}
} else {
String msg = "Directory admin session is null. The LDAP server may not have " +
"started yet.";
logger.error(msg);
throw new DirectoryServerException(msg);
}
} else {
String msg = "Directory service is null. The LDAP server may not have started yet.";
logger.error(msg);
throw new DirectoryServerException(msg);
}
}