Apereo CAS Web Application Themes Support - Provides comprehensive theme resolution and management capabilities for the Central Authentication Service
—
Spring Boot auto-configuration that automatically sets up CAS theme resolution based on configuration properties.
Main auto-configuration class that creates and configures theme-related beans.
/**
* Auto-configuration for CAS themes support
*/
@EnableConfigurationProperties({CasConfigurationProperties.class, ThymeleafProperties.class, WebProperties.class})
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
@ConditionalOnFeatureEnabled(feature = CasFeatureModule.FeatureCatalog.Thymeleaf)
@AutoConfiguration
public class CasThemesAutoConfiguration {
/**
* Creates theme source bean based on configuration
* @param casProperties CAS configuration properties
* @return ThemeSource implementation (DefaultCasThemeSource or AggregateCasThemeSource)
*/
@Bean
@ConditionalOnMissingBean(name = "casThemeSource")
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public ThemeSource themeSource(CasConfigurationProperties casProperties);
/**
* Creates chaining theme resolver with multiple resolution strategies
* @param casProperties CAS configuration properties provider
* @param authenticationRequestServiceSelectionStrategies Service selection strategies
* @param servicesManager Services manager for service-based theme resolution
* @return Configured ChainingThemeResolver
*/
@Bean
@ConditionalOnMissingBean(name = "casThemeResolver")
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public ThemeResolver themeResolver(
ObjectProvider<CasConfigurationProperties> casProperties,
ObjectProvider<AuthenticationServiceSelectionPlan> authenticationRequestServiceSelectionStrategies,
ObjectProvider<ServicesManager> servicesManager);
/**
* Configures static resource handling for themes
* @param casProperties CAS configuration properties
* @param webProperties Spring web properties
* @param thymeleafProperties Thymeleaf template engine properties
* @return WebMvcConfigurer for theme resources
*/
@Bean
@ConditionalOnMissingBean(name = "themesStaticResourcesWebMvcConfigurer")
public WebMvcConfigurer themesStaticResourcesWebMvcConfigurer(
CasConfigurationProperties casProperties,
WebProperties webProperties,
ThymeleafProperties thymeleafProperties);
}Usage Examples:
// Auto-configuration is automatically activated when CAS themes support is on the classpath
// No explicit configuration needed - beans are created automatically
// Optional: Access auto-configured beans in your application
@Autowired
@Qualifier("casThemeSource")
private ThemeSource themeSource;
@Autowired
@Qualifier("casThemeResolver")
private ThemeResolver themeResolver;
// Use theme resolution in controller or service
String resolvedTheme = themeResolver.resolveThemeName(request);
Theme theme = themeSource.getTheme(resolvedTheme);Configuration through application properties:
# application.yml
cas:
theme:
default-theme-name: "cas-theme-default" # Default theme name
param-name: "theme" # HTTP parameter name for theme switching
view:
theme-source-type: AGGREGATE # DEFAULT or AGGREGATE
template-prefixes:
- "file:/etc/cas/themes/" # External theme directory
- "classpath:/themes/" # Classpath theme resources
tgc:
domain: ".example.com" # Cookie domain for theme persistence
secure: true # HTTPS-only cookies
http-only: true # Prevent XSS access to cookies
path: "/cas" # Cookie path
max-age: "P30D" # 30 day cookie expirationAlternative properties format:
# application.properties
cas.theme.default-theme-name=cas-theme-default
cas.theme.param-name=theme
cas.view.theme-source-type=AGGREGATE
cas.view.template-prefixes[0]=file:/etc/cas/themes/
cas.view.template-prefixes[1]=classpath:/themes/The auto-configuration creates theme sources based on the configured type:
// Configuration determines which theme source implementation to use
public enum ThemeSourceTypes {
DEFAULT, // Creates DefaultCasThemeSource
AGGREGATE // Creates AggregateCasThemeSource
}The auto-configuration sets up a complete theme resolver chain:
Automatically configures static resource handling for theme assets:
// Example resource locations served:
// /themes/default/css/cas.css
// /themes/custom/images/logo.png
// /themes/bootstrap/js/theme.jsclass CasConfigurationProperties {
ThemeProperties getTheme();
ViewProperties getView();
TgcProperties getTgc(); // For cookie configuration
}
class ThemeProperties {
String getDefaultThemeName(); // Default: "cas"
String getParamName(); // Default: "theme"
}
class ViewProperties {
List<String> getTemplatePrefixes();
ThemeSourceTypes getThemeSourceType();
enum ThemeSourceTypes {
DEFAULT, AGGREGATE
}
}The auto-configuration requires these dependencies to be available:
Install with Tessl CLI
npx tessl i tessl/maven-org-apereo-cas--cas-server-support-themes