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

auto-configuration.mddocs/

Auto-Configuration

Spring Boot auto-configuration that automatically sets up CAS theme resolution based on configuration properties.

Capabilities

CasThemesAutoConfiguration

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 expiration

Alternative 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/

Theme Source Creation

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  
}

Theme Resolver Chain Configuration

The auto-configuration sets up a complete theme resolver chain:

  1. Cookie Theme Resolver - Reads theme from cookies
  2. Session Theme Resolver - Reads theme from HTTP session
  3. Request Header Theme Resolver - Reads theme from HTTP headers
  4. Registered Service Theme Resolver - Reads theme from service configuration
  5. Fixed Theme Resolver - Falls back to default theme

Static Resource Configuration

Automatically configures static resource handling for theme assets:

  • Serves theme resources from configured template prefixes
  • Enables resource caching and versioning
  • Supports content versioning strategies
  • Configures allowed resource locations for security
// Example resource locations served:
// /themes/default/css/cas.css
// /themes/custom/images/logo.png
// /themes/bootstrap/js/theme.js

Configuration Properties

class 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
    }
}

Integration Requirements

The auto-configuration requires these dependencies to be available:

  • CAS Core Services API
  • CAS Core Web API
  • CAS Core Authentication API
  • Spring Web MVC
  • Spring Boot Auto-Configuration
  • Thymeleaf (when using template features)

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