use of org.mifos.customers.personnel.business.PersonnelUsedPasswordEntity in project head by mifos.
the class PersonnelServiceImpl method changePassword.
@Override
public void changePassword(PersonnelBO user, String newPassword, boolean setPasswordChanged) {
UserContext userContext = new UserContext();
userContext.setId(user.getPersonnelId());
userContext.setName(user.getUserName());
user.updateDetails(userContext);
validateIfPasswordIsRecentlyUsed(user, newPassword);
byte[] newEncPass = EncryptionService.getInstance().createEncryptedPassword(newPassword);
PersonnelUsedPasswordEntity personnelUsedPassword;
int passwordHistoryCount = PasswordRules.getPasswordHistoryCount();
if (user.getPersonnelUsedPasswords().size() >= passwordHistoryCount) {
personnelUsedPassword = new ArrayList<PersonnelUsedPasswordEntity>(user.getPersonnelUsedPasswords()).get(0);
personnelUsedPassword.setUsedPassword(newEncPass);
personnelUsedPassword.setDateChanged(new LocalDateTime().toDateTime().toDate());
} else {
personnelUsedPassword = new PersonnelUsedPasswordEntity();
personnelUsedPassword.setPersonnel(user);
personnelUsedPassword.setUsedPassword(newEncPass);
personnelUsedPassword.setDateChanged(new LocalDateTime().toDateTime().toDate());
user.getPersonnelUsedPasswords().add(personnelUsedPassword);
}
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(user);
user.changePasswordTo(newPassword, user.getPersonnelId(), setPasswordChanged);
this.personnelDao.save(user);
hibernateTransactionHelper.commitTransaction();
} catch (Exception e) {
hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
hibernateTransactionHelper.closeSession();
}
}
Aggregations