Consistent local vs external resolution of https schema references
Closes gh-22504
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.beans.factory.xml;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -52,7 +53,7 @@ public class BeansDtdResolver implements EntityResolver {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public InputSource resolveEntity(String publicId, @Nullable String systemId) throws IOException {
|
||||
public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws IOException {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Trying to resolve XML entity with public ID [" + publicId +
|
||||
"] and system ID [" + systemId + "]");
|
||||
@@ -76,7 +77,7 @@ public class BeansDtdResolver implements EntityResolver {
|
||||
}
|
||||
return source;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
catch (FileNotFoundException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not resolve beans DTD [" + systemId + "]: not found in classpath", ex);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -79,7 +79,9 @@ public class DelegatingEntityResolver implements EntityResolver {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public InputSource resolveEntity(String publicId, @Nullable String systemId) throws SAXException, IOException {
|
||||
public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId)
|
||||
throws SAXException, IOException {
|
||||
|
||||
if (systemId != null) {
|
||||
if (systemId.endsWith(DTD_SUFFIX)) {
|
||||
return this.dtdResolver.resolveEntity(publicId, systemId);
|
||||
@@ -88,6 +90,8 @@ public class DelegatingEntityResolver implements EntityResolver {
|
||||
return this.schemaResolver.resolveEntity(publicId, systemId);
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to the parser's default behavior.
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ public class PluggableSchemaResolver implements EntityResolver {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public InputSource resolveEntity(String publicId, @Nullable String systemId) throws IOException {
|
||||
public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws IOException {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Trying to resolve XML entity with public id [" + publicId +
|
||||
"] and system id [" + systemId + "]");
|
||||
@@ -114,6 +114,10 @@ public class PluggableSchemaResolver implements EntityResolver {
|
||||
|
||||
if (systemId != null) {
|
||||
String resourceLocation = getSchemaMappings().get(systemId);
|
||||
if (resourceLocation == null && systemId.startsWith("https:")) {
|
||||
// Retrieve canonical http schema mapping even for https declaration
|
||||
resourceLocation = getSchemaMappings().get("http:" + systemId.substring(6));
|
||||
}
|
||||
if (resourceLocation != null) {
|
||||
Resource resource = new ClassPathResource(resourceLocation, this.classLoader);
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,9 +31,9 @@ import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* EntityResolver implementation that tries to resolve entity references
|
||||
* {@code EntityResolver} implementation that tries to resolve entity references
|
||||
* through a {@link org.springframework.core.io.ResourceLoader} (usually,
|
||||
* relative to the resource base of an ApplicationContext), if applicable.
|
||||
* relative to the resource base of an {@code ApplicationContext}), if applicable.
|
||||
* Extends {@link DelegatingEntityResolver} to also provide DTD and XSD lookup.
|
||||
*
|
||||
* <p>Allows to use standard XML entities to include XML snippets into an
|
||||
@@ -72,8 +72,11 @@ public class ResourceEntityResolver extends DelegatingEntityResolver {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public InputSource resolveEntity(String publicId, @Nullable String systemId) throws SAXException, IOException {
|
||||
public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId)
|
||||
throws SAXException, IOException {
|
||||
|
||||
InputSource source = super.resolveEntity(publicId, systemId);
|
||||
|
||||
if (source == null && systemId != null) {
|
||||
String resourcePath = null;
|
||||
try {
|
||||
@@ -105,7 +108,18 @@ public class ResourceEntityResolver extends DelegatingEntityResolver {
|
||||
logger.debug("Found XML entity [" + systemId + "]: " + resource);
|
||||
}
|
||||
}
|
||||
else if (systemId.endsWith(DTD_SUFFIX) || systemId.endsWith(XSD_SUFFIX)) {
|
||||
// External dtd/xsd lookup via https even for canonical http declaration
|
||||
String url = systemId;
|
||||
if (url.startsWith("http:")) {
|
||||
url = "https:" + url.substring(5);
|
||||
}
|
||||
source = new InputSource(url);
|
||||
source.setPublicId(publicId);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user