Search in sources :

Example 1 with PasswordValidator

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");
}
Also used : PasswordValidator(org.motechproject.security.validator.PasswordValidator) Test(org.junit.Test)

Example 2 with PasswordValidator

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);
}
Also used : PasswordValidator(org.motechproject.security.validator.PasswordValidator)

Example 3 with PasswordValidator

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;
}
Also used : MinLengthValidatorDecorator(org.motechproject.security.validator.impl.MinLengthValidatorDecorator) MotechSettings(org.motechproject.config.domain.MotechSettings) PasswordValidator(org.motechproject.security.validator.PasswordValidator)

Example 4 with PasswordValidator

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");
}
Also used : PasswordValidatorException(org.motechproject.security.exception.PasswordValidatorException) PasswordValidator(org.motechproject.security.validator.PasswordValidator) Test(org.junit.Test)

Example 5 with PasswordValidator

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");
}
Also used : PasswordValidator(org.motechproject.security.validator.PasswordValidator) Test(org.junit.Test)

Aggregations

PasswordValidator (org.motechproject.security.validator.PasswordValidator)6 Test (org.junit.Test)3 MotechSettings (org.motechproject.config.domain.MotechSettings)1 PasswordValidatorException (org.motechproject.security.exception.PasswordValidatorException)1 MinLengthValidatorDecorator (org.motechproject.security.validator.impl.MinLengthValidatorDecorator)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1