Commit cc40dceb authored by Matt Benson's avatar Matt Benson Committed by Phillip Webb

Use canonical paths for Undertow document root

Update `UndertowEmbeddedServletContainerFactory` so that the canonical
path is used when setting up the document root. Prior to this commit
Windows machines with `java.io.tmpdir` set to a tilde-compressed path
would cause problems.

Fixes gh-4765
Closes gh-4766
parent 097e5881
...@@ -427,8 +427,7 @@ public class UndertowEmbeddedServletContainerFactory ...@@ -427,8 +427,7 @@ public class UndertowEmbeddedServletContainerFactory
} }
private ResourceManager getDocumentRootResourceManager() { private ResourceManager getDocumentRootResourceManager() {
File root = getValidDocumentRoot(); File root = getCanonicalDocumentRoot();
root = (root != null ? root : createTempDir("undertow-docbase"));
if (root.isDirectory()) { if (root.isDirectory()) {
return new FileResourceManager(root, 0); return new FileResourceManager(root, 0);
} }
...@@ -438,6 +437,22 @@ public class UndertowEmbeddedServletContainerFactory ...@@ -438,6 +437,22 @@ public class UndertowEmbeddedServletContainerFactory
return ResourceManager.EMPTY_RESOURCE_MANAGER; return ResourceManager.EMPTY_RESOURCE_MANAGER;
} }
/**
* Return the document root in canonical form. Undertow uses File#getCanonicalFile()
* to determine whether a resource has been requested using the proper case but on
* Windows {@code java.io.tmpdir} may be set as a tilde-compressed pathname.
*/
private File getCanonicalDocumentRoot() {
try {
File root = getValidDocumentRoot();
root = (root != null ? root : createTempDir("undertow-docbase"));
return root.getCanonicalFile();
}
catch (IOException e) {
throw new IllegalStateException("Cannot get canonical document root", e);
}
}
private void configureErrorPages(DeploymentInfo servletBuilder) { private void configureErrorPages(DeploymentInfo servletBuilder) {
for (ErrorPage errorPage : getErrorPages()) { for (ErrorPage errorPage : getErrorPages()) {
servletBuilder.addErrorPage(getUndertowErrorPage(errorPage)); servletBuilder.addErrorPage(getUndertowErrorPage(errorPage));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment