Search in sources :

Example 1 with PersonnelUsedPasswordEntity

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();
    }
}
Also used : PersonnelUsedPasswordEntity(org.mifos.customers.personnel.business.PersonnelUsedPasswordEntity) LocalDateTime(org.joda.time.LocalDateTime) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosRuntimeException(org.mifos.core.MifosRuntimeException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

ArrayList (java.util.ArrayList)1 LocalDateTime (org.joda.time.LocalDateTime)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 PersonnelUsedPasswordEntity (org.mifos.customers.personnel.business.PersonnelUsedPasswordEntity)1 UserContext (org.mifos.security.util.UserContext)1 BusinessRuleException (org.mifos.service.BusinessRuleException)1