Search in sources :

Example 41 with EntityDescriptor

use of org.opensaml.saml2.metadata.EntityDescriptor in project pac4j by pac4j.

the class SAML2IdentityProviderMetadataResolverTest method resolveMetadataEntityId.

@Test
public void resolveMetadataEntityId() throws Exception {
    MetadataResolver resolver = metadataResolver.resolve();
    CriteriaSet criteria = new CriteriaSet(new EntityIdCriterion("mmoayyed.example.net"));
    final EntityDescriptor entity = resolver.resolveSingle(criteria);
    assertEquals(entity.getEntityID(), "mmoayyed.example.net");
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) CriteriaSet(net.shibboleth.utilities.java.support.resolver.CriteriaSet) EntityIdCriterion(org.opensaml.core.criterion.EntityIdCriterion) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) Test(org.junit.Test)

Example 42 with EntityDescriptor

use of org.opensaml.saml2.metadata.EntityDescriptor in project pac4j by pac4j.

the class SAML2MetadataGenerator method getMetadata.

@Override
public final String getMetadata() throws Exception {
    final EntityDescriptor md = buildEntityDescriptor();
    final Element entityDescriptorElement = this.marshallerFactory.getMarshaller(md).marshall(md);
    return SerializeSupport.nodeToString(entityDescriptorElement);
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) Element(org.w3c.dom.Element)

Example 43 with EntityDescriptor

use of org.opensaml.saml2.metadata.EntityDescriptor in project pac4j by pac4j.

the class SAML2MetadataGenerator method buildEntityDescriptor.

@Override
public final EntityDescriptor buildEntityDescriptor() {
    final SAMLObjectBuilder<EntityDescriptor> builder = (SAMLObjectBuilder<EntityDescriptor>) this.builderFactory.getBuilder(EntityDescriptor.DEFAULT_ELEMENT_NAME);
    final EntityDescriptor descriptor = builder.buildObject();
    descriptor.setEntityID(this.entityId);
    descriptor.setValidUntil(DateTime.now(DateTimeZone.UTC).plusYears(20));
    descriptor.setID(generateEntityDescriptorId());
    descriptor.setExtensions(generateMetadataExtensions());
    descriptor.getRoleDescriptors().add(buildSPSSODescriptor());
    return descriptor;
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) SAMLObjectBuilder(org.opensaml.saml.common.SAMLObjectBuilder)

Example 44 with EntityDescriptor

use of org.opensaml.saml2.metadata.EntityDescriptor in project pac4j by pac4j.

the class SAML2MetadataGenerator method buildMetadataResolver.

@Override
public final MetadataResolver buildMetadataResolver() throws Exception {
    final EntityDescriptor md = buildEntityDescriptor();
    final Element entityDescriptorElement = this.marshallerFactory.getMarshaller(md).marshall(md);
    final DOMMetadataResolver resolver = new DOMMetadataResolver(entityDescriptorElement);
    resolver.setRequireValidMetadata(true);
    resolver.setFailFastInitialization(true);
    resolver.setId(resolver.getClass().getCanonicalName());
    resolver.initialize();
    return resolver;
}
Also used : DOMMetadataResolver(org.opensaml.saml.metadata.resolver.impl.DOMMetadataResolver) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) Element(org.w3c.dom.Element)

Example 45 with EntityDescriptor

use of org.opensaml.saml2.metadata.EntityDescriptor in project pac4j by pac4j.

the class SAML2IdentityProviderMetadataResolver method resolve.

@Override
public final MetadataResolver resolve() {
    // Usage of locks will adversly impact performance.
    if (idpMetadataProvider != null) {
        return idpMetadataProvider;
    }
    try {
        if (this.idpMetadataResource == null) {
            throw new XMLParserException("idp metadata cannot be resolved from " + this.idpMetadataResource);
        }
        try (final InputStream in = this.idpMetadataResource.getInputStream()) {
            final Document inCommonMDDoc = Configuration.getParserPool().parse(in);
            final Element metadataRoot = inCommonMDDoc.getDocumentElement();
            idpMetadataProvider = new DOMMetadataResolver(metadataRoot);
            idpMetadataProvider.setParserPool(Configuration.getParserPool());
            idpMetadataProvider.setFailFastInitialization(true);
            idpMetadataProvider.setRequireValidMetadata(true);
            idpMetadataProvider.setId(idpMetadataProvider.getClass().getCanonicalName());
            idpMetadataProvider.initialize();
        } catch (final FileNotFoundException e) {
            throw new TechnicalException("Error loading idp Metadata");
        }
        // If no idpEntityId declared, select first EntityDescriptor entityId as our IDP entityId
        if (this.idpEntityId == null) {
            final Iterator<EntityDescriptor> it = idpMetadataProvider.iterator();
            while (it.hasNext()) {
                final EntityDescriptor entityDescriptor = it.next();
                if (this.idpEntityId == null) {
                    this.idpEntityId = entityDescriptor.getEntityID();
                }
            }
        }
        if (this.idpEntityId == null) {
            throw new SAMLException("No idp entityId found");
        }
    } catch (final ComponentInitializationException e) {
        throw new SAMLException("Error initializing idpMetadataProvider", e);
    } catch (final XMLParserException e) {
        throw new TechnicalException("Error parsing idp Metadata", e);
    } catch (final IOException e) {
        throw new TechnicalException("Error getting idp Metadata resource", e);
    }
    return idpMetadataProvider;
}
Also used : DOMMetadataResolver(org.opensaml.saml.metadata.resolver.impl.DOMMetadataResolver) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) TechnicalException(org.pac4j.core.exception.TechnicalException) ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) XMLParserException(net.shibboleth.utilities.java.support.xml.XMLParserException) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAMLException(org.pac4j.saml.exceptions.SAMLException)

Aggregations

EntityDescriptor (org.opensaml.saml.saml2.metadata.EntityDescriptor)60 Test (org.junit.jupiter.api.Test)15 KeyDescriptor (org.opensaml.saml.saml2.metadata.KeyDescriptor)13 EntityDescriptorBuilder.anEntityDescriptor (uk.gov.ida.saml.core.test.builders.metadata.EntityDescriptorBuilder.anEntityDescriptor)11 CriteriaSet (net.shibboleth.utilities.java.support.resolver.CriteriaSet)8 Test (org.junit.Test)8 IDPSSODescriptor (org.opensaml.saml.saml2.metadata.IDPSSODescriptor)8 SingleSignOnService (org.opensaml.saml.saml2.metadata.SingleSignOnService)8 List (java.util.List)7 EntityIdCriterion (org.opensaml.core.criterion.EntityIdCriterion)7 AssertionConsumerService (org.opensaml.saml.saml2.metadata.AssertionConsumerService)7 X509Certificate (org.opensaml.xmlsec.signature.X509Certificate)7 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 SPSSODescriptor (org.opensaml.saml.saml2.metadata.SPSSODescriptor)6 InputStreamReader (java.io.InputStreamReader)5 SamlRegisteredServiceServiceProviderMetadataFacade (org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade)5 SamlRegisteredServiceCachingMetadataResolver (org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver)5 ApplicationContext (org.springframework.context.ApplicationContext)5