Skip to content

Commit

Permalink
[XSDLookUp] Updated entity resolver to not fallback to network lookup…
Browse files Browse the repository at this point in the history
… when xsd is not found
  • Loading branch information
Kavya Shastri committed Feb 21, 2022
1 parent 6cdea2e commit 61a1936
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package liquibase.parser.core.xml;

import liquibase.GlobalConfiguration;
import liquibase.Scope;
import liquibase.logging.Logger;
import liquibase.resource.*;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.resource.InputStreamList;
import liquibase.resource.ResourceAccessor;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.ext.EntityResolver2;
Expand Down Expand Up @@ -34,13 +37,18 @@ public InputSource resolveEntity(String name, String publicId, String baseURI, S
.replace("http://www.liquibase.org/xml/ns/migrator/", "http://www.liquibase.org/xml/ns/dbchangelog/")
.replaceFirst("https?://", "");


ResourceAccessor resourceAccessor = Scope.getCurrentScope().getResourceAccessor();
InputStreamList streams = resourceAccessor.openStreams(null, path);
if (streams.isEmpty()) {
streams = getFallbackResourceAccessor().openStreams(null, path);

if (streams.isEmpty()) {
if (streams.isEmpty() && GlobalConfiguration.SECURE_PARSING.getCurrentValue()) {
String errorMessage = "Unable to resolve xml entity locally : " +
path +
"\nGlobalConfiguration.SECURE_PARSING is set to true which only checks for locally packaged xsd files with liquibase." +
"\nPlease set the flag to FALSE to allow remote lookups for xsd.";
throw new XSDLookUpException(errorMessage);
} else {
log.fine("Unable to resolve XML entity locally. Will load from network.");
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package liquibase.parser.core.xml;

public class XSDLookUpException extends RuntimeException{

public XSDLookUpException(String message) {
super(message);
}

}

0 comments on commit 61a1936

Please sign in to comment.