Search in sources :

Example 6 with PasswordValidatorException

use of org.motechproject.security.exception.PasswordValidatorException in project motech by motech.

the class MotechUserServiceTest method shouldValidatePasswordOnEdit.

@Test(expected = PasswordValidatorException.class)
public void shouldValidatePasswordOnEdit() {
    UserDto userDto = new UserDto();
    userDto.setPassword("wrong");
    userDto.setUserName("user");
    when(motechUsersDao.findByUserName("user")).thenReturn(user);
    doThrow(new PasswordValidatorException("error")).when(validator).validate("wrong");
    motechUserService.updateUserDetailsWithPassword(userDto);
}
Also used : PasswordValidatorException(org.motechproject.security.exception.PasswordValidatorException) UserDto(org.motechproject.security.model.UserDto) Test(org.junit.Test)

Example 7 with PasswordValidatorException

use of org.motechproject.security.exception.PasswordValidatorException in project motech by motech.

the class ResetController method changePassword.

@RequestMapping(value = "/changepassword", method = RequestMethod.POST)
@ResponseBody
public ChangePasswordViewData changePassword(@RequestBody ChangePasswordForm form) {
    ChangePasswordViewData viewData = new ChangePasswordViewData(form);
    ChangePasswordFormValidator validator = new ChangePasswordFormValidator();
    List<String> errors = validator.validate(form);
    if (!errors.isEmpty()) {
        viewData.setErrors(errors);
    } else {
        try {
            MotechUserProfile profile = motechUserService.changeExpiredPassword(form.getUsername(), form.getOldPassword(), form.getPassword());
            if (profile != null) {
                viewData.setChangeSucceded(true);
            } else {
                viewData.getErrors().add("server.reset.wrongPassword");
            }
        } catch (PasswordValidatorException e) {
            viewData.getErrors().add(e.getMessage());
        } catch (LockedException e) {
            viewData.setUserBlocked(true);
        }
    }
    viewData.getChangePasswordForm().resetPasswordsAndUserName();
    return viewData;
}
Also used : ChangePasswordFormValidator(org.motechproject.server.web.validator.ChangePasswordFormValidator) MotechUserProfile(org.motechproject.security.domain.MotechUserProfile) LockedException(org.springframework.security.authentication.LockedException) PasswordValidatorException(org.motechproject.security.exception.PasswordValidatorException) ChangePasswordViewData(org.motechproject.server.web.dto.ChangePasswordViewData) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

PasswordValidatorException (org.motechproject.security.exception.PasswordValidatorException)7 Test (org.junit.Test)6 UserDto (org.motechproject.security.model.UserDto)2 Locale (java.util.Locale)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 MotechUser (org.motechproject.security.domain.MotechUser)1 MotechUserProfile (org.motechproject.security.domain.MotechUserProfile)1 PasswordValidator (org.motechproject.security.validator.PasswordValidator)1 ChangePasswordViewData (org.motechproject.server.web.dto.ChangePasswordViewData)1 ChangePasswordFormValidator (org.motechproject.server.web.validator.ChangePasswordFormValidator)1 LockedException (org.springframework.security.authentication.LockedException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1