CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apereo-cas--cas-server-core-configuration-api

Apereo CAS Core Configuration API providing configuration management and property source location capabilities for the Central Authentication Service

Pending
Overview
Eval results
Files

property-source-location.mddocs/

Property Source Location

Core functionality for locating and loading configuration properties from multiple sources with defined precedence order. The property source location system supports standalone files, configuration directories, classpath resources, system properties, environment variables, and Docker secrets integration.

Capabilities

Core Property Source Locator Interface

Primary interface for discovering configuration properties from various sources with defined precedence handling.

@FunctionalInterface
public interface CasConfigurationPropertiesSourceLocator {
    /**
     * Locate property sources for CAS via the given environment and other resources.
     *
     * @param environment    the environment
     * @param resourceLoader the resource loader
     * @return the property source
     */
    Optional<PropertySource<?>> locate(Environment environment, ResourceLoader resourceLoader);
}

Static Utility Methods

public interface CasConfigurationPropertiesSourceLocator {
    /**
     * Gets standalone profile configuration directory.
     *
     * @param environment the environment
     * @return the standalone profile configuration directory
     */
    static File getStandaloneProfileConfigurationDirectory(Environment environment);
    
    /**
     * Gets standalone profile configuration file.
     *
     * @param environment the environment
     * @return the standalone profile configuration file
     */
    static File getStandaloneProfileConfigurationFile(Environment environment);
    
    /**
     * Gets application name.
     *
     * @param environment the environment
     * @return the application name
     */
    static String getApplicationName(Environment environment);
    
    /**
     * Gets configuration name.
     *
     * @param environment the environment
     * @return the configuration name
     */
    static String getConfigurationName(Environment environment);
    
    /**
     * Gets configuration properties loaders using ServiceLoader.
     *
     * @return the configuration properties loaders
     */
    static List<CasConfigurationPropertiesLoader> getConfigurationPropertiesLoaders();
}

Default Property Source Locator

Standard implementation that locates properties from multiple sources with defined precedence order: system properties → configuration files → classpath resources.

public class DefaultCasConfigurationPropertiesSourceLocator implements CasConfigurationPropertiesSourceLocator {
    /**
     * Constructor with cipher executor for encryption support.
     *
     * @param casConfigurationCipherExecutor the cipher executor
     */
    public DefaultCasConfigurationPropertiesSourceLocator(CipherExecutor<String, String> casConfigurationCipherExecutor);
    
    /**
     * Locate configuration property sources with precedence handling.
     *
     * @param environment    the environment
     * @param resourceLoader the resource loader
     * @return composite property source
     */
    @Override
    public Optional<PropertySource<?>> locate(Environment environment, ResourceLoader resourceLoader);
    
    /**
     * Load embedded properties from classpath resources.
     *
     * @param resourceLoader the resource loader
     * @param environment    the environment
     * @return the property source
     */
    protected PropertySource<?> loadEmbeddedProperties(ResourceLoader resourceLoader, Environment environment);
}

Usage Example

import org.apereo.cas.configuration.DefaultCasConfigurationPropertiesSourceLocator;
import org.apereo.cas.configuration.support.CasConfigurationJasyptCipherExecutor;

// Create cipher executor
CasConfigurationJasyptCipherExecutor cipherExecutor = 
    new CasConfigurationJasyptCipherExecutor(environment);

// Create default locator
DefaultCasConfigurationPropertiesSourceLocator locator = 
    new DefaultCasConfigurationPropertiesSourceLocator(cipherExecutor);

// Locate properties with precedence handling
Optional<PropertySource<?>> properties = locator.locate(environment, resourceLoader);

Standalone Configuration File Locator

High-precedence locator for standalone configuration files specified via environment properties.

@Order(Ordered.HIGHEST_PRECEDENCE)
public class StandaloneConfigurationFilePropertiesSourceLocator implements CasConfigurationPropertiesSourceLocator {
    /**
     * Constructor with cipher executor.
     *
     * @param casConfigurationCipherExecutor the cipher executor
     */
    public StandaloneConfigurationFilePropertiesSourceLocator(CipherExecutor<String, String> casConfigurationCipherExecutor);
    
    /**
     * Locate standalone configuration file properties.
     *
     * @param environment    the environment
     * @param resourceLoader the resource loader
     * @return the property source if standalone file exists
     */
    @Override
    public Optional<PropertySource<?>> locate(Environment environment, ResourceLoader resourceLoader);
}

Usage Example

// Create standalone file locator (highest precedence)
StandaloneConfigurationFilePropertiesSourceLocator standaloneLocator = 
    new StandaloneConfigurationFilePropertiesSourceLocator(cipherExecutor);

// Will only return properties if cas.standalone.configuration-file is set
Optional<PropertySource<?>> standaloneProps = standaloneLocator.locate(environment, resourceLoader);

Docker Secrets Property Source Locator

Locator for Docker secrets when running in containerized environments.

public class DockerSecretsPropertySourceLocator implements CasConfigurationPropertiesSourceLocator {
    /**
     * Locate Docker secrets as property source.
     *
     * @param environment    the environment
     * @param resourceLoader the resource loader
     * @return property source with secrets
     */
    @Override
    public Optional<PropertySource<?>> locate(Environment environment, ResourceLoader resourceLoader);
    
    /**
     * Load all Docker secrets from secrets directory.
     *
     * @return map of secret names and values
     */
    protected Map<String, Object> loadSecrets();
}

Usage Example

// Set environment variable to enable Docker secrets
System.setProperty("CONTAINER", "true");

// Create Docker secrets locator
DockerSecretsPropertySourceLocator dockerLocator = new DockerSecretsPropertySourceLocator();

// Load secrets from /run/secrets/ directory
Optional<PropertySource<?>> dockerSecrets = dockerLocator.locate(environment, resourceLoader);

Configuration File Discovery

The system automatically discovers configuration files based on application name, configuration name, active profiles, and file extensions.

File Discovery Pattern

// Base configuration files (in order of precedence)
String[] baseFiles = {
    "application.yml", "application.yaml", "application.properties",
    "cas.yml", "cas.yaml", "cas.properties",
    "CAS.yml", "CAS.yaml", "CAS.properties"
};

// Profile-specific files
String[] profilePatterns = {
    "application-{profile}.{extension}",
    "{profile}.{extension}",
    "{appName}-{profile}.{extension}"
};

Supported File Extensions

  • .yml - YAML format (highest precedence)
  • .yaml - YAML format
  • .properties - Java Properties format
  • .groovy - Groovy configuration scripts

Constants

// Bean name for bootstrap property locator
String BOOTSTRAP_PROPERTY_LOCATOR_BEAN_NAME = "casCoreBootstrapPropertySourceLocator";

// Property names for configuration paths
String PROPERTY_CAS_STANDALONE_CONFIGURATION_FILE = "cas.standalone.configuration-file";
String PROPERTY_CAS_STANDALONE_CONFIGURATION_DIRECTORY = "cas.standalone.configuration-directory";

// Default configuration directories (checked in order)
List<File> DEFAULT_CAS_CONFIG_DIRECTORIES = List.of(
    new File("/etc/cas/config"),
    new File("/opt/cas/config"),
    new File("/var/cas/config")
);

// Configuration profiles
String PROFILE_STANDALONE = "standalone";
String PROFILE_NATIVE = "native";
String PROFILE_EMBEDDED = "embedded";
String PROFILE_NONE = "none";

// Docker secrets configuration
String DEFAULT_SECRETS_DIR = "/run/secrets/";
String VAR_CAS_DOCKER_SECRETS_DIRECTORY = "CAS_DOCKER_SECRETS_DIRECTORY";
String VAR_CONTAINER = "CONTAINER";

Property Source Precedence Order

  1. System Properties and Environment Variables (highest precedence)
  2. Standalone Configuration File (if specified via cas.standalone.configuration-file)
  3. Configuration Directory Files (profile-specific override base configurations)
  4. Docker Secrets (when CONTAINER=true)
  5. Embedded Classpath Resources (lowest precedence)

Within each category, profile-specific configurations override base configurations, and later profiles override earlier profiles.

Install with Tessl CLI

npx tessl i tessl/maven-org-apereo-cas--cas-server-core-configuration-api

docs

configuration-encryption.md

configuration-loading.md

configuration-management.md

configuration-watching.md

index.md

property-source-location.md

tile.json