Search in sources :

Example 41 with MotechUser

use of org.motechproject.security.domain.MotechUser in project motech by motech.

the class MotechUserServiceImpl method setLocale.

@Override
@Transactional
public void setLocale(Locale locale) {
    UserDto currentUser = getCurrentUser();
    MotechUser user = motechUsersDao.findByUserName(currentUser.getUserName());
    user.setLocale(locale);
    updateUserDetailsWithoutPassword(new UserDto(user));
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) UserDto(org.motechproject.security.model.UserDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with MotechUser

use of org.motechproject.security.domain.MotechUser in project motech by motech.

the class PasswordExpirationCheckEventHandler method handleEvent.

/**
 * Handles PASSWORD_EXPIRATION_CHECK_EVENT event. Checks every user for the date of the last password change and sends an
 * event if the user should be notified about the required password change.
 *
 * @param event  the event to be handled
 */
@MotechListener(subjects = PASSWORD_EXPIRATION_CHECK_EVENT)
public void handleEvent(MotechEvent event) {
    if (settingService.isPasswordResetReminderEnabled()) {
        LOGGER.info("Daily password reset reminder triggered");
        final int passwordExpirationInDays = settingService.getNumberOfDaysToChangePassword();
        final int daysBeforeExpirationToSendReminder = settingService.getNumberOfDaysForReminder();
        final int daysWithNoPassChangeForReminder = passwordExpirationInDays - daysBeforeExpirationToSendReminder;
        for (MotechUser user : allUsers.retrieveAll()) {
            final int daysWithoutPasswordChange = daysWithoutPasswordChange(user);
            LOGGER.debug("User {} hasn't changed password in {} days. Notification is being after {} days without" + " password change, {} days before expiration", user.getUserName(), daysWithoutPasswordChange, daysWithNoPassChangeForReminder, daysBeforeExpirationToSendReminder);
            if (daysWithoutPasswordChange == daysWithNoPassChangeForReminder) {
                if (StringUtils.isNotBlank(user.getEmail())) {
                    sendPasswordReminderEvent(user, passwordExpirationInDays, daysBeforeExpirationToSendReminder);
                } else {
                    LOGGER.debug("User {} doesn't have an email address set, skipping sending of reminder", user.getUserName());
                }
            }
        }
    } else {
        LOGGER.info("Daily password reset reminder is disabled, skipping processing of users");
    }
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) MotechListener(org.motechproject.event.listener.annotations.MotechListener)

Example 43 with MotechUser

use of org.motechproject.security.domain.MotechUser in project motech by motech.

the class MotechLoginErrorHandlerTest method createUser.

private MotechUser createUser(UserStatus userStatus, int failureLoginCounter) {
    MotechUser user = new MotechUser();
    user.setUserName("testUser");
    user.setFailureLoginCounter(failureLoginCounter);
    user.setUserStatus(userStatus);
    return user;
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser)

Example 44 with MotechUser

use of org.motechproject.security.domain.MotechUser in project motech by motech.

the class PasswordExpirationCheckEventHandlerTest method prepareMotechUsersTwo.

private List<MotechUser> prepareMotechUsersTwo() {
    List<MotechUser> users = new ArrayList<>();
    DateTime date = DateUtil.now().minusDays(14);
    MotechUser user = new MotechUser();
    user.setUserName("fooUsernameOne");
    user.setEmail("foouserone@foodomain.com");
    user.setLastPasswordChange(date);
    users.add(user);
    user = new MotechUser();
    user.setUserName("fooUsernameTwo");
    user.setEmail("foousertwo@foodomain.com");
    user.setLastPasswordChange(date);
    users.add(user);
    user = new MotechUser();
    user.setUserName("fooUsernameThree");
    user.setEmail("foouserthree@foodomain.com");
    user.setLastPasswordChange(date.minusDays(2));
    users.add(user);
    user = new MotechUser();
    user.setUserName("fooUsernameFour");
    user.setEmail("foouserfour@foodomain.com");
    user.setLastPasswordChange(date.minusDays(2));
    users.add(user);
    return users;
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime)

Example 45 with MotechUser

use of org.motechproject.security.domain.MotechUser in project motech by motech.

the class PasswordExpirationCheckEventHandlerTest method prepareMotechUsersOne.

private List<MotechUser> prepareMotechUsersOne() {
    List<MotechUser> users = new ArrayList<>();
    DateTime date = DateUtil.now().minusDays(14);
    MotechUser user = new MotechUser();
    user.setUserName("fooUsernameOne");
    user.setEmail("foouserone@foodomain.com");
    user.setLastPasswordChange(date);
    users.add(user);
    user = new MotechUser();
    user.setUserName("fooUsernameTwo");
    user.setEmail("foousertwo@foodomain.com");
    user.setLastPasswordChange(date.minusDays(1));
    users.add(user);
    user = new MotechUser();
    user.setUserName("fooUsernameThree");
    user.setEmail("foouserthree@foodomain.com");
    user.setLastPasswordChange(date.minusDays(1));
    users.add(user);
    user = new MotechUser();
    user.setUserName("fooUsernameFour");
    user.setEmail("foouserfour@foodomain.com");
    user.setLastPasswordChange(date.minusDays(2));
    users.add(user);
    return users;
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime)

Aggregations

MotechUser (org.motechproject.security.domain.MotechUser)61 Test (org.junit.Test)27 Transactional (org.springframework.transaction.annotation.Transactional)24 MotechUserProfile (org.motechproject.security.domain.MotechUserProfile)8 ArrayList (java.util.ArrayList)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)6 DateTime (org.joda.time.DateTime)4 PasswordRecovery (org.motechproject.security.domain.PasswordRecovery)4 Authentication (org.springframework.security.core.Authentication)4 User (org.springframework.security.core.userdetails.User)4 HttpSession (javax.servlet.http.HttpSession)3 MotechRole (org.motechproject.security.domain.MotechRole)3 RoleDto (org.motechproject.security.model.RoleDto)3 ConfigAttribute (org.springframework.security.access.ConfigAttribute)3 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)3 AuthenticationException (org.springframework.security.core.AuthenticationException)3 UserNotFoundException (org.motechproject.security.exception.UserNotFoundException)2 UserDto (org.motechproject.security.model.UserDto)2 SecurityConfig (org.springframework.security.access.SecurityConfig)2 AbstractAuthenticationToken (org.springframework.security.authentication.AbstractAuthenticationToken)2