diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/opensaml/OpenSamlObjects.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/opensaml/OpenSamlObjects.java index 3a7114eb0..8a25b0855 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/opensaml/OpenSamlObjects.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/opensaml/OpenSamlObjects.java @@ -5,6 +5,7 @@ import net.shibboleth.utilities.java.support.component.ComponentInitializationException; import net.shibboleth.utilities.java.support.xml.BasicParserPool; import net.shibboleth.utilities.java.support.xml.ParserPool; +import net.shibboleth.utilities.java.support.xml.XMLParserException; import org.opensaml.core.config.ConfigurationService; import org.opensaml.core.config.InitializationException; import org.opensaml.core.xml.XMLObject; @@ -15,6 +16,7 @@ import org.opensaml.core.xml.io.MarshallingException; import org.opensaml.core.xml.io.Unmarshaller; import org.opensaml.core.xml.io.UnmarshallerFactory; +import org.opensaml.core.xml.io.UnmarshallingException; import org.opensaml.saml.saml2.metadata.EntityDescriptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -130,6 +132,17 @@ public EntityDescriptor unmarshalFromXml(byte[] entityDescriptorXml) throws Exce } } + public T unmarshallFromXml(byte[] xml, Class type) throws IOException, XMLParserException, UnmarshallingException { + try (InputStream is = ByteSource.wrap(xml).openBufferedStream()) { + Document d = this.parserPool.parse(is); + Unmarshaller unmarshaller = this.unmarshallerFactory.getUnmarshaller(d.getDocumentElement()); + if (unmarshaller != null) { + return type.cast(unmarshaller.unmarshall(d.getDocumentElement())); + } + return null; + } + } + // TODO: yeah, I'm not happy with this... public T buildDefaultInstanceOfType(Class type) { try {