@ConditionalOnMissingBean(name = "configurationPropertiesEnvironmentManager") @Bean public CasConfigurationPropertiesEnvironmentManager configurationPropertiesEnvironmentManager() { return new CasConfigurationPropertiesEnvironmentManager(binder, environment); } }
/** * Rebind cas configuration properties. * * @param applicationContext the application context */ public void rebindCasConfigurationProperties(final ApplicationContext applicationContext) { rebindCasConfigurationProperties(this.binder, applicationContext); }
/** * 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; }
private void watchConfigurationDirectoryIfNeeded() { val configDirectory = configurationPropertiesEnvironmentManager.getStandaloneProfileConfigurationDirectory(); if (configDirectory != null && configDirectory.exists()) { LOGGER.debug("Starting to watch configuration directory [{}]", configDirectory); this.configurationDirectoryWatch = new PathWatcherService(configDirectory.toPath(), createConfigurationCreatedEvent.andNext(eventPublisher::publishEvent), createConfigurationModifiedEvent.andNext(eventPublisher::publishEvent), createConfigurationDeletedEvent.andNext(eventPublisher::publishEvent)); configurationDirectoryWatch.start(configDirectory.getName()); } }
private void watchConfigurationFileIfNeeded() { val configFile = configurationPropertiesEnvironmentManager.getStandaloneProfileConfigurationFile(); if (configFile != null && configFile.exists()) { LOGGER.debug("Starting to watch configuration file [{}]", configFile); this.configurationFileWatch = new FileWatcherService(configFile, createConfigurationCreatedEvent.andNext(eventPublisher::publishEvent), createConfigurationModifiedEvent.andNext(eventPublisher::publishEvent), createConfigurationDeletedEvent.andNext(eventPublisher::publishEvent)); configurationFileWatch.start(configFile.getName()); } }
/** * 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 application.properties, cas.properties, CAS.properties so that * the profiles will override the base properties. * Profiles are processed in order so that the last profile list (e.g. in spring.active.profiles) will override the * the first profile. * Where multiple filenames with same base name and different extensions exist, the priority is yaml, yml, properties. */ private List<File> getAllPossibleExternalConfigDirFilenames(final File configDirectory, final List<String> profiles) { val applicationName = casConfigurationPropertiesEnvironmentManager.getApplicationName(); val appNameLowerCase = applicationName.toLowerCase(); val fileNames = CollectionUtils.wrapList("application", appNameLowerCase, applicationName) .stream() .distinct() .flatMap(appName -> EXTENSIONS .stream() .map(ext -> new File(configDirectory, String.format("%s.%s", appName, ext)))) .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))))).collect(Collectors.toList())); fileNames.add(new File(configDirectory, appNameLowerCase.concat(".groovy"))); return fileNames; }
@SneakyThrows public void runNativeConfigurationDirectoryPathWatchService() { final File config = configurationPropertiesEnvironmentManager.getStandaloneProfileConfigurationDirectory(); if (casProperties.getEvents().isTrackConfigurationModifications() && config.exists()) { LOGGER.debug("Starting to watch configuration directory [{}]", config); final PathWatcherService watcher = new PathWatcherService(config.toPath(), createConfigurationCreatedEvent.andNext(publish), createConfigurationModifiedEvent.andNext(publish), createConfigurationDeletedEvent.andNext(publish)); watcher.start(config.getName()); } else { LOGGER.info("CAS is configured to NOT watch configuration directory [{}]. Changes require manual reloads/restarts.", config); } } }
@ConditionalOnMissingBean(name = "casManagementConfigurationPropertiesEnvironmentManager") @Bean public CasConfigurationPropertiesEnvironmentManager casManagementConfigurationPropertiesEnvironmentManager() { return new CasConfigurationPropertiesEnvironmentManager(binder, environment); } }
private void rebind() { LOGGER.info("Refreshing CAS configuration. Stand by..."); if (configurationPropertiesEnvironmentManager != null) { configurationPropertiesEnvironmentManager.rebindCasConfigurationProperties(this.applicationContext); } else { CasConfigurationPropertiesEnvironmentManager.rebindCasConfigurationProperties(this.binder, this.applicationContext); } } }
@ConditionalOnMissingBean(name = "casManagementConfigurationPropertiesEnvironmentManager") @Bean public CasConfigurationPropertiesEnvironmentManager casManagementConfigurationPropertiesEnvironmentManager() { return new CasConfigurationPropertiesEnvironmentManager(binder, environment); } }