Apereo CAS Core Configuration API providing configuration management and property source location capabilities for the Central Authentication Service
—
Pluggable configuration loading system supporting multiple file formats with encryption/decryption capabilities. The loading system uses Java's ServiceLoader pattern for extensibility and supports YAML, Properties, and custom format loaders.
Base interface for all configuration property loaders with support for resource format detection and encrypted property handling.
public interface CasConfigurationPropertiesLoader extends NamedObject {
/**
* Load property source from resource.
*
* @param resource the resource
* @param environment the environment
* @param name the name
* @param configurationCipherExecutor the configuration cipher executor
* @return the property source
*/
PropertySource load(Resource resource, Environment environment, String name,
CipherExecutor<String, String> configurationCipherExecutor);
/**
* Check if this loader supports the given resource.
*
* @param resource the resource
* @return true if supported
*/
boolean supports(Resource resource);
}Abstract base class providing common functionality for all configuration loaders including property decryption and property source creation.
public abstract class BaseConfigurationPropertiesLoader implements CasConfigurationPropertiesLoader {
/**
* Default constructor.
*/
protected BaseConfigurationPropertiesLoader();
/**
* Decrypt properties using cipher executor.
*
* @param configurationCipherExecutor the configuration cipher executor
* @param properties the properties
* @return decrypted properties map
*/
protected Map<String, Object> decryptProperties(CipherExecutor<String, String> configurationCipherExecutor,
Map properties);
/**
* Create MapPropertySource from properties map.
*
* @param name the name
* @param properties the properties
* @return the property source
*/
protected PropertySource finalizeProperties(String name, Map properties);
/**
* Create PropertiesPropertySource from Properties object.
*
* @param name the name
* @param props the properties
* @return the property source
*/
protected PropertySource finalizeProperties(String name, Properties props);
/**
* Get active application profiles from environment.
*
* @param environment the environment
* @return list of active profiles
*/
protected List<String> getApplicationProfiles(Environment environment);
}Loads YAML configuration files (.yaml, .yml extensions) with support for multi-document YAML and nested properties.
public class YamlConfigurationPropertiesLoader extends BaseConfigurationPropertiesLoader {
/**
* Default constructor.
*/
public YamlConfigurationPropertiesLoader();
/**
* Load YAML resource as property source.
*
* @param resource the YAML resource
* @param environment the environment
* @param name property source name
* @param configurationCipherExecutor cipher executor for decryption
* @return property source with YAML properties
*/
@Override
public PropertySource load(Resource resource, Environment environment, String name,
CipherExecutor<String, String> configurationCipherExecutor);
/**
* Check if resource has .yaml or .yml extension.
*
* @param resource the resource
* @return true if YAML file
*/
@Override
public boolean supports(Resource resource);
}import org.apereo.cas.configuration.loader.YamlConfigurationPropertiesLoader;
import org.springframework.core.io.ClassPathResource;
// Create YAML loader
YamlConfigurationPropertiesLoader yamlLoader = new YamlConfigurationPropertiesLoader();
// Load YAML configuration
Resource yamlResource = new ClassPathResource("application.yml");
if (yamlLoader.supports(yamlResource)) {
PropertySource propertySource = yamlLoader.load(yamlResource, environment,
"yamlConfig", cipherExecutor);
}Loads Java Properties configuration files (.properties extension) with standard Properties format support.
public class SimpleConfigurationPropertiesLoader extends BaseConfigurationPropertiesLoader {
/**
* Default constructor.
*/
public SimpleConfigurationPropertiesLoader();
/**
* Load Properties resource as property source.
*
* @param resource the Properties resource
* @param environment the environment
* @param name property source name
* @param configurationCipherExecutor cipher executor for decryption
* @return property source with Properties
*/
@Override
public PropertySource load(Resource resource, Environment environment, String name,
CipherExecutor<String, String> configurationCipherExecutor);
/**
* Check if resource has .properties extension.
*
* @param resource the resource
* @return true if Properties file
*/
@Override
public boolean supports(Resource resource);
}import org.apereo.cas.configuration.loader.SimpleConfigurationPropertiesLoader;
import org.springframework.core.io.FileSystemResource;
// Create Properties loader
SimpleConfigurationPropertiesLoader propertiesLoader = new SimpleConfigurationPropertiesLoader();
// Load Properties configuration
Resource propsResource = new FileSystemResource("/etc/cas/config/application.properties");
if (propertiesLoader.supports(propsResource)) {
PropertySource propertySource = propertiesLoader.load(propsResource, environment,
"propertiesConfig", cipherExecutor);
}Configuration loaders are discovered automatically using Java's ServiceLoader mechanism, allowing for pluggable extension with custom loaders.
// Automatic discovery of all available loaders
List<CasConfigurationPropertiesLoader> loaders =
CasConfigurationPropertiesSourceLocator.getConfigurationPropertiesLoaders();
// Find appropriate loader for resource
CasConfigurationPropertiesLoader foundLoader = loaders.stream()
.filter(loader -> loader.supports(resource))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("No configuration loader found for " + resource));
// Load using discovered loader
PropertySource propertySource = foundLoader.load(resource, environment, name, cipherExecutor);Loaders determine file format support based on file extensions:
// YAML files
filename.endsWith(".yaml") || filename.endsWith(".yml")
// Properties files
filename.endsWith(".properties")
// Custom loaders can support additional formatsAll loaders automatically decrypt encrypted properties using the provided cipher executor:
// Properties with encrypted values are automatically decrypted
Map<String, Object> decryptedProperties = decryptProperties(configurationCipherExecutor, rawProperties);Loaders handle various error conditions gracefully:
# application.yml
cas:
server:
name: "My CAS Server"
prefix: "https://cas.example.org/cas"
# Encrypted properties
database:
password: "{cas-cipher}ENCRYPTED_VALUE_HERE"
# Profile-specific configuration
---
spring:
profiles: production
cas:
server:
name: "Production CAS Server"# application.properties
cas.server.name=My CAS Server
cas.server.prefix=https://cas.example.org/cas
# Encrypted properties
database.password={cas-cipher}ENCRYPTED_VALUE_HERE
# Profile-specific properties file: application-production.properties
cas.server.name=Production CAS ServerTo create custom configuration loaders, implement the interface and register via ServiceLoader:
public class CustomConfigurationLoader extends BaseConfigurationPropertiesLoader {
@Override
public boolean supports(Resource resource) {
return resource.getFilename().endsWith(".custom");
}
@Override
public PropertySource load(Resource resource, Environment environment, String name,
CipherExecutor<String, String> configurationCipherExecutor) {
// Custom loading logic
Map<String, Object> properties = loadCustomFormat(resource);
Map<String, Object> decrypted = decryptProperties(configurationCipherExecutor, properties);
return finalizeProperties(name, decrypted);
}
}Create file: META-INF/services/org.apereo.cas.configuration.loader.CasConfigurationPropertiesLoader
com.example.CustomConfigurationLoaderInstall with Tessl CLI
npx tessl i tessl/maven-org-apereo-cas--cas-server-core-configuration-api