Skip to content

Commit

Permalink
Issue ehcache#3242 : Validate user provided DOM trees
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdennis committed Aug 21, 2024
1 parent 60c7bfd commit d5dc57a
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

import java.io.BufferedReader;
Expand Down Expand Up @@ -228,6 +229,10 @@ public Document uriToDocument(URI uri) throws IOException, SAXException {
}

public XmlConfigurationWrapper documentToConfig(Document document, ClassLoader classLoader, Map<String, ClassLoader> cacheClassLoaders) throws JAXBException, ClassNotFoundException, InstantiationException, IllegalAccessException {
Validator validator = schema.newValidator();
validator.setErrorHandler(new FatalErrorHandler());
validator.validate(new DOMSource(document));

Document annotatedDocument = stampExternalConfigurations(copyAndValidate(document));
Element root = annotatedDocument.getDocumentElement();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.ehcache.xml.exceptions.XmlConfigurationException;
import org.w3c.dom.Document;

import javax.xml.transform.dom.DOMSource;
import java.lang.reflect.Array;
import java.net.URL;
import java.util.Collection;
Expand Down Expand Up @@ -202,7 +203,11 @@ public XmlConfiguration(Configuration configuration) throws XmlConfigurationExce
try {
ConfigurationParser parser = new ConfigurationParser();
this.configuration = configuration;
this.templates = emptyMap();
if (configuration instanceof XmlConfiguration) {
this.templates = ((XmlConfiguration) configuration).templates;
} else {
this.templates = emptyMap();
}

this.document = parser.configToDocument(configuration);
this.renderedDocument = documentToText(document);
Expand Down
Loading

0 comments on commit d5dc57a

Please sign in to comment.