use of org.springframework.web.servlet.config.annotation.WebMvcConfigurer in project cas by apereo.
the class CasThemesConfiguration method themesStaticResourcesWebMvcConfigurer.
@Bean
@ConditionalOnMissingBean(name = "themesStaticResourcesWebMvcConfigurer")
public WebMvcConfigurer themesStaticResourcesWebMvcConfigurer(final CasConfigurationProperties casProperties, final WebProperties webProperties, final ThymeleafProperties thymeleafProperties) {
return new WebMvcConfigurer() {
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
val templatePrefixes = casProperties.getView().getTemplatePrefixes();
if (!templatePrefixes.isEmpty()) {
val registration = registry.addResourceHandler("/**");
val resources = templatePrefixes.stream().map(prefix -> StringUtils.appendIfMissing(prefix, "/")).map(Unchecked.function(ResourceUtils::getRawResourceFrom)).toArray(Resource[]::new);
LOGGER.debug("Adding resource handler for resources [{}]", (Object[]) resources);
registration.addResourceLocations(templatePrefixes.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
registration.addResourceLocations(webProperties.getResources().getStaticLocations());
FunctionUtils.doIfNotNull(webProperties.getResources().getCache().getPeriod(), period -> registration.setCachePeriod((int) period.getSeconds()));
registration.setCacheControl(webProperties.getResources().getCache().getCachecontrol().toHttpCacheControl());
registration.setUseLastModified(true);
val cache = thymeleafProperties != null && thymeleafProperties.isCache();
val chainRegistration = registration.resourceChain(cache);
val resolver = new PathResourceResolver();
resolver.setAllowedLocations(resources);
chainRegistration.addResolver(resolver);
}
}
};
}
Aggregations