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;
}
Aggregations