Search in sources :

Example 1 with ResourceUtils

use of org.apereo.cas.util.ResourceUtils 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);
            }
        }
    };
}
Also used : lombok.val(lombok.val) PathResourceResolver(org.springframework.web.servlet.resource.PathResourceResolver) WebMvcConfigurer(org.springframework.web.servlet.config.annotation.WebMvcConfigurer) ResourceUtils(org.apereo.cas.util.ResourceUtils) ResourceHandlerRegistry(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with ResourceUtils

use of org.apereo.cas.util.ResourceUtils in project cas by apereo.

the class WsFederationCertificateProvider method getProvider.

/**
 * Gets providers.
 *
 * @param config             the config
 * @param openSamlConfigBean the open saml config bean
 * @return the providers
 */
static WsFederationCertificateProvider getProvider(final WsFederationConfiguration config, final OpenSamlConfigBean openSamlConfigBean) {
    val chain = new ChainingWsFederationCertificateProvider();
    StringUtils.commaDelimitedListToSet(config.getSigningCertificates()).stream().map(Unchecked.function(ResourceUtils::getRawResourceFrom)).forEach(resource -> {
        if (StringUtils.hasText(resource.getFilename()) && resource.getFilename().endsWith(".xml")) {
            chain.addProvider(new WsFederationMetadataCertificateProvider(resource, config, openSamlConfigBean));
        } else {
            chain.addProvider(new WsFederationStaticCertificateProvider(resource));
        }
    });
    return chain;
}
Also used : lombok.val(lombok.val) ResourceUtils(org.apereo.cas.util.ResourceUtils)

Aggregations

lombok.val (lombok.val)2 ResourceUtils (org.apereo.cas.util.ResourceUtils)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 ResourceHandlerRegistry (org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry)1 WebMvcConfigurer (org.springframework.web.servlet.config.annotation.WebMvcConfigurer)1 PathResourceResolver (org.springframework.web.servlet.resource.PathResourceResolver)1