Search in sources :

Example 56 with MotechUser

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

the class MotechLoginSuccessHandlerTest method shouldSetSessionTimeoutAndStore.

@Test
public void shouldSetSessionTimeoutAndStore() throws ServletException, IOException {
    MotechUser user = new MotechUser();
    user.setUserName("testUser");
    user.setFailureLoginCounter(3);
    when(authentication.getName()).thenReturn("testUser");
    when(motechUsersDao.findByUserName("testUser")).thenReturn(user);
    when(request.getSession()).thenReturn(session);
    when(settingService.getSessionTimeout()).thenReturn(500);
    motechLoginSuccessHandler.onAuthenticationSuccess(request, response, authentication);
    verify(session).setMaxInactiveInterval(500);
    verify(sessionHandler).addSession(session);
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) Test(org.junit.Test)

Example 57 with MotechUser

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

the class PasswordReminderEventHandlerTest method prepareUser.

private void prepareUser() {
    user = new MotechUser();
    user.setLastPasswordChange(DateUtil.now().minusDays(DAYS_TO_CHANGE_PASSWORD - DAYS_FOR_REMINDER));
    user.setUserName("FooUsername");
    user.setEmail("fooUser@domain.com");
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser)

Example 58 with MotechUser

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

the class MotechUserServiceBundleIT method testPasswordEncoding.

@Test
public void testPasswordEncoding() {
    String plainTextPassword = "testpassword";
    motechUserService.register("testuser", plainTextPassword, "entity1", "", asList("ADMIN"), Locale.ENGLISH);
    MotechUser motechUser = usersDataService.findByUserName("testuser");
    assertTrue(passwordEncoder.isPasswordValid(motechUser.getPassword(), plainTextPassword));
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) Test(org.junit.Test)

Example 59 with MotechUser

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

the class MotechUserServiceBundleIT method testRegister.

@Test
public void testRegister() {
    motechUserService.register("userName", "password", "1234", "", asList("IT_ADMIN", "DB_ADMIN"), Locale.ENGLISH);
    MotechUser motechUser = usersDataService.findByUserName("userName");
    assertNotNull(motechUser);
    assertTrue(motechUser.getRoles().contains("IT_ADMIN"));
    assertTrue(motechUser.getRoles().contains("DB_ADMIN"));
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) Test(org.junit.Test)

Example 60 with MotechUser

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

the class MotechUserServiceBundleIT method shouldCreateActiveUserByDefault.

@Test
public void shouldCreateActiveUserByDefault() {
    motechUserService.register("userName", "password", "1234", "", asList("IT_ADMIN", "DB_ADMIN"), Locale.ENGLISH);
    MotechUser motechUser = usersDataService.findByUserName("userName");
    assertEquals(UserStatus.ACTIVE, motechUser.getUserStatus());
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) Test(org.junit.Test)

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