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;
}
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.");
}
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;
}
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;
}
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);
}
}
}
Aggregations