Search in sources :

Example 1 with XMLParserException

use of net.shibboleth.utilities.java.support.xml.XMLParserException 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

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ComponentInitializationException (net.shibboleth.utilities.java.support.component.ComponentInitializationException)1 XMLParserException (net.shibboleth.utilities.java.support.xml.XMLParserException)1 DOMMetadataResolver (org.opensaml.saml.metadata.resolver.impl.DOMMetadataResolver)1 EntityDescriptor (org.opensaml.saml.saml2.metadata.EntityDescriptor)1 TechnicalException (org.pac4j.core.exception.TechnicalException)1 SAMLException (org.pac4j.saml.exceptions.SAMLException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1