From cc40dcebcfa9250578ac8cf68a8b15aad4985bd2 Mon Sep 17 00:00:00 2001 From: Matt Benson Date: Fri, 11 Dec 2015 16:04:13 -0600 Subject: [PATCH] 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 --- ...dertowEmbeddedServletContainerFactory.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java index ddae4e55f9e..2a9588f8b37 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java @@ -427,8 +427,7 @@ public class UndertowEmbeddedServletContainerFactory } private ResourceManager getDocumentRootResourceManager() { - File root = getValidDocumentRoot(); - root = (root != null ? root : createTempDir("undertow-docbase")); + File root = getCanonicalDocumentRoot(); if (root.isDirectory()) { return new FileResourceManager(root, 0); } @@ -438,6 +437,22 @@ public class UndertowEmbeddedServletContainerFactory 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) { for (ErrorPage errorPage : getErrorPages()) { servletBuilder.addErrorPage(getUndertowErrorPage(errorPage));