use of org.opensaml.saml.metadata.resolver.MetadataResolver in project cas by apereo.
the class SamlIdPUtils method getMetadataResolverForAllSamlServices.
/**
* Gets chaining metadata resolver for all saml services.
*
* @param servicesManager the services manager
* @param entityID the entity id
* @param resolver the resolver
* @return the chaining metadata resolver for all saml services
*/
@SneakyThrows
public static MetadataResolver getMetadataResolverForAllSamlServices(final ServicesManager servicesManager, final String entityID, final SamlRegisteredServiceCachingMetadataResolver resolver) {
final Collection<RegisteredService> registeredServices = servicesManager.findServiceBy(SamlRegisteredService.class::isInstance);
final List<MetadataResolver> resolvers;
final ChainingMetadataResolver chainingMetadataResolver = new ChainingMetadataResolver();
resolvers = registeredServices.stream().filter(SamlRegisteredService.class::isInstance).map(SamlRegisteredService.class::cast).map(s -> SamlRegisteredServiceServiceProviderMetadataFacade.get(resolver, s, entityID)).filter(Optional::isPresent).map(Optional::get).map(SamlRegisteredServiceServiceProviderMetadataFacade::getMetadataResolver).collect(Collectors.toList());
LOGGER.debug("Located [{}] metadata resolvers to match against [{}]", resolvers, entityID);
chainingMetadataResolver.setResolvers(resolvers);
chainingMetadataResolver.setId(entityID);
chainingMetadataResolver.initialize();
return chainingMetadataResolver;
}
use of org.opensaml.saml.metadata.resolver.MetadataResolver in project cas by apereo.
the class SamlRegisteredServiceServiceProviderMetadataFacade method get.
@SneakyThrows
private static Optional<SamlRegisteredServiceServiceProviderMetadataFacade> get(final SamlRegisteredServiceCachingMetadataResolver resolver, final SamlRegisteredService registeredService, final String entityID, final CriteriaSet criterions) {
LOGGER.debug("Adapting SAML metadata for CAS service [{}] issued by [{}]", registeredService.getName(), entityID);
criterions.add(new EntityIdCriterion(entityID), true);
LOGGER.debug("Locating metadata for entityID [{}] by attempting to run through the metadata chain...", entityID);
final MetadataResolver chainingMetadataResolver = resolver.resolve(registeredService);
LOGGER.info("Resolved metadata chain for service [{}]. Filtering the chain by entity ID [{}]", registeredService.getServiceId(), entityID);
final EntityDescriptor entityDescriptor = chainingMetadataResolver.resolveSingle(criterions);
if (entityDescriptor == null) {
LOGGER.warn("Cannot find entity [{}] in metadata provider Ensure the metadata is valid and has not expired.", entityID);
return Optional.empty();
}
LOGGER.debug("Located entity descriptor in metadata for [{}]", entityID);
if (entityDescriptor.getValidUntil() != null && entityDescriptor.getValidUntil().isBeforeNow()) {
LOGGER.warn("Entity descriptor in the metadata has expired at [{}]", entityDescriptor.getValidUntil());
return Optional.empty();
}
return getServiceProviderSsoDescriptor(entityID, chainingMetadataResolver, entityDescriptor);
}
use of org.opensaml.saml.metadata.resolver.MetadataResolver in project cas by apereo.
the class MongoDbSamlRegisteredServiceMetadataResolverTests method verifyResolver.
@Test
public void verifyResolver() {
final SamlRegisteredService service = new SamlRegisteredService();
service.setName("SAML Service");
service.setServiceId("https://carmenwiki.osu.edu/shibboleth");
service.setDescription("Testing");
service.setMetadataLocation("mongodb://");
assertTrue(resolver.supports(service));
final Collection<MetadataResolver> resolvers = resolver.resolve(service);
assertTrue(resolvers.size() == 1);
}
use of org.opensaml.saml.metadata.resolver.MetadataResolver in project cas by apereo.
the class RestSamlRegisteredServiceMetadataResolver method resolve.
@Override
public Collection<MetadataResolver> resolve(final SamlRegisteredService service) {
try {
final RestSamlMetadataProperties rest = samlIdPProperties.getMetadata().getRest();
final HttpResponse response = HttpUtils.execute(rest.getUrl(), rest.getMethod(), rest.getBasicAuthUsername(), rest.getBasicAuthPassword(), CollectionUtils.wrap("entityId", service.getServiceId()), CollectionUtils.wrap("Content-Type", MediaType.APPLICATION_XML_VALUE));
if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
final SamlMetadataDocument doc = MAPPER.readValue(response.getEntity().getContent(), SamlMetadataDocument.class);
final MetadataResolver resolver = buildMetadataResolverFrom(service, doc);
return CollectionUtils.wrapList(resolver);
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
use of org.opensaml.saml.metadata.resolver.MetadataResolver in project cas by apereo.
the class RestSamlRegisteredServiceMetadataResolverTests method verifyRestEndpointProducesMetadata.
@Test
public void verifyRestEndpointProducesMetadata() {
final SamlRegisteredService service = new SamlRegisteredService();
service.setName("SAML Wiki Service");
service.setServiceId("https://carmenwiki.osu.edu/shibboleth");
service.setDescription("Testing");
service.setMetadataLocation("rest://");
assertTrue(resolver.supports(service));
final Collection<MetadataResolver> resolvers = resolver.resolve(service);
assertTrue(resolvers.size() == 1);
}
Aggregations