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

configuration-management.mddocs/

Configuration Management

Runtime configuration management including property rebinding, environment configuration, and validation of configuration properties. The management system provides mechanisms for dynamic configuration updates and comprehensive validation reporting.

Capabilities

Configuration Properties Environment Manager

Primary manager for handling configuration property rebinding and environment setup during runtime configuration changes.

public class CasConfigurationPropertiesEnvironmentManager {
    /**
     * Constructor with configuration properties binding post processor.
     *
     * @param binder the configuration properties binding post processor
     */
    public CasConfigurationPropertiesEnvironmentManager(ConfigurationPropertiesBindingPostProcessor binder);
    
    /**
     * Rebind CAS configuration properties using instance binder.
     *
     * @param applicationContext the application context
     * @return the application context
     */
    public ApplicationContext rebindCasConfigurationProperties(ApplicationContext applicationContext);
}

Static Configuration Management Methods

public class CasConfigurationPropertiesEnvironmentManager {
    /**
     * Rebind CAS configuration properties using provided binder.
     *
     * @param binder             the configuration properties binding post processor
     * @param applicationContext the application context
     * @return the application context
     */
    public static ApplicationContext rebindCasConfigurationProperties(
        ConfigurationPropertiesBindingPostProcessor binder,
        ApplicationContext applicationContext);
    
    /**
     * Configure environment property sources with native composite source.
     *
     * @param environment the configurable environment
     * @return composite property source with native sources
     */
    public static CompositePropertySource configureEnvironmentPropertySources(ConfigurableEnvironment environment);
}

Configuration Properties Validator

Comprehensive validation system for CAS configuration properties that reports unbound and invalid property configurations.

public class CasConfigurationPropertiesValidator {
    /**
     * Constructor with application context.
     *
     * @param applicationContext the configurable application context
     */
    public CasConfigurationPropertiesValidator(ConfigurableApplicationContext applicationContext);
    
    /**
     * Validate CAS configuration properties and return validation results.
     *
     * @return list of validation error messages
     */
    public List<String> validate();
}

Usage Examples

Configuration Rebinding

import org.apereo.cas.configuration.CasConfigurationPropertiesEnvironmentManager;
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;

// Get the binding post processor from application context
ConfigurationPropertiesBindingPostProcessor binder = 
    applicationContext.getBean(ConfigurationPropertiesBindingPostProcessor.class);

// Create environment manager
CasConfigurationPropertiesEnvironmentManager manager = 
    new CasConfigurationPropertiesEnvironmentManager(binder);

// Rebind configuration properties after changes
ApplicationContext updatedContext = manager.rebindCasConfigurationProperties(applicationContext);

Static Configuration Rebinding

// Static method approach for one-time rebinding
ApplicationContext updatedContext = CasConfigurationPropertiesEnvironmentManager
    .rebindCasConfigurationProperties(binder, applicationContext);

// Verify rebinding was successful
CasConfigurationProperties config = updatedContext.getBean(CasConfigurationProperties.class);
System.out.println("Configuration rebound: " + config.getClass().getName());

Environment Property Sources Configuration

import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.CompositePropertySource;

// Configure native property sources for environment
ConfigurableEnvironment environment = (ConfigurableEnvironment) applicationContext.getEnvironment();
CompositePropertySource nativeSource = CasConfigurationPropertiesEnvironmentManager
    .configureEnvironmentPropertySources(environment);

// Native source includes:
// - commandLineArgs (if present)
// - systemProperties
// - systemEnvironment

Configuration Validation

import org.apereo.cas.configuration.CasConfigurationPropertiesValidator;

// Create validator with application context
CasConfigurationPropertiesValidator validator = 
    new CasConfigurationPropertiesValidator(applicationContext);

// Validate all CAS configuration properties
List<String> validationResults = validator.validate();

if (validationResults.isEmpty()) {
    System.out.println("Configuration validation passed successfully");
} else {
    System.err.println("Configuration validation failed:");
    validationResults.forEach(System.err::println);
}

Complete Configuration Management Workflow

import org.apereo.cas.configuration.CasConfigurationPropertiesEnvironmentManager;
import org.apereo.cas.configuration.CasConfigurationPropertiesValidator;

// Step 1: Configure environment property sources
ConfigurableEnvironment environment = (ConfigurableEnvironment) applicationContext.getEnvironment();
CompositePropertySource nativeSource = CasConfigurationPropertiesEnvironmentManager
    .configureEnvironmentPropertySources(environment);

// Step 2: Rebind configuration properties
ConfigurationPropertiesBindingPostProcessor binder = 
    applicationContext.getBean(ConfigurationPropertiesBindingPostProcessor.class);
ApplicationContext updatedContext = CasConfigurationPropertiesEnvironmentManager
    .rebindCasConfigurationProperties(binder, applicationContext);

// Step 3: Validate configuration
CasConfigurationPropertiesValidator validator = 
    new CasConfigurationPropertiesValidator((ConfigurableApplicationContext) updatedContext);
List<String> validationResults = validator.validate();

// Step 4: Handle validation results
if (!validationResults.isEmpty()) {
    String errorMessage = String.join("\n", validationResults);
    System.err.println("Configuration validation errors:\n" + errorMessage);
    // Handle validation failures appropriately
}

Configuration Management Process

Property Rebinding Process

  1. Retrieve Configuration Bean: Get existing CasConfigurationProperties bean from application context
  2. Create Bean Name: Generate unique name using CasConfigurationProperties.PREFIX and class name
  3. Pre-Initialize: Call postProcessBeforeInitialization on the configuration bean
  4. Initialize Bean: Initialize the bean using application context's autowire capability
  5. Autowire Dependencies: Autowire the bean to inject all dependencies
  6. Log Completion: Log successful configuration reload

Environment Property Source Configuration

The native composite property source includes these sources in order of precedence:

  1. Command Line Arguments (commandLineArgs) - Highest precedence
  2. System Properties (systemProperties) - JVM system properties
  3. System Environment (systemEnvironment) - Operating system environment variables

Configuration Validation Process

  1. Discover Configuration Beans: Find all beans of type CasConfigurationProperties in application context
  2. Extract Property Sources: Get all property sources from environment
  3. Create Binder: Set up Spring Boot configuration binder with property sources and conversion service
  4. Validate Each Bean: For each configuration bean:
    • Create ConfigurationPropertiesBean wrapper
    • Extract binding target and annotation information
    • Attempt to bind properties using NoUnboundElementsBindHandler
    • Collect any binding exceptions and unbound properties
  5. Generate Results: Return list of validation error messages

Validation Error Reporting

Validation errors include detailed information about:

  • Unbound Properties: Properties that don't match any configuration binding
  • Property Origins: Source location of problematic properties
  • Property Values: Current values of unbound properties
  • Binding Errors: Detailed error messages from Spring Boot binding process

Constants

/**
 * Default bean name for configuration properties environment manager.
 */
String BEAN_NAME = "configurationPropertiesEnvironmentManager";

Error Handling

Rebinding Error Handling

The rebinding process includes comprehensive error handling:

  • Logs successful reloads with bean names
  • Handles missing configuration beans gracefully
  • Preserves application context state on failures

Validation Error Handling

The validation system provides detailed error reporting:

  • Catches and processes binding exceptions
  • Extracts unbound configuration properties with origins
  • Formats error messages with property names, values, and sources
  • Continues validation even when individual beans fail

Property Source Error Handling

Environment configuration handles missing property sources:

  • Checks for existence of each property source before adding
  • Uses FunctionUtils.doIfNotNull for safe null handling
  • Gracefully handles missing command line arguments or system properties

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