Search in sources :

Example 6 with MetadataFilterChain

use of org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain in project cas by apereo.

the class SamlMetadataUIConfiguration method configureAdapter.

private static MetadataResolverAdapter configureAdapter(final AbstractMetadataResolverAdapter adapter, final ConfigurableApplicationContext applicationContext, final CasConfigurationProperties casProperties, final OpenSamlConfigBean openSamlConfigBean) {
    val resources = new HashMap<Resource, MetadataFilterChain>();
    val chain = new MetadataFilterChain();
    casProperties.getSamlMetadataUi().getResources().forEach(Unchecked.consumer(r -> configureResource(applicationContext, resources, chain, r, casProperties)));
    adapter.setRequireValidMetadata(casProperties.getSamlMetadataUi().isRequireValidMetadata());
    adapter.setMetadataResources(resources);
    adapter.setConfigBean(openSamlConfigBean);
    return adapter;
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Arrays(java.util.Arrays) StaticMetadataResolverAdapter(org.apereo.cas.support.saml.mdui.StaticMetadataResolverAdapter) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) RequiredValidUntilFilter(org.opensaml.saml.metadata.resolver.filter.impl.RequiredValidUntilFilter) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ArrayList(java.util.ArrayList) SamlUtils(org.apereo.cas.support.saml.SamlUtils) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Duration(java.time.Duration) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Splitter(com.google.common.base.Splitter) MetadataFilter(org.opensaml.saml.metadata.resolver.filter.MetadataFilter) Resource(org.springframework.core.io.Resource) MetadataFilterChain(org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain) AbstractMetadataResolverAdapter(org.apereo.cas.support.saml.mdui.AbstractMetadataResolverAdapter) MetadataResolverAdapter(org.apereo.cas.support.saml.mdui.MetadataResolverAdapter) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ResourceUtils(org.apereo.cas.util.ResourceUtils) Unchecked(org.jooq.lambda.Unchecked) lombok.val(lombok.val) ScopedProxyMode(org.springframework.context.annotation.ScopedProxyMode) ChainingMetadataResolverAdapter(org.apereo.cas.support.saml.mdui.ChainingMetadataResolverAdapter) OpenSamlConfigBean(org.apereo.cas.support.saml.OpenSamlConfigBean) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) DynamicMetadataResolverAdapter(org.apereo.cas.support.saml.mdui.DynamicMetadataResolverAdapter) Bean(org.springframework.context.annotation.Bean) HashMap(java.util.HashMap) MetadataFilterChain(org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain)

Example 7 with MetadataFilterChain

use of org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain in project cas by apereo.

the class SamlMetadataUIConfiguration method configureResource.

private static void configureResource(final ConfigurableApplicationContext applicationContext, final Map<Resource, MetadataFilterChain> resources, final MetadataFilterChain chain, final String resourceArray, final CasConfigurationProperties casProperties) {
    val splitArray = org.springframework.util.StringUtils.commaDelimitedListToStringArray(resourceArray);
    Arrays.stream(splitArray).forEach(Unchecked.consumer(entry -> {
        val arr = Splitter.on(DEFAULT_SEPARATOR).splitToList(entry);
        val metadataFile = arr.get(0);
        val signingKey = arr.size() > 1 ? arr.get(1) : null;
        val filters = new ArrayList<MetadataFilter>();
        if (casProperties.getSamlMetadataUi().getMaxValidity() > 0) {
            val filter = new RequiredValidUntilFilter();
            filter.setMaxValidityInterval(Duration.ofSeconds(casProperties.getSamlMetadataUi().getMaxValidity()));
            filters.add(filter);
        }
        var addResource = true;
        if (StringUtils.isNotBlank(signingKey)) {
            val sigFilter = SamlUtils.buildSignatureValidationFilter(applicationContext, signingKey);
            if (sigFilter != null) {
                sigFilter.setRequireSignedRoot(casProperties.getSamlMetadataUi().isRequireSignedRoot());
                filters.add(sigFilter);
            } else {
                LOGGER.warn("Failed to locate the signing key [{}] for [{}]", signingKey, metadataFile);
                addResource = false;
            }
        }
        chain.setFilters(filters);
        val resource = applicationContext.getResource(metadataFile);
        if (addResource && ResourceUtils.doesResourceExist(resource)) {
            resources.put(resource, chain);
        } else {
            LOGGER.warn("Skipping metadata [{}]; Either the resource cannot be retrieved or its signing key is missing", metadataFile);
        }
    }));
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Arrays(java.util.Arrays) StaticMetadataResolverAdapter(org.apereo.cas.support.saml.mdui.StaticMetadataResolverAdapter) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) RequiredValidUntilFilter(org.opensaml.saml.metadata.resolver.filter.impl.RequiredValidUntilFilter) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ArrayList(java.util.ArrayList) SamlUtils(org.apereo.cas.support.saml.SamlUtils) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Duration(java.time.Duration) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Splitter(com.google.common.base.Splitter) MetadataFilter(org.opensaml.saml.metadata.resolver.filter.MetadataFilter) Resource(org.springframework.core.io.Resource) MetadataFilterChain(org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain) AbstractMetadataResolverAdapter(org.apereo.cas.support.saml.mdui.AbstractMetadataResolverAdapter) MetadataResolverAdapter(org.apereo.cas.support.saml.mdui.MetadataResolverAdapter) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ResourceUtils(org.apereo.cas.util.ResourceUtils) Unchecked(org.jooq.lambda.Unchecked) lombok.val(lombok.val) ScopedProxyMode(org.springframework.context.annotation.ScopedProxyMode) ChainingMetadataResolverAdapter(org.apereo.cas.support.saml.mdui.ChainingMetadataResolverAdapter) OpenSamlConfigBean(org.apereo.cas.support.saml.OpenSamlConfigBean) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) DynamicMetadataResolverAdapter(org.apereo.cas.support.saml.mdui.DynamicMetadataResolverAdapter) Bean(org.springframework.context.annotation.Bean) RequiredValidUntilFilter(org.opensaml.saml.metadata.resolver.filter.impl.RequiredValidUntilFilter) MetadataFilter(org.opensaml.saml.metadata.resolver.filter.MetadataFilter)

Aggregations

MetadataFilterChain (org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain)7 lombok.val (lombok.val)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 MetadataFilter (org.opensaml.saml.metadata.resolver.filter.MetadataFilter)4 Splitter (com.google.common.base.Splitter)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 Slf4j (lombok.extern.slf4j.Slf4j)3 StringUtils (org.apache.commons.lang3.StringUtils)3 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)3 OpenSamlConfigBean (org.apereo.cas.support.saml.OpenSamlConfigBean)3 SamlUtils (org.apereo.cas.support.saml.SamlUtils)3 AbstractMetadataResolverAdapter (org.apereo.cas.support.saml.mdui.AbstractMetadataResolverAdapter)3 ChainingMetadataResolverAdapter (org.apereo.cas.support.saml.mdui.ChainingMetadataResolverAdapter)3 DynamicMetadataResolverAdapter (org.apereo.cas.support.saml.mdui.DynamicMetadataResolverAdapter)3 MetadataResolverAdapter (org.apereo.cas.support.saml.mdui.MetadataResolverAdapter)3 StaticMetadataResolverAdapter (org.apereo.cas.support.saml.mdui.StaticMetadataResolverAdapter)3 CollectionUtils (org.apereo.cas.util.CollectionUtils)3 ResourceUtils (org.apereo.cas.util.ResourceUtils)3