Search in sources :

Example 1 with UserDto

use of org.motechproject.security.model.UserDto in project motech by motech.

the class MotechUserServiceBundleIT method shouldFindUserByUsername.

@Test
public void shouldFindUserByUsername() {
    motechUserService.register("userName", "password", "1234", "", asList("IT_ADMIN", "DB_ADMIN"), Locale.ENGLISH);
    UserDto motechUser = motechUserService.getUser("userName");
    assertNotNull(motechUser);
    assertTrue(motechUser.getRoles().contains("IT_ADMIN"));
    assertTrue(motechUser.getRoles().contains("DB_ADMIN"));
}
Also used : UserDto(org.motechproject.security.model.UserDto) Test(org.junit.Test)

Example 2 with UserDto

use of org.motechproject.security.model.UserDto in project motech by motech.

the class MotechUserServiceBundleIT method shouldFindUserByUsernameCaseInsensitive.

@Test
public void shouldFindUserByUsernameCaseInsensitive() {
    motechUserService.register("userName", "password", "1234", "", asList("IT_ADMIN", "DB_ADMIN"), Locale.ENGLISH);
    UserDto motechUser = motechUserService.getUser("USERNAME");
    assertNotNull(motechUser);
    assertTrue(motechUser.getRoles().contains("IT_ADMIN"));
    assertTrue(motechUser.getRoles().contains("DB_ADMIN"));
}
Also used : UserDto(org.motechproject.security.model.UserDto) Test(org.junit.Test)

Example 3 with UserDto

use of org.motechproject.security.model.UserDto in project motech by motech.

the class MotechUserServiceBundleIT method shouldNotActivateUserWhenPasswordsAreTheSame.

@Test
public void shouldNotActivateUserWhenPasswordsAreTheSame() {
    motechUserService.register("expired", "password", "1234", "", asList("IT_ADMIN"), Locale.ENGLISH, UserStatus.MUST_CHANGE_PASSWORD, "");
    MotechUserProfile profile = motechUserService.changeExpiredPassword("expired", "password", "password");
    assertNull(profile);
    UserDto userDto = motechUserService.getUser("expired");
    assertEquals(UserStatus.MUST_CHANGE_PASSWORD, userDto.getUserStatus());
}
Also used : MotechUserProfile(org.motechproject.security.domain.MotechUserProfile) UserDto(org.motechproject.security.model.UserDto) Test(org.junit.Test)

Example 4 with UserDto

use of org.motechproject.security.model.UserDto 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());
}
Also used : MotechUserProfile(org.motechproject.security.domain.MotechUserProfile) UserDto(org.motechproject.security.model.UserDto) Test(org.junit.Test)

Example 5 with UserDto

use of org.motechproject.security.model.UserDto in project motech by motech.

the class UserControllerTest method shouldPrintErrorsFromValidators.

@Test
public void shouldPrintErrorsFromValidators() throws Exception {
    when(localeService.getUserLocale(any(HttpServletRequest.class))).thenReturn(Locale.GERMAN);
    when(settingService.getPasswordValidator()).thenReturn(validator);
    when(validator.getValidationError(Locale.GERMAN)).thenReturn("Error from validator");
    doThrow(new PasswordValidatorException("error")).when(userService).register(eq("john"), eq("invalid"), eq("john@gmail.com"), eq(""), anyListOf(String.class), any(Locale.class));
    UserDto userDto = new UserDto();
    userDto.setUserName("john");
    userDto.setEmail("john@gmail.com");
    userDto.setPassword("invalid");
    mockMvc.perform(post("/users/create").body(new ObjectMapper().writeValueAsBytes(userDto)).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isBadRequest()).andExpect(content().string("literal:Error from validator"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Locale(java.util.Locale) PasswordValidatorException(org.motechproject.security.exception.PasswordValidatorException) UserDto(org.motechproject.security.model.UserDto) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

UserDto (org.motechproject.security.model.UserDto)15 Test (org.junit.Test)12 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 MotechUser (org.motechproject.security.domain.MotechUser)2 MotechUserProfile (org.motechproject.security.domain.MotechUserProfile)2 PasswordValidatorException (org.motechproject.security.exception.PasswordValidatorException)2 User (org.springframework.security.core.userdetails.User)2 Transactional (org.springframework.transaction.annotation.Transactional)2 List (java.util.List)1 HttpClient (org.apache.http.client.HttpClient)1 HttpGet (org.apache.http.client.methods.HttpGet)1 Contains (org.mockito.internal.matchers.Contains)1 PasswordTooShortException (org.motechproject.security.exception.PasswordTooShortException)1 RoleDto (org.motechproject.security.model.RoleDto)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1