Search in sources :

Example 1 with ChainingMetadataResolver

use of org.opensaml.saml.metadata.resolver.ChainingMetadataResolver in project pac4j by pac4j.

the class SAML2Client method initChainingMetadataResolver.

protected ChainingMetadataResolver initChainingMetadataResolver(final MetadataResolver idpMetadataProvider, final MetadataResolver spMetadataProvider) {
    final ChainingMetadataResolver metadataManager = new ChainingMetadataResolver();
    metadataManager.setId(ChainingMetadataResolver.class.getCanonicalName());
    try {
        final List<MetadataResolver> list = new ArrayList<>();
        list.add(idpMetadataProvider);
        list.add(spMetadataProvider);
        metadataManager.setResolvers(list);
        metadataManager.initialize();
    } catch (final ResolverException e) {
        throw new TechnicalException("Error adding idp or sp metadatas to manager", e);
    } catch (final ComponentInitializationException e) {
        throw new TechnicalException("Error initializing manager", e);
    }
    return metadataManager;
}
Also used : ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) ResolverException(net.shibboleth.utilities.java.support.resolver.ResolverException) TechnicalException(org.pac4j.core.exception.TechnicalException) ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) ArrayList(java.util.ArrayList) SAML2IdentityProviderMetadataResolver(org.pac4j.saml.metadata.SAML2IdentityProviderMetadataResolver) SAML2ServiceProviderMetadataResolver(org.pac4j.saml.metadata.SAML2ServiceProviderMetadataResolver) SAML2MetadataResolver(org.pac4j.saml.metadata.SAML2MetadataResolver) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver)

Example 2 with ChainingMetadataResolver

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

the class AbstractMetadataResolverAdapter method buildMetadataResolverAggregate.

/**
 * Build metadata resolver aggregate. Loops through metadata resources
 * and attempts to resolve the metadata.
 *
 * @param entityId the entity id
 */
@Synchronized
@SneakyThrows
public void buildMetadataResolverAggregate(final String entityId) {
    LOGGER.trace("Building metadata resolver aggregate");
    this.metadataResolver = new ChainingMetadataResolver();
    val entries = this.metadataResources.entrySet();
    val resolvers = new ArrayList<MetadataResolver>(entries.size());
    entries.forEach(entry -> {
        val resource = entry.getKey();
        LOGGER.debug("Loading [{}]", resource.getFilename());
        resolvers.addAll(loadMetadataFromResource(entry.getValue(), resource, entityId));
    });
    this.metadataResolver.setId(ChainingMetadataResolver.class.getCanonicalName());
    this.metadataResolver.setResolvers(resolvers);
    LOGGER.debug("Collected metadata from [{}] resolvers(s). Initializing aggregate resolver...", resolvers.size());
    this.metadataResolver.initialize();
    LOGGER.info("Metadata aggregate initialized successfully.");
}
Also used : lombok.val(lombok.val) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) ArrayList(java.util.ArrayList) Synchronized(lombok.Synchronized) SneakyThrows(lombok.SneakyThrows)

Example 3 with ChainingMetadataResolver

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

the class SamlSPUtils method determineEntityIdList.

private static List<String> determineEntityIdList(final AbstractSamlSPProperties sp, final SamlRegisteredServiceCachingMetadataResolver resolver, final SamlRegisteredService service) {
    val entityIDList = sp.getEntityIds();
    if (entityIDList.isEmpty()) {
        val criteriaSet = new CriteriaSet();
        criteriaSet.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
        criteriaSet.add(new SatisfyAnyCriterion());
        val metadataResolver = resolver.resolve(service, criteriaSet);
        val resolvers = new ArrayList<MetadataResolver>();
        if (metadataResolver instanceof ChainingMetadataResolver) {
            resolvers.addAll(((ChainingMetadataResolver) metadataResolver).getResolvers());
        } else {
            resolvers.add(metadataResolver);
        }
        resolvers.forEach(r -> {
            if (r instanceof AbstractBatchMetadataResolver) {
                val it = ((AbstractBatchMetadataResolver) r).iterator();
                val descriptor = StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, Spliterator.ORDERED), false).filter(e -> e.getSPSSODescriptor(SAMLConstants.SAML20P_NS) != null).findFirst();
                if (descriptor.isPresent()) {
                    entityIDList.add(descriptor.get().getEntityID());
                } else {
                    LOGGER.warn("Skipped registration of [{}] since no entity id could be found", sp.getName());
                }
            }
        });
    }
    return entityIDList;
}
Also used : lombok.val(lombok.val) SatisfyAnyCriterion(org.opensaml.core.criterion.SatisfyAnyCriterion) AbstractBatchMetadataResolver(org.opensaml.saml.metadata.resolver.impl.AbstractBatchMetadataResolver) Ordered(org.springframework.core.Ordered) PrincipalAttributeRegisteredServiceUsernameProvider(org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider) SneakyThrows(lombok.SneakyThrows) Spliterators(java.util.Spliterators) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) StringUtils(org.apache.commons.lang3.StringUtils) AbstractBatchMetadataResolver(org.opensaml.saml.metadata.resolver.impl.AbstractBatchMetadataResolver) ArrayList(java.util.ArrayList) UtilityClass(lombok.experimental.UtilityClass) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) SatisfyAnyCriterion(org.opensaml.core.criterion.SatisfyAnyCriterion) StreamSupport(java.util.stream.StreamSupport) SAMLConstants(org.opensaml.saml.common.xml.SAMLConstants) ChainingAttributeReleasePolicy(org.apereo.cas.services.ChainingAttributeReleasePolicy) ServicesManager(org.apereo.cas.services.ServicesManager) lombok.val(lombok.val) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) RegisteredService(org.apereo.cas.services.RegisteredService) SPSSODescriptor(org.opensaml.saml.saml2.metadata.SPSSODescriptor) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) AbstractSamlSPProperties(org.apereo.cas.configuration.model.support.saml.sps.AbstractSamlSPProperties) ReturnMappedAttributeReleasePolicy(org.apereo.cas.services.ReturnMappedAttributeReleasePolicy) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) CoreAuthenticationUtils(org.apereo.cas.authentication.CoreAuthenticationUtils) PredicateFilter(org.opensaml.saml.metadata.resolver.filter.impl.PredicateFilter) Spliterator(java.util.Spliterator) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion) ArrayList(java.util.ArrayList)

Example 4 with ChainingMetadataResolver

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

the class SamlRegisteredServiceMetadataResolverCacheLoader method load.

@Override
@Synchronized
@SneakyThrows
public ChainingMetadataResolver load(final SamlRegisteredServiceCacheKey cacheKey) {
    val metadataResolver = new ChainingMetadataResolver();
    val service = cacheKey.getRegisteredService();
    val availableResolvers = metadataResolutionPlan.getRegisteredMetadataResolvers();
    val size = availableResolvers.size();
    val metadataResolvers = new ArrayList<MetadataResolver>(size);
    LOGGER.debug("There are [{}] metadata resolver(s) available in the chain", size);
    availableResolvers.stream().filter(Objects::nonNull).filter(r -> {
        LOGGER.trace("Evaluating whether metadata resolver [{}] can support service [{}]", r.getName(), service.getName());
        return r.supports(service);
    }).map(Unchecked.function(r -> {
        LOGGER.trace("Metadata resolver [{}] has started to process metadata for [{}]", r.getName(), service.getName());
        return r.resolve(service, cacheKey.getCriteriaSet());
    })).forEach(metadataResolvers::addAll);
    if (metadataResolvers.isEmpty()) {
        val metadataLocation = SpringExpressionLanguageValueResolver.getInstance().resolve(service.getMetadataLocation());
        throw new SamlException("No metadata resolvers could be configured for service " + service.getName() + " with metadata location " + metadataLocation);
    }
    metadataResolver.setId(ChainingMetadataResolver.class.getCanonicalName());
    LOGGER.trace("There are [{}] eligible metadata resolver(s) for this request", metadataResolvers.size());
    metadataResolver.setResolvers(metadataResolvers);
    metadataResolver.initialize();
    LOGGER.debug("Metadata resolvers active for this request are [{}]", metadataResolvers);
    return metadataResolver;
}
Also used : lombok.val(lombok.val) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) ArrayList(java.util.ArrayList) SamlException(org.apereo.cas.support.saml.SamlException) Synchronized(lombok.Synchronized) SneakyThrows(lombok.SneakyThrows)

Example 5 with ChainingMetadataResolver

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

the class DefaultSamlRegisteredServiceCachingMetadataResolver method resolve.

@Override
public ChainingMetadataResolver resolve(final SamlRegisteredService service) {
    ChainingMetadataResolver resolver = null;
    try {
        LOGGER.debug("Resolving metadata for [{}] at [{}].", service.getName(), service.getMetadataLocation());
        resolver = this.cache.get(service);
        return resolver;
    } catch (final Exception e) {
        throw new IllegalArgumentException("Metadata resolver could not be located from metadata " + service.getMetadataLocation(), e);
    } finally {
        if (resolver != null) {
            LOGGER.debug("Loaded and cached SAML metadata [{}] from [{}] for [{}] minute(s)", resolver.getId(), service.getMetadataLocation(), this.metadataCacheExpirationMinutes);
        }
    }
}
Also used : ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver)

Aggregations

ChainingMetadataResolver (org.opensaml.saml.metadata.resolver.ChainingMetadataResolver)8 ArrayList (java.util.ArrayList)6 SneakyThrows (lombok.SneakyThrows)5 lombok.val (lombok.val)4 MetadataResolver (org.opensaml.saml.metadata.resolver.MetadataResolver)4 Synchronized (lombok.Synchronized)3 SamlException (org.apereo.cas.support.saml.SamlException)3 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)3 List (java.util.List)2 Slf4j (lombok.extern.slf4j.Slf4j)2 CacheLoader (com.github.benmanes.caffeine.cache.CacheLoader)1 Collection (java.util.Collection)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Spliterator (java.util.Spliterator)1 Spliterators (java.util.Spliterators)1 StreamSupport (java.util.stream.StreamSupport)1 AllArgsConstructor (lombok.AllArgsConstructor)1 UtilityClass (lombok.experimental.UtilityClass)1 ComponentInitializationException (net.shibboleth.utilities.java.support.component.ComponentInitializationException)1