Package com.sdl.delivery.security.xml
Class SecureXmlProcessingUtils
java.lang.Object
com.sdl.delivery.security.xml.SecureXmlProcessingUtils
This class provides bunch of methods to work securely with XML.
Actually it is a mediator (no need to remember exact class to create).
-
Method Summary
Modifier and TypeMethodDescriptionstatic DocumentBuilderFactorycreateDocumentBuilderFactory(XmlRestriction... restrictions) This method creates a factory which is safe from XXE vulnerability/ See http://cwe.mitre.org/data/definitions/611.html for details.static SAXTransformerFactorycreateSaxTransformerFactory(XmlRestriction... restrictions) Creates a SAX transformer factory to use in XSLT.static TransformercreateTransformer(XmlRestriction... restrictions) Creates a secured transformer for XSLT.static TransformercreateTransformer(String stylesheet, Optional<Map<String, Object>> transformParameters, XmlRestriction... restrictions) Creates a secured transformer for XSLT.static TransformerFactorycreateTransformerFactory(XmlRestriction... restrictions) Creates a transformer factory to use in XSLT.static ValidatorcreateValidator(InputStream xsdStream, XmlRestriction... restrictions) Creates a XML validator to verify XMLs by provided schema.static ValidatorcreateValidator(String xsdContent, XmlRestriction... restrictions) Creates a XML validator to verify XMLs by provided schema.static XMLInputFactorycreateXmlInputFactory(XmlRestriction... restrictions) Creates a XML input factory to use in XSLT Steam Reader.static XmlEqualsResultCompares two given xml strings by transforming them to W3C document and back to strings.
-
Method Details
-
createDocumentBuilderFactory
This method creates a factory which is safe from XXE vulnerability/ See http://cwe.mitre.org/data/definitions/611.html for details.- Returns:
- prepared and tuned DocumentBuilderFactory.
-
createTransformerFactory
Creates a transformer factory to use in XSLT.- Parameters:
restrictions- to allow that transformer working with given protocols.- Returns:
- secured transformer factory
-
createSaxTransformerFactory
Creates a SAX transformer factory to use in XSLT.- Parameters:
restrictions- to allow that transformer working with given protocols.- Returns:
- secured SAX transformer factory
-
createXmlInputFactory
Creates a XML input factory to use in XSLT Steam Reader.- Parameters:
restrictions- to allow that transformer working with given protocols.- Returns:
- secured XML input factory
-
createTransformer
public static Transformer createTransformer(String stylesheet, Optional<Map<String, Object>> transformParameters, XmlRestriction... restrictions) throws TransformerConfigurationExceptionCreates a secured transformer for XSLT.- Parameters:
stylesheet- to make transformer to.transformParameters- stylesheet may have parameters, which are provided here.restrictions- to permit protocols for external resources.- Returns:
- secured transformer
- Throws:
TransformerConfigurationException- if could not create.
-
createTransformer
public static Transformer createTransformer(XmlRestriction... restrictions) throws TransformerConfigurationException Creates a secured transformer for XSLT.- Parameters:
restrictions- to permit protocols for external resources.- Returns:
- secured transformer
- Throws:
TransformerConfigurationException- if could not create.
-
createValidator
public static Validator createValidator(InputStream xsdStream, XmlRestriction... restrictions) throws SAXException Creates a XML validator to verify XMLs by provided schema.- Parameters:
xsdStream- XSD schemarestrictions- array of restrictions for validity- Returns:
- secured validator
- Throws:
SAXException
-
createValidator
public static Validator createValidator(String xsdContent, XmlRestriction... restrictions) throws SAXException Creates a XML validator to verify XMLs by provided schema.- Parameters:
xsdContent- XSD schemarestrictions- array of restrictions for validity- Returns:
- secured validator
- Throws:
SAXException
-
xmlEquals
Compares two given xml strings by transforming them to W3C document and back to strings.- Parameters:
expectedXml-actualXml-- Returns:
- results of comparing
- Throws:
Exception
-