use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUsersDaoTest method shouldNotCreateNewAccountIfUserAlreadyExists.
@Test
public void shouldNotCreateNewAccountIfUserAlreadyExists() {
MotechUser motechUser = new MotechUser("testuser", "testpassword", "test@test.com", "id", asList("ADMIN"), "", Locale.ENGLISH);
when(usersDataService.findByUserName("testuser")).thenReturn(motechUser);
motechUsersDao.add(motechUser);
verify(usersDataService).findByUserName("testuser");
verify(usersDataService, never()).create(motechUser);
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechAuthenticationProviderTest method shouldChangeUserStatusToMustChangePass.
@Test
public void shouldChangeUserStatusToMustChangePass() {
MotechUser motechUser = new MotechUser("bob", "encodedPassword", "entity_1", "", asList("some_role"), "", Locale.ENGLISH);
motechUser.setUserStatus(UserStatus.ACTIVE);
motechUser.setLastPasswordChange(DateTime.now().minusDays(3));
when(motechUsersDao.findByUserName("bob")).thenReturn(motechUser);
when(settingService.getNumberOfDaysToChangePassword()).thenReturn(2);
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("bob", "encodedPassword");
UserDetails details = authenticationProvider.retrieveUser("bob", authentication);
verify(motechUsersDao).update(userCaptor.capture());
assertTrue(details.isAccountNonLocked());
assertFalse(details.isCredentialsNonExpired());
MotechUser capturedUser = userCaptor.getValue();
Assert.assertEquals((Integer) 0, capturedUser.getFailureLoginCounter());
Assert.assertEquals(UserStatus.MUST_CHANGE_PASSWORD, capturedUser.getUserStatus());
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUserServiceTest method shouldBlockUserAfterCrossingTheFailureLoginCounter.
@Test(expected = LockedException.class)
public void shouldBlockUserAfterCrossingTheFailureLoginCounter() {
MotechUser motechUser = new MotechUser();
motechUser.setUserStatus(UserStatus.MUST_CHANGE_PASSWORD);
motechUser.setPassword(PASSWORD);
motechUser.setUserName(USER);
motechUser.setFailureLoginCounter(1);
when(motechUsersDao.findByUserName(USER)).thenReturn(motechUser);
when(motechPasswordEncoder.isPasswordValid(PASSWORD, PASSWORD)).thenReturn(false);
when(settingService.getFailureLoginLimit()).thenReturn(1);
motechUserService.changeExpiredPassword(USER, PASSWORD, NEW_PASSWORD);
}
use of org.motechproject.security.domain.MotechUser 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());
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechLoginSuccessHandlerTest method shouldReturnJSON.
@Test
public void shouldReturnJSON() throws ServletException, IOException {
MockHttpServletResponse mockResponse = new MockHttpServletResponse();
MockHttpServletRequest mockRequest = new MockHttpServletRequest();
mockRequest.addHeader("x-requested-with", "XMLHttpRequest");
MotechUser user = new MotechUser();
user.setUserName("testUser");
user.setFailureLoginCounter(3);
when(authentication.getName()).thenReturn("testUser");
when(motechUsersDao.findByUserName("testUser")).thenReturn(user);
motechLoginSuccessHandler.onAuthenticationSuccess(mockRequest, mockResponse, authentication);
MotechJsonMessage message = new MotechJsonMessage("SUCCESS");
assertEquals(message.toJson(), mockResponse.getContentAsString());
}
Aggregations