0
# Auto-Configuration
1
2
Spring Boot auto-configuration that automatically sets up CAS theme resolution based on configuration properties.
3
4
## Capabilities
5
6
### CasThemesAutoConfiguration
7
8
Main auto-configuration class that creates and configures theme-related beans.
9
10
```java { .api }
11
/**
12
* Auto-configuration for CAS themes support
13
*/
14
@EnableConfigurationProperties({CasConfigurationProperties.class, ThymeleafProperties.class, WebProperties.class})
15
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
16
@ConditionalOnFeatureEnabled(feature = CasFeatureModule.FeatureCatalog.Thymeleaf)
17
@AutoConfiguration
18
public class CasThemesAutoConfiguration {
19
20
/**
21
* Creates theme source bean based on configuration
22
* @param casProperties CAS configuration properties
23
* @return ThemeSource implementation (DefaultCasThemeSource or AggregateCasThemeSource)
24
*/
25
@Bean
26
@ConditionalOnMissingBean(name = "casThemeSource")
27
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
28
public ThemeSource themeSource(CasConfigurationProperties casProperties);
29
30
/**
31
* Creates chaining theme resolver with multiple resolution strategies
32
* @param casProperties CAS configuration properties provider
33
* @param authenticationRequestServiceSelectionStrategies Service selection strategies
34
* @param servicesManager Services manager for service-based theme resolution
35
* @return Configured ChainingThemeResolver
36
*/
37
@Bean
38
@ConditionalOnMissingBean(name = "casThemeResolver")
39
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
40
public ThemeResolver themeResolver(
41
ObjectProvider<CasConfigurationProperties> casProperties,
42
ObjectProvider<AuthenticationServiceSelectionPlan> authenticationRequestServiceSelectionStrategies,
43
ObjectProvider<ServicesManager> servicesManager);
44
45
/**
46
* Configures static resource handling for themes
47
* @param casProperties CAS configuration properties
48
* @param webProperties Spring web properties
49
* @param thymeleafProperties Thymeleaf template engine properties
50
* @return WebMvcConfigurer for theme resources
51
*/
52
@Bean
53
@ConditionalOnMissingBean(name = "themesStaticResourcesWebMvcConfigurer")
54
public WebMvcConfigurer themesStaticResourcesWebMvcConfigurer(
55
CasConfigurationProperties casProperties,
56
WebProperties webProperties,
57
ThymeleafProperties thymeleafProperties);
58
}
59
```
60
61
**Usage Examples:**
62
63
```java
64
// Auto-configuration is automatically activated when CAS themes support is on the classpath
65
// No explicit configuration needed - beans are created automatically
66
67
// Optional: Access auto-configured beans in your application
68
@Autowired
69
@Qualifier("casThemeSource")
70
private ThemeSource themeSource;
71
72
@Autowired
73
@Qualifier("casThemeResolver")
74
private ThemeResolver themeResolver;
75
76
// Use theme resolution in controller or service
77
String resolvedTheme = themeResolver.resolveThemeName(request);
78
Theme theme = themeSource.getTheme(resolvedTheme);
79
```
80
81
**Configuration through application properties:**
82
83
```yaml
84
# application.yml
85
cas:
86
theme:
87
default-theme-name: "cas-theme-default" # Default theme name
88
param-name: "theme" # HTTP parameter name for theme switching
89
view:
90
theme-source-type: AGGREGATE # DEFAULT or AGGREGATE
91
template-prefixes:
92
- "file:/etc/cas/themes/" # External theme directory
93
- "classpath:/themes/" # Classpath theme resources
94
tgc:
95
domain: ".example.com" # Cookie domain for theme persistence
96
secure: true # HTTPS-only cookies
97
http-only: true # Prevent XSS access to cookies
98
path: "/cas" # Cookie path
99
max-age: "P30D" # 30 day cookie expiration
100
```
101
102
**Alternative properties format:**
103
104
```properties
105
# application.properties
106
cas.theme.default-theme-name=cas-theme-default
107
cas.theme.param-name=theme
108
cas.view.theme-source-type=AGGREGATE
109
cas.view.template-prefixes[0]=file:/etc/cas/themes/
110
cas.view.template-prefixes[1]=classpath:/themes/
111
```
112
113
### Theme Source Creation
114
115
The auto-configuration creates theme sources based on the configured type:
116
117
```java { .api }
118
// Configuration determines which theme source implementation to use
119
public enum ThemeSourceTypes {
120
DEFAULT, // Creates DefaultCasThemeSource
121
AGGREGATE // Creates AggregateCasThemeSource
122
}
123
```
124
125
### Theme Resolver Chain Configuration
126
127
The auto-configuration sets up a complete theme resolver chain:
128
129
1. **Cookie Theme Resolver** - Reads theme from cookies
130
2. **Session Theme Resolver** - Reads theme from HTTP session
131
3. **Request Header Theme Resolver** - Reads theme from HTTP headers
132
4. **Registered Service Theme Resolver** - Reads theme from service configuration
133
5. **Fixed Theme Resolver** - Falls back to default theme
134
135
### Static Resource Configuration
136
137
Automatically configures static resource handling for theme assets:
138
139
- Serves theme resources from configured template prefixes
140
- Enables resource caching and versioning
141
- Supports content versioning strategies
142
- Configures allowed resource locations for security
143
144
```java
145
// Example resource locations served:
146
// /themes/default/css/cas.css
147
// /themes/custom/images/logo.png
148
// /themes/bootstrap/js/theme.js
149
```
150
151
## Configuration Properties
152
153
```java { .api }
154
class CasConfigurationProperties {
155
ThemeProperties getTheme();
156
ViewProperties getView();
157
TgcProperties getTgc(); // For cookie configuration
158
}
159
160
class ThemeProperties {
161
String getDefaultThemeName(); // Default: "cas"
162
String getParamName(); // Default: "theme"
163
}
164
165
class ViewProperties {
166
List<String> getTemplatePrefixes();
167
ThemeSourceTypes getThemeSourceType();
168
169
enum ThemeSourceTypes {
170
DEFAULT, AGGREGATE
171
}
172
}
173
```
174
175
## Integration Requirements
176
177
The auto-configuration requires these dependencies to be available:
178
179
- CAS Core Services API
180
- CAS Core Web API
181
- CAS Core Authentication API
182
- Spring Web MVC
183
- Spring Boot Auto-Configuration
184
- Thymeleaf (when using template features)