CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apereo-cas--cas-server-support-themes

Apereo CAS Web Application Themes Support - Provides comprehensive theme resolution and management capabilities for the Central Authentication Service

Pending
Overview
Eval results
Files

theme-sources.mddocs/

Theme Sources

Theme source implementations that load and manage theme properties and resources from various locations.

Capabilities

DefaultCasThemeSource

Default theme source implementation that searches template prefixes for theme properties and supports hierarchical theme inheritance.

/**
 * Default theme source that extends ResourceBundleThemeSource with CAS-specific features
 */
public class DefaultCasThemeSource extends ResourceBundleThemeSource {
    
    /**
     * Constructor requiring CAS configuration properties
     * @param casProperties CAS configuration containing template prefixes and theme settings
     */
    public DefaultCasThemeSource(CasConfigurationProperties casProperties);
    
    /**
     * Creates message source for theme properties, searches template prefixes first
     * @param basename Theme base name (e.g., "default", "custom")
     * @return MessageSource containing theme properties and messages
     */
    @Nonnull
    @Override
    protected MessageSource createMessageSource(@Nonnull String basename);
    
    /**
     * Creates hierarchical message source with custom and default theme support
     * @param basename Theme base name
     * @return MessageSource with parent-child hierarchy
     */
    protected MessageSource createExtendedMessageSource(String basename);
    
    /**
     * Loads properties from specified path and creates static message source
     * @param path Path to theme properties file
     * @return StaticMessageSource with loaded properties
     * @throws Exception if resource cannot be loaded
     */
    protected StaticMessageSource loadMessageSourceFromPath(String path) throws Exception;
}

Usage Examples:

import org.apereo.cas.services.web.DefaultCasThemeSource;
import org.apereo.cas.configuration.CasConfigurationProperties;

// Create default theme source
CasConfigurationProperties properties = // ... configured instance
DefaultCasThemeSource themeSource = new DefaultCasThemeSource(properties);

// Theme source will search for properties in configured template prefixes:
// /etc/cas/themes/mytheme.properties
// classpath:/themes/mytheme.properties
// Standard resource bundle locations

AggregateCasThemeSource

Theme source that merges all theme resource bundles it can find across all configured template prefixes.

/**
 * Theme source that aggregates properties from multiple theme resource bundles
 */
public class AggregateCasThemeSource extends ResourceBundleThemeSource {
    
    /**
     * Constructor requiring CAS configuration properties
     * @param casProperties CAS configuration containing template prefixes
     */
    public AggregateCasThemeSource(CasConfigurationProperties casProperties);
    
    /**
     * Creates message source that aggregates properties from all template prefixes
     * @param basename Theme base name to search for across all prefixes
     * @return MessageSource containing merged properties from all found resources
     */
    @Nonnull
    @Override
    protected MessageSource createMessageSource(@Nonnull String basename);
}

Usage Examples:

import org.apereo.cas.services.web.AggregateCasThemeSource;

// Create aggregate theme source
AggregateCasThemeSource themeSource = new AggregateCasThemeSource(properties);

// Will merge properties from all matching files:
// /etc/cas/themes/mytheme.properties
// /var/cas/themes/mytheme.properties  
// classpath:/themes/mytheme.properties
// All properties are combined into single MessageSource

CasThemeResourceBundleMessageSource

Enhanced message source for theme resource bundles with improved error handling and validation.

/**
 * Custom message source for theme resource bundles with enhanced error handling
 * Validates that resource bundles are not empty before returning them
 */
public class CasThemeResourceBundleMessageSource extends ResourceBundleMessageSource {
    
    /**
     * Gets resource bundle with null-safe error handling and validation
     * Returns null if bundle is not found, empty, or an exception occurs
     * @param basename Base name of the resource bundle
     * @param locale Locale for the bundle
     * @return ResourceBundle if found and non-empty, null otherwise for graceful fallback
     */
    @Override
    protected ResourceBundle doGetBundle(String basename, Locale locale);
}

Usage Examples:

import org.apereo.cas.services.web.CasThemeResourceBundleMessageSource;

// Create enhanced message source for theme validation
CasThemeResourceBundleMessageSource messageSource = new CasThemeResourceBundleMessageSource();
messageSource.setBasename("mytheme");

// The message source will validate bundle existence and content
// Returns null for missing or empty bundles, allowing graceful fallback
ResourceBundle bundle = messageSource.doGetBundle("mytheme", Locale.ENGLISH);
if (bundle != null) {
    // Bundle exists and has content
    String message = bundle.getString("login.welcome");
}

Theme Property File Format

Theme properties files use standard Java properties format:

# Theme metadata
theme.name=My Custom Theme
theme.description=A beautiful custom theme for CAS

# CSS and JavaScript resources
theme.css.file=css/custom.css
theme.js.file=js/custom.js

# Localized messages  
login.welcome=Welcome to CAS
login.instructions=Please enter your credentials
error.authentication.failed=Authentication failed

Theme Search Strategy

DefaultCasThemeSource Search Order

  1. Template Prefixes: Searches configured template prefixes in order

    • Example: /etc/cas/themes/mytheme.properties
    • Example: classpath:/themes/mytheme.properties
  2. Hierarchical Support: Creates parent-child message source hierarchy

    • Custom theme inherits from default theme
    • Replaces -default with -custom in basename
  3. Fallback: Uses standard ResourceBundle mechanism if not found in prefixes

AggregateCasThemeSource Merging

  1. Collect All: Finds all matching property files across all template prefixes
  2. Merge Properties: Combines all properties into single MessageSource
  3. Parent Chain: Sets standard ResourceBundle as parent for fallback

Resource Loading

Both theme sources support loading from:

  • File System: file:/path/to/themes/
  • Classpath: classpath:/themes/
  • HTTP URLs: http://example.com/themes/ (via ResourceUtils)
  • Custom Resources: Any Spring Resource implementation
// Example template prefix configurations
cas.view.template-prefixes[0]=file:/etc/cas/themes/
cas.view.template-prefixes[1]=classpath:/themes/
cas.view.template-prefixes[2]=http://cdn.example.com/cas-themes/

Locale Support

Theme sources support internationalization:

// DefaultCasThemeSource loads properties for multiple locales
List.of(Locale.US, Locale.CANADA, Locale.ENGLISH).forEach(locale -> {
    source.addMessage(key.toString(), locale, value.toString());
});

// AggregateCasThemeSource uses English locale by default
source.addMessage(key.toString(), Locale.ENGLISH, value.toString());

Error Handling

  • Resource Not Found: Gracefully falls back to parent message sources
  • IO Exceptions: Logged as warnings, theme loading continues
  • Invalid Properties: Individual property errors don't stop theme loading
  • Bundle Validation: CasThemeResourceBundleMessageSource validates bundle contents

Install with Tessl CLI

npx tessl i tessl/maven-org-apereo-cas--cas-server-support-themes

docs

auto-configuration.md

header-theme-resolution.md

index.md

service-theme-resolution.md

theme-resolution.md

theme-sources.md

tile.json