Search in sources :

Example 1 with CharacterRule

use of org.passay.CharacterRule in project credhub by cloudfoundry-incubator.

the class CharacterRuleProviderTest method getCharacterRules_canCreateCharacterRulesWithoutUppercase.

@Test
public void getCharacterRules_canCreateCharacterRulesWithoutUppercase() {
    StringGenerationParameters generationParameters = new StringGenerationParameters();
    generationParameters.setExcludeUpper(true);
    List<CharacterRule> characterRules = CharacterRuleProvider.getCharacterRules(generationParameters);
    assertThat(characterRules, iterableWithSize(2));
    assertThat(characterRules, containsInAnyOrder(usesCharacters(EnglishCharacterData.LowerCase), usesCharacters(EnglishCharacterData.Digit)));
    assertThat(characterRules, not(containsInAnyOrder(usesCharacters(EnglishCharacterData.UpperCase), usesCharacters(CredHubCharacterData.Special), usesCharacters(CredHubCharacterData.Hex))));
}
Also used : CharacterRule(org.passay.CharacterRule) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Test(org.junit.Test)

Example 2 with CharacterRule

use of org.passay.CharacterRule in project credhub by cloudfoundry-incubator.

the class CharacterRuleProviderTest method getCharacterRules_canCreateCharacterRulesWithoutSpecialCharacters.

@Test
public void getCharacterRules_canCreateCharacterRulesWithoutSpecialCharacters() {
    StringGenerationParameters generationParameters = new StringGenerationParameters();
    generationParameters.setIncludeSpecial(false);
    List<CharacterRule> characterRules = CharacterRuleProvider.getCharacterRules(generationParameters);
    assertThat(characterRules, iterableWithSize(3));
    assertThat(characterRules, containsInAnyOrder(usesCharacters(EnglishCharacterData.UpperCase), usesCharacters(EnglishCharacterData.LowerCase), usesCharacters(EnglishCharacterData.Digit)));
    assertThat(characterRules, not(hasItem(usesCharacters(CredHubCharacterData.Special))));
    assertThat(characterRules, not(hasItem(usesCharacters(CredHubCharacterData.Hex))));
}
Also used : CharacterRule(org.passay.CharacterRule) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Test(org.junit.Test)

Example 3 with CharacterRule

use of org.passay.CharacterRule in project dataverse by IQSS.

the class PasswordValidatorTest method getCharacterRulesHarvardLevel3.

public static List<CharacterRule> getCharacterRulesHarvardLevel3() {
    List<CharacterRule> characterRules = new ArrayList<>();
    characterRules.add(new CharacterRule(EnglishCharacterData.UpperCase, 1));
    characterRules.add(new CharacterRule(EnglishCharacterData.LowerCase, 1));
    characterRules.add(new CharacterRule(EnglishCharacterData.Digit, 1));
    characterRules.add(new CharacterRule(EnglishCharacterData.Special, 1));
    return characterRules;
}
Also used : ArrayList(java.util.ArrayList) CharacterRule(org.passay.CharacterRule)

Example 4 with CharacterRule

use of org.passay.CharacterRule in project dataverse by IQSS.

the class PasswordValidatorServiceBean method addStandardValidator.

/**
 * standardValidator
 * <p>
 * Apply Rules 1, 2 and 3.
 */
private void addStandardValidator() {
    int maxLength = getMaxLength();
    int minLength = getMinLength();
    int numberOfCharacteristics = getNumberOfCharacteristics();
    int numberOfConsecutiveDigitsAllowed = getNumberOfConsecutiveDigitsAllowed();
    PasswordValidator passwordValidator = validators.get(ValidatorTypes.StandardValidator);
    if (passwordValidator == null) {
        final List<Rule> rules = new ArrayList<>(4);
        rules.add(dictionarySubstringRule());
        final LengthRule lengthRule = new LengthRule();
        if (maxLength != 0) {
            lengthRule.setMaximumLength(maxLength);
        }
        if (minLength != 0) {
            lengthRule.setMinimumLength(minLength);
        }
        rules.add(lengthRule);
        if (numberOfCharacteristics != 0) {
            rules.add(characterRule(getCharacterRules()));
        }
        rules.add(repeatingDigitsRule(numberOfConsecutiveDigitsAllowed));
        passwordValidator = new PasswordValidator(messageResolver, rules);
        validators.put(ValidatorTypes.StandardValidator, passwordValidator);
    }
}
Also used : LengthRule(org.passay.LengthRule) PasswordValidator(org.passay.PasswordValidator) ArrayList(java.util.ArrayList) DictionaryRule(org.passay.DictionaryRule) CharacterRule(org.passay.CharacterRule) IllegalRegexRule(org.passay.IllegalRegexRule) CharacterCharacteristicsRule(org.passay.CharacterCharacteristicsRule) Rule(org.passay.Rule) DictionarySubstringRule(org.passay.DictionarySubstringRule) LengthRule(org.passay.LengthRule)

Example 5 with CharacterRule

use of org.passay.CharacterRule in project dataverse by IQSS.

the class PasswordValidatorUtil method getCharacterRulesDefault.

/**
 * The default out-of-the-box character rules for Dataverse.
 */
public static List<CharacterRule> getCharacterRulesDefault() {
    List<CharacterRule> characterRules = new ArrayList<>();
    characterRules.add(new CharacterRule(EnglishCharacterData.Alphabetical, 1));
    characterRules.add(new CharacterRule(EnglishCharacterData.Digit, 1));
    return characterRules;
}
Also used : ArrayList(java.util.ArrayList) CharacterRule(org.passay.CharacterRule)

Aggregations

CharacterRule (org.passay.CharacterRule)14 Test (org.junit.Test)8 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)7 ArrayList (java.util.ArrayList)4 Date (java.util.Date)1 CharacterCharacteristicsRule (org.passay.CharacterCharacteristicsRule)1 DictionaryRule (org.passay.DictionaryRule)1 DictionarySubstringRule (org.passay.DictionarySubstringRule)1 EnglishCharacterData (org.passay.EnglishCharacterData)1 IllegalRegexRule (org.passay.IllegalRegexRule)1 LengthRule (org.passay.LengthRule)1 PasswordGenerator (org.passay.PasswordGenerator)1 PasswordValidator (org.passay.PasswordValidator)1 Rule (org.passay.Rule)1