@ConditionalOnMissingBean(name = "casConfigurationPropertiesSourceLocator") @Bean public CasConfigurationPropertiesSourceLocator casConfigurationPropertiesSourceLocator() { return new DefaultCasConfigurationPropertiesSourceLocator( configurationPropertiesEnvironmentManager.getIfAvailable(), configurationPropertiesLoaderFactory()); }
/** * Get all possible configuration files for config directory that actually exist as files. * * @param config Folder in which to look for files * @param profiles Profiles that are active * @return List of files to be processed in order where last one processed overrides others */ private List<Resource> scanForConfigurationResources(final File config, final List<String> profiles) { val possibleFiles = getAllPossibleExternalConfigDirFilenames(config, profiles); return possibleFiles.stream() .filter(File::exists) .filter(File::isFile) .map(FileSystemResource::new) .collect(Collectors.toList()); }
/** * Adding items to composite property source which contains property sources processed in order, first one wins. * First Priority: Standalone configuration file * Second Priority: Configuration files in config dir, profiles override non-profiles, last profile overrides first * Third Priority: classpath:/application.yml * * @param environment the environment * @param resourceLoader the resource loader * @return CompositePropertySource containing sources listed above */ @Override public PropertySource<?> locate(final Environment environment, final ResourceLoader resourceLoader) { val compositePropertySource = new CompositePropertySource("casCompositePropertySource"); val configFile = casConfigurationPropertiesEnvironmentManager.getStandaloneProfileConfigurationFile(); if (configFile != null) { val sourceStandalone = loadSettingsFromStandaloneConfigFile(environment, configFile); compositePropertySource.addPropertySource(sourceStandalone); } val config = casConfigurationPropertiesEnvironmentManager.getStandaloneProfileConfigurationDirectory(); LOGGER.debug("Located CAS standalone configuration directory at [{}]", config); if (config != null && config.isDirectory() && config.exists()) { val sourceProfiles = loadSettingsByApplicationProfiles(environment, config); compositePropertySource.addPropertySource(sourceProfiles); } else { LOGGER.info("Configuration directory [{}] is not a directory or cannot be found at the specific path", config); } val sourceYaml = loadEmbeddedYamlOverriddenProperties(resourceLoader); compositePropertySource.addPropertySource(sourceYaml); return compositePropertySource; }
/** * Property files processed in order of non-profiles first and then profiles, and profiles are first to last * with properties in the last profile overriding properties in previous profiles or non-profiles. * * @param environment Spring environment * @param config Location of config files * @return Merged properties */ private PropertySource<?> loadSettingsByApplicationProfiles(final Environment environment, final File config) { val profiles = ConfigurationPropertiesLoaderFactory.getApplicationProfiles(environment); val resources = scanForConfigurationResources(config, profiles); val composite = new CompositePropertySource("applicationProfilesCompositeProperties"); LOGGER.info("Configuration files found at [{}] are [{}] under profile(s) [{}]", config, resources, profiles); resources.forEach(Unchecked.consumer(f -> { LOGGER.debug("Loading configuration file [{}]", f); val loader = configurationPropertiesLoaderFactory.getLoader(f, "applicationProfilesProperties-" + f.getFilename()); composite.addFirstPropertySource(loader.load()); })); return composite; }
@ConditionalOnMissingBean(name = "casManagementConfigurationPropertiesSourceLocator") @Bean public CasConfigurationPropertiesSourceLocator casManagementConfigurationPropertiesSourceLocator() { return new DefaultCasConfigurationPropertiesSourceLocator(casManagementConfigurationCipherExecutor(), casManagementConfigurationPropertiesEnvironmentManager()); }
@ConditionalOnMissingBean(name = "casManagementConfigurationPropertiesSourceLocator") @Bean public CasConfigurationPropertiesSourceLocator casManagementConfigurationPropertiesSourceLocator() { return new DefaultCasConfigurationPropertiesSourceLocator(casManagementConfigurationCipherExecutor(), casManagementConfigurationPropertiesEnvironmentManager()); }