ifs-data-layer/ifs-data-service/src/main/java/org/innovateuk/ifs/authentication/validator/PasswordPolicyValidator.java
/**
     * This method, given a user, their chosen password, an exclusion rule (e.g. no full names) and a pattern generator, will
     * check for the presence of excluded tokens (in different orders as well if, for instance, checking for more than one word
     * for a single rule, like in the case of full name (that uses "first name" and "last name" in combination)).
     *
     * @param password
     * @param rule
     * @param patternGenerator
     * @param excludedWords
     * @return
     */
This method, given a user, their chosen password, an exclusion rule  and a pattern generator, will
check for the presence of excluded tokens (in different orders as well if, for instance, checking for more than one word
for a single rule, like in the case of full name (that uses "first name" and "last name" in combination)).


This method given a user their chosen password an exclusion rule and a pattern generator will check for the presence of excluded tokens ( in different orders as well if for instance checking for more than one word for a single rule like in the case of full name ( that uses " first name " and " last name " in combination )) .
private ServiceResult<Void> checkForExclusionWordsWithinPassword(String password, ExclusionRule rule, ExclusionRulePatternGenerator patternGenerator, List<String> excludedWords) {
        int lengthOfAllWords = excludedWords.stream().collect(summingInt(String::length));
        if (lengthOfAllWords < rule.lengthThresholdForRuleToApply) {
            return serviceSuccess();
        }
        List<List<String>> permutations = findPermutations(excludedWords);
        List<String> permutationsAsRegexes = simpleMap(permutations, permutation -> ".*" + simpleJoiner(permutation, ".*") + ".*");
        String permutationsAsSingleRegex = simpleJoiner(permutationsAsRegexes, "|");
        List<Pattern> exclusionPatterns = patternGenerator.apply(permutationsAsSingleRegex);
        boolean excluded = exclusionPatterns.stream().anyMatch(pattern -> pattern.matcher(password).matches());
        return excluded ? serviceFailure(new Error(rule.errorKey, BAD_REQUEST)) : serviceSuccess();
    }
private ServiceResult < Void > checkForExclusionWordsWithinPassword ( String password , ExclusionRule rule , ExclusionRulePatternGenerator patternGenerator , List < String > excludedWords ) { int lengthOfAllWords = excludedWords . stream ( ) . collect ( summingInt ( String :: length ) ) ; if ( lengthOfAllWords < rule . lengthThresholdForRuleToApply ) { return serviceSuccess ( ) ; } List < List < String > > permutations = findPermutations ( excludedWords ) ; List < String > permutationsAsRegexes = simpleMap ( permutations , permutation -> ".*" + simpleJoiner ( permutation , ".*" ) + ".*" ) ; String permutationsAsSingleRegex = simpleJoiner ( permutationsAsRegexes , "|" ) ; List < Pattern > exclusionPatterns = patternGenerator . apply ( permutationsAsSingleRegex ) ; boolean excluded = exclusionPatterns . stream ( ) . anyMatch ( pattern -> pattern . matcher ( password ) . matches ( ) ) ; return excluded ? serviceFailure ( new Error ( rule . errorKey , BAD_REQUEST ) ) : serviceSuccess ( ) ; }
This method, given a user, their chosen password, an exclusion rule (e.g.
This method given a user their chosen password an exclusion rule ( e . g .