Apereo CAS Web Application Themes Support - Provides comprehensive theme resolution and management capabilities for the Central Authentication Service
—
Theme source implementations that load and manage theme properties and resources from various locations.
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 locationsTheme 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 MessageSourceEnhanced 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 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 failedTemplate Prefixes: Searches configured template prefixes in order
/etc/cas/themes/mytheme.propertiesclasspath:/themes/mytheme.propertiesHierarchical Support: Creates parent-child message source hierarchy
-default with -custom in basenameFallback: Uses standard ResourceBundle mechanism if not found in prefixes
Both theme sources support loading from:
file:/path/to/themes/classpath:/themes/http://example.com/themes/ (via ResourceUtils)// 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/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());Install with Tessl CLI
npx tessl i tessl/maven-org-apereo-cas--cas-server-support-themes