private static List<File> getAllPossibleExternalConfigDirFilenames(
        final Environment environment,
        final File configDirectory,
        final List<String> profiles) {
        val applicationName = CasConfigurationPropertiesSourceLocator.getApplicationName(environment);
        val configName = CasConfigurationPropertiesSourceLocator.getConfigurationName(environment);
        val appNameLowerCase = applicationName.toLowerCase(Locale.ENGLISH);
        val appConfigNames = CollectionUtils.wrapList("application", appNameLowerCase, applicationName, configName);

        val fileNames = appConfigNames
            .stream()
            .distinct()
            .flatMap(appName -> EXTENSIONS
                .stream()
                .map(ext -> new File(configDirectory, String.format("%s.%s", appName, ext))))
            .filter(File::exists)
            .collect(Collectors.toList());

        fileNames.addAll(profiles
            .stream()
            .flatMap(profile -> EXTENSIONS
                .stream()
                .flatMap(ext -> PROFILE_PATTERNS
                    .stream().map(pattern -> new File(configDirectory, String.format(pattern, profile, ext)))))
            .filter(File::exists).toList());

        fileNames.addAll(profiles
            .stream()
            .map(profile -> EXTENSIONS
                .stream()
                .map(ext -> appConfigNames
                    .stream()
                    .map(appName -> new File(configDirectory, String.format("%s-%s.%s", appName, profile, ext)))
                    .filter(File::exists)
                    .collect(Collectors.toList()))
                .flatMap(List::stream)
                .collect(Collectors.toList()))
            .flatMap(List::stream)
            .toList());

        val groovyFile = new File(configDirectory, appNameLowerCase.concat(".groovy"));
        FunctionUtils.doIf(groovyFile.exists(), o -> fileNames.add(groovyFile)).accept(groovyFile);
        return fileNames;
    }
Make a list of files that will be processed in order where the last one processed wins.
Profiles are added after base property names like {@code application.properties}, {@code cas.properties},
{@code CAS.properties} so that the profiles will override the base properties.
<p>
Profiles are processed in order so that the last profile list (e.g. in {@code spring.active.profiles}) will override the
the first profile.
<p>
Where multiple filenames with same base name and different extensions exist, the priority is yaml, yml, properties.
core/cas-server-core-configuration-api/src/main/java/org/apereo/cas/configuration/DefaultCasConfigurationPropertiesSourceLocator.java