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 18, 2022
1 parent 6cdea2e commit c4277f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Expand Up @@ -2,7 +2,9 @@

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 All @@ -18,6 +20,8 @@ public class LiquibaseEntityResolver implements EntityResolver2 {

private static ClassLoaderResourceAccessor fallbackResourceAccessor;

private final boolean ALLOW_NETWORK_LOOKUP = false;

@Override
@java.lang.SuppressWarnings("squid:S2095")
public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws SAXException, IOException {
Expand All @@ -41,8 +45,12 @@ public InputSource resolveEntity(String name, String publicId, String baseURI, S
streams = getFallbackResourceAccessor().openStreams(null, path);

if (streams.isEmpty()) {
log.fine("Unable to resolve XML entity locally. Will load from network.");
return null;
if(ALLOW_NETWORK_LOOKUP) {
log.fine("Unable to resolve XML entity locally. Will load from network.");
return null;
} else {
throw new XSDLookUpException("Unable to resolve xml entity : " + path);
}
}
} else if (streams.size() == 1) {
log.fine("Found XML entity at " + streams.getURIs().get(0));
Expand Down
@@ -0,0 +1,9 @@
package liquibase.parser.core.xml;

public class XSDLookUpException extends RuntimeException{

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

}

0 comments on commit c4277f1

Please sign in to comment.