use of org.motechproject.security.validator.PasswordValidator in project motech by motech.
the class MinLengthValidatorDecoratorTest method shouldValidateLength.
@Test(expected = PasswordTooShortException.class)
public void shouldValidateLength() {
PasswordValidator decoratedValidator = new MinLengthValidatorDecorator(validator, 3);
decoratedValidator.validate("eh");
}
use of org.motechproject.security.validator.PasswordValidator in project motech by motech.
the class MotechUserServiceImpl method validatePassword.
@Override
public void validatePassword(String password) {
PasswordValidator validator = settingService.getPasswordValidator();
validator.validate(password);
}
use of org.motechproject.security.validator.PasswordValidator in project motech by motech.
the class SettingServiceImpl method getPasswordValidator.
@Override
public PasswordValidator getPasswordValidator() {
MotechSettings motechSettings = configurationService.getPlatformSettings();
String validatorName = motechSettings.getPasswordValidator();
PasswordValidator validator = null;
if (StringUtils.isNotBlank(validatorName)) {
LOGGER.debug("No password validator configured");
validator = passwordValidatorManager.getValidator(validatorName);
}
if (validator == null) {
validator = passwordValidatorManager.noneValidator();
}
// if min pass length configured, then decorate the validator
int minPassLength = getMinPasswordLength();
if (minPassLength > 0) {
validator = new MinLengthValidatorDecorator(validator, minPassLength);
}
return validator;
}
use of org.motechproject.security.validator.PasswordValidator in project motech by motech.
the class MinLengthValidatorDecoratorTest method shouldThrowExceptionFromInnerValidator.
@Test(expected = PasswordValidatorException.class)
public void shouldThrowExceptionFromInnerValidator() {
PasswordValidator decoratedValidator = new MinLengthValidatorDecorator(validator, 3);
doThrow(new PasswordValidatorException("wrong")).when(validator).validate("password");
decoratedValidator.validate("password");
}
use of org.motechproject.security.validator.PasswordValidator in project motech by motech.
the class MinLengthValidatorDecoratorTest method shouldAcceptValidLength.
@Test
public void shouldAcceptValidLength() {
PasswordValidator decoratedValidator = new MinLengthValidatorDecorator(validator, 3);
decoratedValidator.validate("pass");
verify(validator).validate("pass");
decoratedValidator = new MinLengthValidatorDecorator(validator, 0);
decoratedValidator.validate("p");
verify(validator).validate("pass");
}
Aggregations