public void validateParameters()

in src/java/org/apache/cassandra/db/guardrails/CassandraPasswordConfiguration.java [160:277]


    public void validateParameters() throws ConfigurationException
    {
        if (maxLength < 0) throw mustBePositiveException(MAX_LENGTH_KEY);
        if (characteristicsWarn < 0) throw mustBePositiveException(CHARACTERISTIC_WARN_KEY);
        if (characteristicsFail < 0) throw mustBePositiveException(CHARACTERISTIC_FAIL_KEY);
        if (lowerCaseWarn < 0) throw mustBePositiveException(LOWER_CASE_WARN_KEY);
        if (lowerCaseFail < 0) throw mustBePositiveException(LOWER_CASE_FAIL_KEY);
        if (upperCaseWarn < 0) throw mustBePositiveException(UPPER_CASE_WARN_KEY);
        if (upperCaseFail < 0) throw mustBePositiveException(UPPER_CASE_FAIL_KEY);
        if (specialsWarn < 0) throw mustBePositiveException(SPECIAL_WARN_KEY);
        if (specialsFail < 0) throw mustBePositiveException(SPECIAL_FAIL_KEY);
        if (digitsWarn < 0) throw mustBePositiveException(DIGIT_WARN_KEY);
        if (digitsFail < 0) throw mustBePositiveException(DIGIT_FAIL_KEY);
        if (lengthWarn < 0) throw mustBePositiveException(LENGTH_WARN_KEY);
        if (lengthFail < 0) throw mustBePositiveException(LENGTH_FAIL_KEY);

        if (maxLength <= lengthWarn)
            throw getValidationException(MAX_LENGTH_KEY, maxLength, LENGTH_WARN_KEY, lengthWarn);

        if (lengthWarn <= lengthFail)
            throw getValidationException(LENGTH_WARN_KEY, lengthWarn, LENGTH_FAIL_KEY, lengthFail);

        if (specialsWarn <= specialsFail)
            throw getValidationException(SPECIAL_WARN_KEY,
                                         specialsWarn,
                                         SPECIAL_FAIL_KEY,
                                         specialsFail);

        if (digitsWarn <= digitsFail)
            throw getValidationException(DIGIT_WARN_KEY,
                                         digitsWarn,
                                         DIGIT_FAIL_KEY,
                                         digitsFail);

        if (upperCaseWarn <= upperCaseFail)
            throw getValidationException(UPPER_CASE_WARN_KEY,
                                         upperCaseWarn,
                                         UPPER_CASE_FAIL_KEY,
                                         upperCaseFail);

        if (lowerCaseWarn <= lowerCaseFail)
            throw getValidationException(LOWER_CASE_WARN_KEY,
                                         lowerCaseWarn,
                                         LOWER_CASE_FAIL_KEY,
                                         lowerCaseFail);

        if (illegalSequenceLength < IllegalSequenceRule.MINIMUM_SEQUENCE_LENGTH)
            throw new ConfigurationException(format("Illegal sequence length can not be lower than %s.",
                                                    IllegalSequenceRule.MINIMUM_SEQUENCE_LENGTH));

        if (characteristicsWarn > 4)
            throw new ConfigurationException(format("%s can not be bigger than %s",
                                                    CHARACTERISTIC_WARN_KEY,
                                                    MAX_CHARACTERISTICS));

        if (characteristicsFail > 4)
            throw new ConfigurationException(format("%s can not be bigger than %s",
                                                    CHARACTERISTIC_FAIL_KEY,
                                                    MAX_CHARACTERISTICS));

        if (characteristicsFail == characteristicsWarn)
            throw new ConfigurationException(format("%s can not be equal to %s. You set %s and %s respectively.",
                                                    CHARACTERISTIC_FAIL_KEY,
                                                    CHARACTERISTIC_WARN_KEY,
                                                    characteristicsFail,
                                                    characteristicsWarn));

        if (characteristicsFail > characteristicsWarn)
            throw new ConfigurationException(format("%s can not be bigger than %s. You have set %s and %s respectively.",
                                                    CHARACTERISTIC_FAIL_KEY,
                                                    CHARACTERISTIC_WARN_KEY,
                                                    characteristicsFail,
                                                    characteristicsWarn));

        int[] minimumLengthsWarn = new int[]{ specialsWarn, digitsWarn,
                                              upperCaseWarn, lowerCaseWarn };
        Arrays.sort(minimumLengthsWarn);

        int minimumLenghtOfWarnCharacteristics = 0;
        for (int i = 0; i < characteristicsWarn; i++)
            minimumLenghtOfWarnCharacteristics += minimumLengthsWarn[i];

        if (minimumLenghtOfWarnCharacteristics > lengthWarn)
            throw new ConfigurationException(format("The shortest password to pass the warning validator for any %s " +
                                                    "characteristics out of %s is %s but you have set the %s to %s.",
                                                    characteristicsWarn,
                                                    MAX_CHARACTERISTICS,
                                                    minimumLenghtOfWarnCharacteristics,
                                                    LENGTH_WARN_KEY,
                                                    lengthWarn));

        int[] minimumLengthsFail = new int[]{ specialsFail, digitsFail,
                                              upperCaseFail, lowerCaseFail };
        Arrays.sort(minimumLengthsFail);

        int minimumLenghtOfFailCharacteristics = 0;
        for (int i = 0; i < characteristicsFail; i++)
            minimumLenghtOfFailCharacteristics += minimumLengthsFail[i];

        if (minimumLenghtOfFailCharacteristics > lengthFail)
            throw new ConfigurationException(format("The shortest password to pass the failing validator for any %s " +
                                                    "characteristics out of %s is %s but you have set the %s to %s.",
                                                    characteristicsFail,
                                                    MAX_CHARACTERISTICS,
                                                    minimumLenghtOfFailCharacteristics,
                                                    LENGTH_FAIL_KEY,
                                                    lengthFail));

        if (dictionary != null)
        {
            File dictionaryFile = new File(dictionary);
            if (!dictionaryFile.exists())
                throw new ConfigurationException(format("Dictionary file %s does not exist.", dictionary));

            if (!dictionaryFile.isReadable())
                throw new ConfigurationException(format("Dictionary file %s is not readable.", dictionary));
        }
    }