Search in sources :

Example 11 with MetadataResolver

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;
}
Also used : MessageContext(org.opensaml.messaging.context.MessageContext) BindingCriterion(org.opensaml.saml.criterion.BindingCriterion) SneakyThrows(lombok.SneakyThrows) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) StringUtils(org.apache.commons.lang3.StringUtils) UtilityClass(lombok.experimental.UtilityClass) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) CollectionUtils(org.apereo.cas.util.CollectionUtils) RoleDescriptorResolver(org.opensaml.saml.metadata.resolver.RoleDescriptorResolver) SAMLConstants(org.opensaml.saml.common.xml.SAMLConstants) ServicesManager(org.apereo.cas.services.ServicesManager) AssertionConsumerServiceBuilder(org.opensaml.saml.saml2.metadata.impl.AssertionConsumerServiceBuilder) AssertionConsumerService(org.opensaml.saml.saml2.metadata.AssertionConsumerService) Collection(java.util.Collection) PredicateRoleDescriptorResolver(org.opensaml.saml.metadata.resolver.impl.PredicateRoleDescriptorResolver) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) RequestAbstractType(org.opensaml.saml.saml2.core.RequestAbstractType) Collectors(java.util.stream.Collectors) RegisteredService(org.apereo.cas.services.RegisteredService) Endpoint(org.opensaml.saml.saml2.metadata.Endpoint) SPSSODescriptor(org.opensaml.saml.saml2.metadata.SPSSODescriptor) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) EntityRoleCriterion(org.opensaml.saml.criterion.EntityRoleCriterion) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) SAMLEndpointContext(org.opensaml.saml.common.messaging.context.SAMLEndpointContext) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) SamlRegisteredServiceServiceProviderMetadataFacade(org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade) SAMLPeerEntityContext(org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext) Optional(java.util.Optional) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) Optional(java.util.Optional) SamlRegisteredServiceServiceProviderMetadataFacade(org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) SneakyThrows(lombok.SneakyThrows)

Example 12 with MetadataResolver

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);
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) SneakyThrows(lombok.SneakyThrows)

Example 13 with MetadataResolver

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);
}
Also used : SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) SamlRegisteredServiceMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.SamlRegisteredServiceMetadataResolver) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 14 with MetadataResolver

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;
}
Also used : RestSamlMetadataProperties(org.apereo.cas.configuration.model.support.saml.idp.metadata.RestSamlMetadataProperties) HttpResponse(org.apache.http.HttpResponse) SamlMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlMetadataDocument) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) BaseSamlRegisteredServiceMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.BaseSamlRegisteredServiceMetadataResolver)

Example 15 with MetadataResolver

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);
}
Also used : SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) SamlRegisteredServiceMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.SamlRegisteredServiceMetadataResolver) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

MetadataResolver (org.opensaml.saml.metadata.resolver.MetadataResolver)17 ChainingMetadataResolver (org.opensaml.saml.metadata.resolver.ChainingMetadataResolver)7 ArrayList (java.util.ArrayList)6 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)6 SneakyThrows (lombok.SneakyThrows)5 SamlRegisteredServiceCachingMetadataResolver (org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver)4 SamlRegisteredServiceMetadataResolver (org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.SamlRegisteredServiceMetadataResolver)4 Test (org.junit.Test)4 EntityDescriptor (org.opensaml.saml.saml2.metadata.EntityDescriptor)4 List (java.util.List)3 Slf4j (lombok.extern.slf4j.Slf4j)3 CriteriaSet (net.shibboleth.utilities.java.support.resolver.CriteriaSet)3 EntityIdCriterion (org.opensaml.core.criterion.EntityIdCriterion)3 SPSSODescriptor (org.opensaml.saml.saml2.metadata.SPSSODescriptor)3 Provides (com.google.inject.Provides)2 Collection (java.util.Collection)2 Optional (java.util.Optional)2 Named (javax.inject.Named)2 Singleton (javax.inject.Singleton)2 Synchronized (lombok.Synchronized)2