use of org.motechproject.security.domain.MotechUserProfile in project motech by motech.
the class MotechUserServiceBundleIT method shouldChangeExpiredPassword.
@Test
public void shouldChangeExpiredPassword() {
motechUserService.register("expired", "password", "1234", "", asList("IT_ADMIN"), Locale.ENGLISH, UserStatus.MUST_CHANGE_PASSWORD, "");
MotechUserProfile profile = motechUserService.changeExpiredPassword("expired", "password", "newPassword");
assertNotNull(profile);
assertEquals(UserStatus.ACTIVE, profile.getUserStatus());
UserDto userDto = motechUserService.getUser("expired");
assertEquals(UserStatus.ACTIVE, userDto.getUserStatus());
}
use of org.motechproject.security.domain.MotechUserProfile in project motech by motech.
the class MotechUserServiceImpl method hasActiveMotechAdmin.
@Override
@Transactional
public boolean hasActiveMotechAdmin() {
List<MotechUserProfile> users = getUsers();
MotechUserProfile motechUser = (MotechUserProfile) CollectionUtils.find(users, new Predicate() {
@Override
public boolean evaluate(Object object) {
MotechUserProfile user = (MotechUserProfile) object;
return user.isActive() && user.hasRole(UserRoleNames.MOTECH_ADMIN);
}
});
return motechUser != null;
}
use of org.motechproject.security.domain.MotechUserProfile in project motech by motech.
the class MotechUserServiceImpl method changeExpiredPassword.
@Override
@Transactional
public MotechUserProfile changeExpiredPassword(String userName, String oldPassword, String newPassword) {
MotechUser motechUser = motechUsersDao.findByUserName(userName);
validatePassword(newPassword);
if (motechUser != null && UserStatus.MUST_CHANGE_PASSWORD.equals(motechUser.getUserStatus()) && passwordEncoder.isPasswordValid(motechUser.getPassword(), oldPassword)) {
// The new password and the old password cannot be the same
if (passwordEncoder.isPasswordValid(motechUser.getPassword(), newPassword)) {
return null;
}
motechUser.setPassword(passwordEncoder.encodePassword(newPassword));
motechUser.setUserStatus(UserStatus.ACTIVE);
motechUsersDao.update(motechUser);
return new MotechUserProfile(motechUser);
} else {
// Wrong password
incrementFailureLoginCount(motechUser);
}
return null;
}
use of org.motechproject.security.domain.MotechUserProfile in project motech by motech.
the class MotechUserServiceImpl method changePassword.
@Override
@Transactional
public MotechUserProfile changePassword(String userName, String oldPassword, String newPassword) {
MotechUser motechUser = motechUsersDao.findByUserName(userName);
validatePassword(newPassword);
if (motechUser != null && passwordEncoder.isPasswordValid(motechUser.getPassword(), oldPassword)) {
motechUser.setPassword(passwordEncoder.encodePassword(newPassword));
motechUsersDao.update(motechUser);
return new MotechUserProfile(motechUser);
}
return null;
}
use of org.motechproject.security.domain.MotechUserProfile in project motech by motech.
the class MotechUserServiceTest method shouldIncrementFailureLoginCounter.
@Test
public void shouldIncrementFailureLoginCounter() {
MotechUser motechUser = new MotechUser();
motechUser.setUserStatus(UserStatus.MUST_CHANGE_PASSWORD);
motechUser.setPassword(PASSWORD);
motechUser.setUserName(USER);
motechUser.setFailureLoginCounter(0);
when(motechUsersDao.findByUserName(USER)).thenReturn(motechUser);
when(motechPasswordEncoder.isPasswordValid(PASSWORD, PASSWORD)).thenReturn(false);
when(settingService.getFailureLoginLimit()).thenReturn(2);
MotechUserProfile profile = motechUserService.changeExpiredPassword(USER, PASSWORD, NEW_PASSWORD);
assertNull(profile);
verify(motechUsersDao).update(userCaptor.capture());
MotechUser capturedUser = userCaptor.getValue();
assertEquals(USER, capturedUser.getUserName());
assertEquals(PASSWORD, capturedUser.getPassword());
assertEquals(new Integer(1), capturedUser.getFailureLoginCounter());
}
Aggregations