Apereo CAS Core Configuration API providing configuration management and property source location capabilities for the Central Authentication Service
—
File system monitoring service that watches configuration files and directories for changes, automatically publishing configuration events when modifications are detected. The watching service integrates with CAS event system and supports both file and directory monitoring.
Primary service for monitoring configuration files and directories with automatic event publishing on changes.
public class CasConfigurationWatchService implements Closeable, InitializingBean {
/**
* Constructor with application context for event publishing.
*
* @param applicationContext the configurable application context
*/
public CasConfigurationWatchService(ConfigurableApplicationContext applicationContext);
/**
* Initialize file and directory watchers based on environment configuration.
*/
public void initialize();
/**
* Close and cleanup all watch services.
*/
@Override
public void close();
/**
* InitializingBean callback method that calls initialize().
*/
@Override
public void afterPropertiesSet();
}import org.apereo.cas.configuration.CasConfigurationWatchService;
import org.springframework.context.ConfigurableApplicationContext;
// Create watch service with application context
CasConfigurationWatchService watchService =
new CasConfigurationWatchService(applicationContext);
// Initialize watchers (automatically called by afterPropertiesSet)
watchService.initialize();
// The service will now monitor:
// - Standalone configuration file (if specified)
// - Standalone configuration directory (if exists)
// Later, cleanup when shutting down
watchService.close();import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class WatchServiceConfiguration {
@Bean
public CasConfigurationWatchService casConfigurationWatchService(
ConfigurableApplicationContext applicationContext) {
// Spring will automatically call afterPropertiesSet() after bean creation
return new CasConfigurationWatchService(applicationContext);
}
}// Create and configure watch service
CasConfigurationWatchService watchService =
new CasConfigurationWatchService(applicationContext);
// Manually initialize (normally done automatically)
watchService.initialize();
// Service is now monitoring for configuration changes
// At application shutdown
try {
watchService.close();
} catch (Exception e) {
logger.warn("Error closing configuration watch service", e);
}The watch service monitors the standalone configuration file when:
cas.standalone.configuration-file property is set// Set standalone configuration file
System.setProperty("cas.standalone.configuration-file", "/etc/cas/config/cas.properties");
// Watch service will monitor this specific file for:
// - Creation (if file is created after service starts)
// - Modification (content changes)
// - Deletion (if file is removed)The watch service monitors the configuration directory when:
cas.standalone.configuration-directory or defaults)// Set configuration directory
System.setProperty("cas.standalone.configuration-directory", "/etc/cas/config");
// Watch service will monitor the entire directory for:
// - New configuration files created
// - Existing configuration files modified
// - Configuration files deletedIf no specific directory is configured, the service checks default locations:
/etc/cas/config/opt/cas/config/var/cas/configThe first existing directory will be monitored.
The watch service publishes different event types based on file system changes:
// Event types published by the watch service
CasConfigurationCreatedEvent // When configuration files are created
CasConfigurationModifiedEvent // When configuration files are modified
CasConfigurationDeletedEvent // When configuration files are deletedimport org.apereo.cas.config.CasConfigurationModifiedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
@Component
public class ConfigurationChangeHandler {
@EventListener
public void handleConfigurationCreated(CasConfigurationCreatedEvent event) {
Path configPath = event.getFile();
System.out.println("Configuration file created: " + configPath);
// Handle new configuration file
}
@EventListener
public void handleConfigurationModified(CasConfigurationModifiedEvent event) {
Path configPath = event.getFile();
System.out.println("Configuration file modified: " + configPath);
// Reload configuration, restart services, etc.
}
@EventListener
public void handleConfigurationDeleted(CasConfigurationDeletedEvent event) {
Path configPath = event.getFile();
System.out.println("Configuration file deleted: " + configPath);
// Handle missing configuration
}
}Each configuration event includes:
CasConfigurationWatchService instanceClientInfoHolder (if available)The service uses CAS utility classes for file system monitoring:
// File watching for specific files
FileWatcherService configurationFileWatch = new FileWatcherService(
configFile,
createConfigurationCreatedEvent.andNext(applicationContext::publishEvent),
createConfigurationModifiedEvent.andNext(applicationContext::publishEvent),
createConfigurationDeletedEvent.andNext(applicationContext::publishEvent)
);
// Directory watching for configuration directories
PathWatcherService configurationDirectoryWatch = new PathWatcherService(
configDirectory.toPath(),
createConfigurationCreatedEvent.andNext(applicationContext::publishEvent),
createConfigurationModifiedEvent.andNext(applicationContext::publishEvent),
createConfigurationDeletedEvent.andNext(applicationContext::publishEvent)
);The service uses composable functions to create events:
// Function composition for event creation and publishing
ComposableFunction<File, AbstractCasEvent> createConfigurationCreatedEvent = file ->
new CasConfigurationCreatedEvent(this, file.toPath(), ClientInfoHolder.getClientInfo());
ComposableFunction<File, AbstractCasEvent> createConfigurationModifiedEvent = file ->
new CasConfigurationModifiedEvent(this, file.toPath(), ClientInfoHolder.getClientInfo());
ComposableFunction<File, AbstractCasEvent> createConfigurationDeletedEvent = file ->
new CasConfigurationDeletedEvent(this, file.toPath(), ClientInfoHolder.getClientInfo());The watch service behavior is controlled by these configuration properties:
# Standalone configuration file path
cas.standalone.configuration-file=/path/to/cas.properties
# Standalone configuration directory path
cas.standalone.configuration-directory=/etc/cas/config
# Profile settings that affect watching
spring.profiles.active=standaloneThe watch service respects CAS profiles:
none profile: Skips directory watching entirely// Profile "none" disables directory watching
System.setProperty("spring.profiles.active", "none");
// Directory watching will be skipped
// Standalone profile enables normal watching
System.setProperty("spring.profiles.active", "standalone");
// Normal file and directory watchingThe watch service handles various error conditions:
Install with Tessl CLI
npx tessl i tessl/maven-org-apereo-cas--cas-server-core-configuration-api