Search in sources :

Example 16 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class LoginServiceFacadeWebTier method updatePassword.

@Override
public boolean updatePassword(String username, String oldPassword, String newPassword) {
    MifosUser appUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(appUser);
    PersonnelBO user = this.personnelDao.findPersonnelByUsername(username);
    boolean passwordIsAlreadyChanged = user.isPasswordChanged();
    this.personnelService.changePassword(user, newPassword, true);
    Date newExpirationDate = null;
    if (user.getPasswordExpirationDate() != null) {
        newExpirationDate = new LocalDateTime().plusDays(PasswordRules.getPasswordExpirationDatePrelongation()).toDateTime().toDate();
    }
    personnelService.changePasswordExpirationDate(user, newExpirationDate);
    return passwordIsAlreadyChanged;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 17 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class MeetingServiceFacadeWebTier method updateCustomerMeeting.

@Override
public void updateCustomerMeeting(MeetingDto meetingUpdateRequest, Integer customerId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = userContextFactory.create(user);
    MeetingBO meeting = meetingFactory.create(meetingUpdateRequest);
    meeting.updateDetails(userContext);
    CustomerBO customer = this.customerDao.findCustomerById(customerId);
    customer.updateDetails(userContext);
    customerService.updateCustomerMeetingSchedule(meeting, customer);
}
Also used : UserContext(org.mifos.security.util.UserContext) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser)

Example 18 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class PersonnelServiceFacadeWebTier method changeUserLocale.

@Override
public Short changeUserLocale(Short id, HttpServletRequest request) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    if (id != null) {
        Short newLocaleId = id;
        if (Localization.getInstance().getLocaleById(newLocaleId) != null) {
            user.setPreferredLocaleId(newLocaleId);
            try {
                this.transactionHelper.startTransaction();
                PersonnelBO p = this.personnelDao.findPersonnelById((short) user.getUserId());
                p.setPreferredLocale(newLocaleId);
                this.personnelDao.update(p);
                this.transactionHelper.commitTransaction();
                UserContext userContext = (UserContext) request.getSession().getAttribute(LoginConstants.USERCONTEXT);
                userContext.setLocaleId(newLocaleId);
            } catch (Exception e) {
                this.transactionHelper.rollbackTransaction();
                throw new MifosRuntimeException(e);
            }
            ApplicationContextProvider.getBean(MessageLookup.class).updateLabelCache();
        }
    }
    return user.getPreferredLocaleId();
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MessageLookup(org.mifos.application.master.MessageLookup) MifosUser(org.mifos.security.MifosUser) ValidationException(org.mifos.framework.exceptions.ValidationException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 19 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class PersonnelServiceFacadeWebTier method retrieveUserSettings.

@Override
public UserSettingsDto retrieveUserSettings() {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    PersonnelBO personnel = this.personnelDao.findPersonnelById(userContext.getId());
    String gender = getNameForBusinessActivityEntity(personnel.getPersonnelDetails().getGender());
    String martialStatus = getNameForBusinessActivityEntity(personnel.getPersonnelDetails().getMaritalStatus());
    String language = Localization.getInstance().getDisplayName(personnel.getPreferredLocale());
    String sitePreference = SitePreferenceType.getSitePreference(personnel.getSitePreference()).name();
    List<ValueListElement> genders = this.customerDao.retrieveGenders();
    List<ValueListElement> martialStatuses = this.customerDao.retrieveMaritalStatuses();
    List<ValueListElement> languages = Localization.getInstance().getLocaleForUI();
    List<ValueListElement> sitePreferenceTypes = new ArrayList<ValueListElement>();
    for (short i = 0; i < SitePreferenceType.values().length; i++) {
        SitePreferenceType sitePreferenceType = SitePreferenceType.values()[i];
        ValueListElement valueListElement = new BusinessActivityEntity(sitePreferenceType.getValue().intValue(), sitePreferenceType.name(), sitePreferenceType.name());
        sitePreferenceTypes.add(valueListElement);
    }
    int age = DateUtils.DateDiffInYears(((Date) personnel.getPersonnelDetails().getDob()));
    if (age < 0) {
        age = 0;
    }
    return new UserSettingsDto(gender, martialStatus, language, age, sitePreference, genders, martialStatuses, languages, sitePreferenceTypes);
}
Also used : SitePreferenceType(org.mifos.config.SitePreferenceType) BusinessActivityEntity(org.mifos.application.master.business.BusinessActivityEntity) UserContext(org.mifos.security.util.UserContext) UserSettingsDto(org.mifos.dto.screen.UserSettingsDto) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) Date(java.sql.Date) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ValueListElement(org.mifos.dto.domain.ValueListElement)

Example 20 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class PersonnelServiceFacadeWebTier method updateUserSettings.

@Override
public void updateUserSettings(Short personnelId, String emailId, Name name, Integer maritalStatusValue, Integer genderValue, AddressDto address, Short preferredLocale, Short sitePreference) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    PersonnelBO personnel = this.personnelDao.findPersonnelById(personnelId);
    try {
        personnel.updateDetails(userContext);
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(personnel);
        Address theAddress = null;
        if (address != null) {
            theAddress = new Address(address.getLine1(), address.getLine2(), address.getLine3(), address.getCity(), address.getState(), address.getCountry(), address.getZip(), address.getPhoneNumber());
        }
        personnel.update(emailId, name, maritalStatusValue, genderValue, theAddress, preferredLocale, sitePreference);
        if (preferredLocale != null && preferredLocale != 0) {
            user.setPreferredLocaleId(preferredLocale);
        }
        this.transactionHelper.commitTransaction();
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : Address(org.mifos.framework.business.util.Address) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) ValidationException(org.mifos.framework.exceptions.ValidationException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

UserContext (org.mifos.security.util.UserContext)369 MifosUser (org.mifos.security.MifosUser)134 MifosRuntimeException (org.mifos.core.MifosRuntimeException)102 ArrayList (java.util.ArrayList)97 Test (org.junit.Test)81 BusinessRuleException (org.mifos.service.BusinessRuleException)75 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)72 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)65 AccountException (org.mifos.accounts.exceptions.AccountException)55 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)49 Money (org.mifos.framework.util.helpers.Money)46 LoanBO (org.mifos.accounts.loan.business.LoanBO)45 LocalDate (org.joda.time.LocalDate)44 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)43 ServiceException (org.mifos.framework.exceptions.ServiceException)43 PersistenceException (org.mifos.framework.exceptions.PersistenceException)38 CustomerBO (org.mifos.customers.business.CustomerBO)37 MeetingBO (org.mifos.application.meeting.business.MeetingBO)34 Date (java.util.Date)31 CustomerException (org.mifos.customers.exceptions.CustomerException)31