Search in sources :

Example 1 with FileSystemResourceMetadataResolver

use of org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.FileSystemResourceMetadataResolver in project cas by apereo.

the class SamlIdPMetadataConfiguration method samlRegisteredServiceMetadataResolvers.

@ConditionalOnMissingBean(name = "samlRegisteredServiceMetadataResolvers")
@Bean
public SamlRegisteredServiceMetadataResolutionPlan samlRegisteredServiceMetadataResolvers() {
    final DefaultSamlRegisteredServiceMetadataResolutionPlan plan = new DefaultSamlRegisteredServiceMetadataResolutionPlan();
    final SamlIdPProperties samlIdp = casProperties.getAuthn().getSamlIdp();
    plan.registerMetadataResolver(new DynamicMetadataResolver(samlIdp, openSamlConfigBean, httpClient));
    plan.registerMetadataResolver(new FileSystemResourceMetadataResolver(samlIdp, openSamlConfigBean));
    plan.registerMetadataResolver(new UrlResourceMetadataResolver(samlIdp, openSamlConfigBean, httpClient));
    plan.registerMetadataResolver(new ClasspathResourceMetadataResolver(samlIdp, openSamlConfigBean));
    plan.registerMetadataResolver(new GroovyResourceMetadataResolver(samlIdp, openSamlConfigBean));
    final Map<String, SamlRegisteredServiceMetadataResolutionPlanConfigurator> configurers = this.applicationContext.getBeansOfType(SamlRegisteredServiceMetadataResolutionPlanConfigurator.class, false, true);
    configurers.values().forEach(c -> {
        final String name = StringUtils.removePattern(c.getClass().getSimpleName(), "\\$.+");
        LOGGER.debug("Configuring saml metadata resolution plan [{}]", name);
        c.configureMetadataResolutionPlan(plan);
    });
    return plan;
}
Also used : ClasspathResourceMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.ClasspathResourceMetadataResolver) GroovyResourceMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.GroovyResourceMetadataResolver) SamlIdPProperties(org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties) UrlResourceMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.UrlResourceMetadataResolver) DefaultSamlRegisteredServiceMetadataResolutionPlan(org.apereo.cas.support.saml.services.idp.metadata.plan.DefaultSamlRegisteredServiceMetadataResolutionPlan) SamlRegisteredServiceMetadataResolutionPlanConfigurator(org.apereo.cas.support.saml.services.idp.metadata.plan.SamlRegisteredServiceMetadataResolutionPlanConfigurator) FileSystemResourceMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.FileSystemResourceMetadataResolver) DynamicMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.DynamicMetadataResolver) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) OpenSamlConfigBean(org.apereo.cas.support.saml.OpenSamlConfigBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with FileSystemResourceMetadataResolver

use of org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.FileSystemResourceMetadataResolver in project cas by apereo.

the class SamlRegisteredServiceMetadataResolverCacheLoaderTests method verifyFileByExpression.

@Test
public void verifyFileByExpression() throws Exception {
    val mdFile = File.createTempFile("spsamlmetadata", ".xml");
    val content = IOUtils.toString(new ClassPathResource("sample-sp.xml").getInputStream(), StandardCharsets.UTF_8);
    FileUtils.writeStringToFile(mdFile, content, StandardCharsets.UTF_8);
    System.setProperty("SP_REF", mdFile.getCanonicalPath());
    val props = new SamlIdPProperties();
    props.getMetadata().getFileSystem().setLocation(new FileSystemResource(FileUtils.getTempDirectory()).getFile().getCanonicalPath());
    val plan = new DefaultSamlRegisteredServiceMetadataResolutionPlan();
    plan.registerMetadataResolver(new FileSystemResourceMetadataResolver(props, openSamlConfigBean));
    val loader = new SamlRegisteredServiceMetadataResolverCacheLoader(openSamlConfigBean, httpClient, plan);
    val service = new SamlRegisteredService();
    service.setName("Example");
    service.setId(1000);
    service.setServiceId("https://example.org/saml");
    service.setMetadataLocation("${#systemProperties['SP_REF']}");
    val key = new SamlRegisteredServiceCacheKey(service, new CriteriaSet());
    assertNotNull(loader.load(key));
}
Also used : lombok.val(lombok.val) SamlIdPProperties(org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties) DefaultSamlRegisteredServiceMetadataResolutionPlan(org.apereo.cas.support.saml.services.idp.metadata.plan.DefaultSamlRegisteredServiceMetadataResolutionPlan) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) FileSystemResource(org.springframework.core.io.FileSystemResource) FileSystemResourceMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.FileSystemResourceMetadataResolver) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Aggregations

SamlIdPProperties (org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties)2 FileSystemResourceMetadataResolver (org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.FileSystemResourceMetadataResolver)2 DefaultSamlRegisteredServiceMetadataResolutionPlan (org.apereo.cas.support.saml.services.idp.metadata.plan.DefaultSamlRegisteredServiceMetadataResolutionPlan)2 lombok.val (lombok.val)1 CriteriaSet (net.shibboleth.utilities.java.support.resolver.CriteriaSet)1 OpenSamlConfigBean (org.apereo.cas.support.saml.OpenSamlConfigBean)1 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)1 ClasspathResourceMetadataResolver (org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.ClasspathResourceMetadataResolver)1 DynamicMetadataResolver (org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.DynamicMetadataResolver)1 GroovyResourceMetadataResolver (org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.GroovyResourceMetadataResolver)1 UrlResourceMetadataResolver (org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.UrlResourceMetadataResolver)1 SamlRegisteredServiceMetadataResolutionPlanConfigurator (org.apereo.cas.support.saml.services.idp.metadata.plan.SamlRegisteredServiceMetadataResolutionPlanConfigurator)1 Test (org.junit.jupiter.api.Test)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1