Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3242 : Validate user provided DOM trees #3244

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading