From 613e0ecd54fc5638c0a8e3ac5730c0c62751400a Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 2 Mar 2021 14:40:36 -0600 Subject: [PATCH 01/10] Issue #6021 - PoC for resolvePath within XmlConfiguration Signed-off-by: Joakim Erdfelt --- .../src/main/config/etc/jetty-deploy.xml | 10 +-- .../global-webapp-common.xml | 10 +-- .../main/resources/modules/hawtio/hawtio.xml | 2 +- .../main/resources/modules/jamon/jamon.xml | 2 +- .../resources/modules/jolokia/jolokia.xml | 2 +- .../infinispan/infinispan-embedded-query.xml | 2 +- .../infinispan/infinispan-embedded.xml | 2 +- .../infinispan/infinispan-remote-query.xml | 6 +- .../remote/other_proto_marshallers.xml | 2 +- .../sessions/infinispan/infinispan-remote.xml | 2 +- jetty-jaas/src/main/config/etc/jetty-jaas.xml | 7 +- .../main/config/etc/jetty-test-keystore.xml | 7 +- .../src/main/config/modules/test-keystore.mod | 3 - .../src/main/resources/maven.xml | 2 +- .../src/test/config/etc/jetty-ssl.xml | 4 +- .../src/main/config/etc/jetty-requestlog.xml | 11 +-- .../src/main/config/etc/jetty-ssl-context.xml | 18 ++--- .../jetty/util/ssl/SslContextFactory.java | 15 +++- .../eclipse/jetty/xml/XmlConfiguration.java | 24 ++++++ .../jetty/xml/XmlConfigurationTest.java | 73 +++++++++++++++++++ 20 files changed, 155 insertions(+), 49 deletions(-) diff --git a/jetty-deploy/src/main/config/etc/jetty-deploy.xml b/jetty-deploy/src/main/config/etc/jetty-deploy.xml index d244576c1464..45d71dde0396 100644 --- a/jetty-deploy/src/main/config/etc/jetty-deploy.xml +++ b/jetty-deploy/src/main/config/etc/jetty-deploy.xml @@ -40,12 +40,10 @@ - - jetty.deploy.monitoredPath - - / - - + + + + diff --git a/jetty-deploy/src/main/config/modules/global-webapp-common.d/global-webapp-common.xml b/jetty-deploy/src/main/config/modules/global-webapp-common.d/global-webapp-common.xml index 41f3d202a630..93959f7423b0 100644 --- a/jetty-deploy/src/main/config/modules/global-webapp-common.d/global-webapp-common.xml +++ b/jetty-deploy/src/main/config/modules/global-webapp-common.d/global-webapp-common.xml @@ -7,12 +7,10 @@ - - jetty.deploy.webappCommonConfig - - /etc/webapp-common.xml - - + + + /etc/webapp-common.xml + diff --git a/jetty-home/src/main/resources/modules/hawtio/hawtio.xml b/jetty-home/src/main/resources/modules/hawtio/hawtio.xml index 922bcac7f46d..8b66e0362928 100644 --- a/jetty-home/src/main/resources/modules/hawtio/hawtio.xml +++ b/jetty-home/src/main/resources/modules/hawtio/hawtio.xml @@ -6,7 +6,7 @@ /hawtio - /lib/hawtio/hawtio.war + /lib/hawtio/hawtio.war true false /etc/webdefault.xml diff --git a/jetty-home/src/main/resources/modules/jamon/jamon.xml b/jetty-home/src/main/resources/modules/jamon/jamon.xml index 14e2e6ea1e41..e4356d4833fc 100644 --- a/jetty-home/src/main/resources/modules/jamon/jamon.xml +++ b/jetty-home/src/main/resources/modules/jamon/jamon.xml @@ -20,7 +20,7 @@ /jamon - /lib/jamon/jamon.war + /lib/jamon/jamon.war true false /etc/webdefault.xml diff --git a/jetty-home/src/main/resources/modules/jolokia/jolokia.xml b/jetty-home/src/main/resources/modules/jolokia/jolokia.xml index d8f511fbca13..5c46f501a556 100644 --- a/jetty-home/src/main/resources/modules/jolokia/jolokia.xml +++ b/jetty-home/src/main/resources/modules/jolokia/jolokia.xml @@ -6,7 +6,7 @@ /jolokia - /lib/jolokia/jolokia.war + /lib/jolokia/jolokia.war true false /etc/webdefault.xml diff --git a/jetty-infinispan/infinispan-embedded-query/src/main/config-template/etc/sessions/infinispan/infinispan-embedded-query.xml b/jetty-infinispan/infinispan-embedded-query/src/main/config-template/etc/sessions/infinispan/infinispan-embedded-query.xml index bb0b18061d8d..7a434e8bb485 100644 --- a/jetty-infinispan/infinispan-embedded-query/src/main/config-template/etc/sessions/infinispan/infinispan-embedded-query.xml +++ b/jetty-infinispan/infinispan-embedded-query/src/main/config-template/etc/sessions/infinispan/infinispan-embedded-query.xml @@ -39,7 +39,7 @@ - /etc/infinispan.xml + /etc/infinispan.xml diff --git a/jetty-infinispan/infinispan-embedded/src/main/config-templates/etc/sessions/infinispan/infinispan-embedded.xml b/jetty-infinispan/infinispan-embedded/src/main/config-templates/etc/sessions/infinispan/infinispan-embedded.xml index a0175b02b7f8..ee0b60b7ab94 100644 --- a/jetty-infinispan/infinispan-embedded/src/main/config-templates/etc/sessions/infinispan/infinispan-embedded.xml +++ b/jetty-infinispan/infinispan-embedded/src/main/config-templates/etc/sessions/infinispan/infinispan-embedded.xml @@ -7,7 +7,7 @@ - /etc/infinispan.xml + /etc/infinispan.xml diff --git a/jetty-infinispan/infinispan-remote-query/src/main/config-template/etc/sessions/infinispan/infinispan-remote-query.xml b/jetty-infinispan/infinispan-remote-query/src/main/config-template/etc/sessions/infinispan/infinispan-remote-query.xml index 6faf65608f80..389a18428745 100644 --- a/jetty-infinispan/infinispan-remote-query/src/main/config-template/etc/sessions/infinispan/infinispan-remote-query.xml +++ b/jetty-infinispan/infinispan-remote-query/src/main/config-template/etc/sessions/infinispan/infinispan-remote-query.xml @@ -24,9 +24,9 @@ - - /resources/hotrod-client.properties - + + /resources/hotrod-client.properties + diff --git a/jetty-infinispan/infinispan-remote-query/src/main/config-template/modules/sessions/infinispan/remote/other_proto_marshallers.xml b/jetty-infinispan/infinispan-remote-query/src/main/config-template/modules/sessions/infinispan/remote/other_proto_marshallers.xml index 64d34bf32f90..479daf8f657a 100644 --- a/jetty-infinispan/infinispan-remote-query/src/main/config-template/modules/sessions/infinispan/remote/other_proto_marshallers.xml +++ b/jetty-infinispan/infinispan-remote-query/src/main/config-template/modules/sessions/infinispan/remote/other_proto_marshallers.xml @@ -19,7 +19,7 @@ my.proto - /etc/my.proto + /etc/my.proto diff --git a/jetty-infinispan/infinispan-remote/src/main/config-template/etc/sessions/infinispan/infinispan-remote.xml b/jetty-infinispan/infinispan-remote/src/main/config-template/etc/sessions/infinispan/infinispan-remote.xml index 8debcd88e695..7fa442548a04 100644 --- a/jetty-infinispan/infinispan-remote/src/main/config-template/etc/sessions/infinispan/infinispan-remote.xml +++ b/jetty-infinispan/infinispan-remote/src/main/config-template/etc/sessions/infinispan/infinispan-remote.xml @@ -10,7 +10,7 @@ - /resources/hotrod-client.properties + /resources/hotrod-client.properties diff --git a/jetty-jaas/src/main/config/etc/jetty-jaas.xml b/jetty-jaas/src/main/config/etc/jetty-jaas.xml index d973ec20eb09..881b23292a05 100644 --- a/jetty-jaas/src/main/config/etc/jetty-jaas.xml +++ b/jetty-jaas/src/main/config/etc/jetty-jaas.xml @@ -10,7 +10,12 @@ java.security.auth.login.config - / + + + + + + diff --git a/jetty-keystore/src/main/config/etc/jetty-test-keystore.xml b/jetty-keystore/src/main/config/etc/jetty-test-keystore.xml index 3781bc57f815..e7c398596579 100644 --- a/jetty-keystore/src/main/config/etc/jetty-test-keystore.xml +++ b/jetty-keystore/src/main/config/etc/jetty-test-keystore.xml @@ -3,7 +3,12 @@ - / + + + + + + diff --git a/jetty-keystore/src/main/config/modules/test-keystore.mod b/jetty-keystore/src/main/config/modules/test-keystore.mod index 6198f30e36e2..dca5a6518315 100644 --- a/jetty-keystore/src/main/config/modules/test-keystore.mod +++ b/jetty-keystore/src/main/config/modules/test-keystore.mod @@ -27,6 +27,3 @@ jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/bouncycastle/ jetty.sslContext.keyStorePath?=etc/test-keystore.p12 jetty.sslContext.keyStoreType?=PKCS12 jetty.sslContext.keyStorePassword?=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4 -jetty.sslContext.trustStorePath?=etc/test-keystore.p12 -jetty.sslContext.trustStoreType?=PKCS12 -jetty.sslContext.keyStorePassword?=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4 diff --git a/jetty-maven-plugin/src/main/resources/maven.xml b/jetty-maven-plugin/src/main/resources/maven.xml index 36dec030c946..98cf64733c34 100644 --- a/jetty-maven-plugin/src/main/resources/maven.xml +++ b/jetty-maven-plugin/src/main/resources/maven.xml @@ -7,7 +7,7 @@ - /etc/maven.props + /etc/maven.props diff --git a/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-ssl.xml b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-ssl.xml index 178ae88fa362..b25525dec5cd 100644 --- a/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-ssl.xml +++ b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-ssl.xml @@ -31,9 +31,9 @@ - / + / - / + / diff --git a/jetty-server/src/main/config/etc/jetty-requestlog.xml b/jetty-server/src/main/config/etc/jetty-requestlog.xml index 3e87e5c0555c..58a201e96ba7 100644 --- a/jetty-server/src/main/config/etc/jetty-requestlog.xml +++ b/jetty-server/src/main/config/etc/jetty-requestlog.xml @@ -15,11 +15,12 @@ - / - jetty.requestlog.filePath - /yyyy_mm_dd.request.log - - + + + + /yyyy_mm_dd.request.log + + diff --git a/jetty-server/src/main/config/etc/jetty-ssl-context.xml b/jetty-server/src/main/config/etc/jetty-ssl-context.xml index 0c8c739c90b2..8e4fbbc87bf2 100644 --- a/jetty-server/src/main/config/etc/jetty-ssl-context.xml +++ b/jetty-server/src/main/config/etc/jetty-ssl-context.xml @@ -6,22 +6,20 @@ - - - / - - + + + + - - - / - - + + + + diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java index b00f608546ad..d868e2b4a9c6 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java @@ -708,13 +708,20 @@ public String getTrustStorePath() */ public void setTrustStorePath(String trustStorePath) { - try + if (StringUtil.isEmpty(trustStorePath)) { - _trustStoreResource = Resource.newResource(trustStorePath); + _trustStoreResource = null; } - catch (Exception e) + else { - throw new IllegalArgumentException(e); + try + { + _trustStoreResource = Resource.newResource(trustStorePath); + } + catch (Exception e) + { + throw new IllegalArgumentException(e); + } } } diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index 7872e9319537..7e2de36562c0 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -28,6 +28,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.UnknownHostException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.security.AccessController; @@ -331,6 +332,29 @@ public void initializeDefaults(Object object) { } + /** + * Utility method to resolve a provided path against a base directory. + * + * @param baseDir the base directory + * @param destPath the destination path (can be relative or absolute, syntax depends on OS + FileSystem in use) + * @return String to resolved and normalized path, or null if baseDir or destPath is empty. + */ + public static String resolvePath(String baseDir, String destPath) + { + if (StringUtil.isEmpty(baseDir) || StringUtil.isEmpty(destPath)) + return null; + + Path base = Paths.get(baseDir); + + if (!Files.exists(base)) + { + // Add warning to debug output + LOG.debug("Configured baseDir={} does not exist", baseDir); + } + + return base.resolve(destPath).normalize().toString(); + } + private static class JettyXmlConfiguration implements ConfigurationProcessor { XmlParser.Node _root; diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java index 4a977c6a78b0..51b3d51cf5b2 100644 --- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java @@ -15,6 +15,7 @@ import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; @@ -31,10 +32,12 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.jetty.logging.JettyLevel; import org.eclipse.jetty.logging.JettyLogger; import org.eclipse.jetty.logging.StdErrAppender; +import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; @@ -48,6 +51,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -1588,6 +1592,75 @@ public void testDeprecated() throws Exception assertEquals(6, warnings.size()); } + public static Stream resolvePathCases() + { + return Stream.of( + // Not configured, default (in xml) is used. + Arguments.of(null, "/var/lib/jetty-base/etc/keystore.p12"), + // Configured using normal relative path + Arguments.of("alt/keystore", "/var/lib/jetty-base/alt/keystore"), + // Configured using navigated path segments + Arguments.of("../corp/etc/keystore", "/var/lib/corp/etc/keystore"), + // Configured using absolute path + Arguments.of("/opt/jetty/etc/keystore", "/opt/jetty/etc/keystore") + ); + } + + @ParameterizedTest + @MethodSource("resolvePathCases") + public void testCallResolvePath(String configValue, String expectedPath) throws Exception + { + Path war = MavenTestingUtils.getTargetPath("no.war"); + XmlConfiguration configuration = + asXmlConfiguration( + "" + + " " + + " " + + " " + + " " + + " " + + " " + + ""); + + configuration.setJettyStandardIdsAndProperties(null, Resource.newResource(war)); + configuration.getProperties().put("jetty.base", "/var/lib/jetty-base"); + if (configValue != null) + configuration.getProperties().put("jetty.sslContext.keyStorePath", configValue); + + TestConfiguration tc = new TestConfiguration(); + configuration.configure(tc); + + assertThat(tc.getTestString(), is(expectedPath)); + } + + @Test + public void testResolvePathRelative() + { + Path testPath = MavenTestingUtils.getTargetTestingPath("testResolvePathRelative"); + FS.ensureDirExists(testPath); + String resolved = XmlConfiguration.resolvePath(testPath.toString(), "etc/keystore"); + assertEquals(testPath.toString() + File.separator + "etc/keystore", resolved); + } + + @Test + public void testResolvePathAbsolute() + { + Path testPath = MavenTestingUtils.getTargetTestingPath("testResolvePathRelative"); + FS.ensureDirExists(testPath); + String resolved = XmlConfiguration.resolvePath(testPath.toString(), "/tmp/etc/keystore"); + assertEquals("/tmp/etc/keystore", resolved); + } + + @Test + public void testResolvePathInvalidBase() + { + Path testPath = MavenTestingUtils.getTargetTestingPath("testResolvePathRelative"); + FS.ensureDeleted(testPath); + Path baseDir = testPath.resolve("bogus"); + String resolved = XmlConfiguration.resolvePath(baseDir.toString(), "etc/keystore"); + assertNull(resolved, "Should be null as baseDir does not exist"); + } + private ByteArrayOutputStream captureLoggingBytes(ThrowableAction action) throws Exception { Logger slf4jLogger = LoggerFactory.getLogger(XmlConfiguration.class); From 927dc609832a8e7b4f4a184bb726d80455305898 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 2 Mar 2021 14:53:58 -0600 Subject: [PATCH 02/10] Issue #6021 - Fixing test case Signed-off-by: Joakim Erdfelt --- .../jetty/xml/XmlConfigurationTest.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java index 51b3d51cf5b2..463bf0059a1d 100644 --- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java @@ -1622,15 +1622,23 @@ public void testCallResolvePath(String configValue, String expectedPath) throws " " + ""); - configuration.setJettyStandardIdsAndProperties(null, Resource.newResource(war)); - configuration.getProperties().put("jetty.base", "/var/lib/jetty-base"); - if (configValue != null) - configuration.getProperties().put("jetty.sslContext.keyStorePath", configValue); + try + { + configuration.setJettyStandardIdsAndProperties(null, Resource.newResource(war)); + configuration.getProperties().put("jetty.base", "/var/lib/jetty-base"); + if (configValue != null) + configuration.getProperties().put("jetty.sslContext.keyStorePath", configValue); - TestConfiguration tc = new TestConfiguration(); - configuration.configure(tc); + TestConfiguration tc = new TestConfiguration(); + configuration.configure(tc); - assertThat(tc.getTestString(), is(expectedPath)); + assertThat(tc.getTestString(), is(expectedPath)); + } + finally + { + // cleanup after myself + configuration.getProperties().remove("jetty.base"); + } } @Test @@ -1658,7 +1666,7 @@ public void testResolvePathInvalidBase() FS.ensureDeleted(testPath); Path baseDir = testPath.resolve("bogus"); String resolved = XmlConfiguration.resolvePath(baseDir.toString(), "etc/keystore"); - assertNull(resolved, "Should be null as baseDir does not exist"); + assertEquals(baseDir.resolve("etc/keystore").toString(), resolved); } private ByteArrayOutputStream captureLoggingBytes(ThrowableAction action) throws Exception From 021451cba94ad2ab22f6d7758bc2a5e0e4a22b24 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 3 Mar 2021 06:15:30 -0600 Subject: [PATCH 03/10] Issue #6021 - Adding windows specific testcases Signed-off-by: Joakim Erdfelt --- .../jetty/xml/XmlConfigurationTest.java | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java index 463bf0059a1d..b1dd63973e78 100644 --- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java @@ -49,6 +49,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -1594,21 +1595,57 @@ public void testDeprecated() throws Exception public static Stream resolvePathCases() { - return Stream.of( + String resolvePathCasesJettyBase; + + ArrayList cases = new ArrayList<>(); + if (OS.WINDOWS.isCurrentOs()) + { + resolvePathCasesJettyBase = "C:\\web\\jetty-base"; + + // Not configured, default (in xml) is used. + cases.add(Arguments.of(resolvePathCasesJettyBase, null, "C:\\web\\jetty-base\\etc\\keystore.p12")); + // Configured using normal relative path + cases.add(Arguments.of(resolvePathCasesJettyBase, "alt/keystore", "C:\\web\\jetty-base\\alt\\keystore")); + // Configured using navigated path segments + cases.add(Arguments.of(resolvePathCasesJettyBase, "../corp/etc/keystore", "C:\\web\\corp\\etc\\keystore")); + // Configured using absolute path + cases.add(Arguments.of(resolvePathCasesJettyBase, "/included/keystore", "C:\\included\\keystore")); + cases.add(Arguments.of(resolvePathCasesJettyBase, "\\included\\keystore", "C:\\included\\keystore")); + cases.add(Arguments.of(resolvePathCasesJettyBase, "D:\\main\\config\\keystore", "D:\\main\\config\\keystore")); + + resolvePathCasesJettyBase = "\\\\machine\\share\\apps\\jetty-base"; + // Not configured, default (in xml) is used. - Arguments.of(null, "/var/lib/jetty-base/etc/keystore.p12"), + cases.add(Arguments.of(resolvePathCasesJettyBase, null, "\\\\machine\\share\\apps\\jetty-base\\etc\\keystore.p12")); // Configured using normal relative path - Arguments.of("alt/keystore", "/var/lib/jetty-base/alt/keystore"), + cases.add(Arguments.of(resolvePathCasesJettyBase, "alt/keystore", "\\\\machine\\share\\apps\\jetty-base\\alt\\keystore")); // Configured using navigated path segments - Arguments.of("../corp/etc/keystore", "/var/lib/corp/etc/keystore"), + cases.add(Arguments.of(resolvePathCasesJettyBase, "../corp/etc/keystore", "\\\\machine\\share\\apps\\corp\\etc\\keystore")); // Configured using absolute path - Arguments.of("/opt/jetty/etc/keystore", "/opt/jetty/etc/keystore") - ); + cases.add(Arguments.of(resolvePathCasesJettyBase, "/included/keystore", "\\\\machine\\share\\included\\keystore")); + cases.add(Arguments.of(resolvePathCasesJettyBase, "\\included\\keystore", "\\\\machine\\share\\included\\keystore")); + cases.add(Arguments.of(resolvePathCasesJettyBase, "D:\\main\\config\\keystore", "D:\\main\\config\\keystore")); + } + else + { + resolvePathCasesJettyBase = "/var/lib/jetty-base"; + + // Not configured, default (in xml) is used. + cases.add(Arguments.of(resolvePathCasesJettyBase, null, "/var/lib/jetty-base/etc/keystore.p12")); + // Configured using normal relative path + cases.add(Arguments.of(resolvePathCasesJettyBase, "alt/keystore", "/var/lib/jetty-base/alt/keystore")); + // Configured using navigated path segments + cases.add(Arguments.of(resolvePathCasesJettyBase, "../corp/etc/keystore", "/var/lib/corp/etc/keystore")); + // Configured using absolute path + cases.add(Arguments.of(resolvePathCasesJettyBase, "/opt/jetty/etc/keystore", "/opt/jetty/etc/keystore")); + } + + return cases.stream(); } @ParameterizedTest @MethodSource("resolvePathCases") - public void testCallResolvePath(String configValue, String expectedPath) throws Exception + public void testCallResolvePath(String jettyBasePath, String configValue, String expectedPath) throws Exception { Path war = MavenTestingUtils.getTargetPath("no.war"); XmlConfiguration configuration = @@ -1625,7 +1662,7 @@ public void testCallResolvePath(String configValue, String expectedPath) throws try { configuration.setJettyStandardIdsAndProperties(null, Resource.newResource(war)); - configuration.getProperties().put("jetty.base", "/var/lib/jetty-base"); + configuration.getProperties().put("jetty.base", jettyBasePath); if (configValue != null) configuration.getProperties().put("jetty.sslContext.keyStorePath", configValue); From 87f75308348a9067d0061e6af12f4b923ae419bd Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 3 Mar 2021 04:23:33 -0800 Subject: [PATCH 04/10] Issue #6021 - Addressing expectations on Windows Signed-off-by: Joakim Erdfelt --- .../java/org/eclipse/jetty/xml/XmlConfigurationTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java index b1dd63973e78..efaca5d7cae2 100644 --- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java @@ -15,7 +15,6 @@ import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; @@ -46,7 +45,6 @@ import org.eclipse.jetty.util.resource.Resource; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.OS; @@ -1684,7 +1682,7 @@ public void testResolvePathRelative() Path testPath = MavenTestingUtils.getTargetTestingPath("testResolvePathRelative"); FS.ensureDirExists(testPath); String resolved = XmlConfiguration.resolvePath(testPath.toString(), "etc/keystore"); - assertEquals(testPath.toString() + File.separator + "etc/keystore", resolved); + assertEquals(testPath.resolve("etc/keystore").toString(), resolved); } @Test @@ -1693,7 +1691,7 @@ public void testResolvePathAbsolute() Path testPath = MavenTestingUtils.getTargetTestingPath("testResolvePathRelative"); FS.ensureDirExists(testPath); String resolved = XmlConfiguration.resolvePath(testPath.toString(), "/tmp/etc/keystore"); - assertEquals("/tmp/etc/keystore", resolved); + assertEquals(testPath.resolve("/tmp/etc/keystore").toString(), resolved); } @Test From 3a457a15d161b34a62d05a3c1bb1196ceb0c78cf Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 3 Mar 2021 07:22:24 -0600 Subject: [PATCH 05/10] Issue #6021 - More windows specific test cases Signed-off-by: Joakim Erdfelt --- .../eclipse/jetty/xml/XmlConfigurationTest.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java index efaca5d7cae2..81d00277499c 100644 --- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java @@ -1606,10 +1606,15 @@ public static Stream resolvePathCases() cases.add(Arguments.of(resolvePathCasesJettyBase, "alt/keystore", "C:\\web\\jetty-base\\alt\\keystore")); // Configured using navigated path segments cases.add(Arguments.of(resolvePathCasesJettyBase, "../corp/etc/keystore", "C:\\web\\corp\\etc\\keystore")); - // Configured using absolute path + // Configured using relative to drive-root path cases.add(Arguments.of(resolvePathCasesJettyBase, "/included/keystore", "C:\\included\\keystore")); cases.add(Arguments.of(resolvePathCasesJettyBase, "\\included\\keystore", "C:\\included\\keystore")); + // Configured using absolute path cases.add(Arguments.of(resolvePathCasesJettyBase, "D:\\main\\config\\keystore", "D:\\main\\config\\keystore")); + cases.add(Arguments.of(resolvePathCasesJettyBase, "E:other\\keystore", "E:other\\keystore")); + cases.add(Arguments.of(resolvePathCasesJettyBase, "F:\\\\other\\keystore", "F:\\other\\keystore")); + cases.add(Arguments.of(resolvePathCasesJettyBase, "G:///another/keystore", "G:\\another\\keystore")); + cases.add(Arguments.of(resolvePathCasesJettyBase, "H:///prod/app/keystore", "H:\\prod\\app\\keystore")); resolvePathCasesJettyBase = "\\\\machine\\share\\apps\\jetty-base"; @@ -1619,10 +1624,15 @@ public static Stream resolvePathCases() cases.add(Arguments.of(resolvePathCasesJettyBase, "alt/keystore", "\\\\machine\\share\\apps\\jetty-base\\alt\\keystore")); // Configured using navigated path segments cases.add(Arguments.of(resolvePathCasesJettyBase, "../corp/etc/keystore", "\\\\machine\\share\\apps\\corp\\etc\\keystore")); - // Configured using absolute path + // Configured using relative to drive-root path cases.add(Arguments.of(resolvePathCasesJettyBase, "/included/keystore", "\\\\machine\\share\\included\\keystore")); cases.add(Arguments.of(resolvePathCasesJettyBase, "\\included\\keystore", "\\\\machine\\share\\included\\keystore")); + // Configured using absolute path cases.add(Arguments.of(resolvePathCasesJettyBase, "D:\\main\\config\\keystore", "D:\\main\\config\\keystore")); + cases.add(Arguments.of(resolvePathCasesJettyBase, "E:other\\keystore", "E:other\\keystore")); + cases.add(Arguments.of(resolvePathCasesJettyBase, "F:\\\\other\\keystore", "F:\\other\\keystore")); + cases.add(Arguments.of(resolvePathCasesJettyBase, "G:///another/keystore", "G:\\another\\keystore")); + cases.add(Arguments.of(resolvePathCasesJettyBase, "H:///prod/app/keystore", "H:\\prod\\app\\keystore")); } else { From e34c1cc312d1e4a94d281f64882615f677235276 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 3 Mar 2021 08:28:04 -0600 Subject: [PATCH 06/10] Issue #6021 - Tabs vs Spaces Signed-off-by: Joakim Erdfelt --- .../infinispan/infinispan-remote-query.xml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/jetty-infinispan/infinispan-remote-query/src/main/config-template/etc/sessions/infinispan/infinispan-remote-query.xml b/jetty-infinispan/infinispan-remote-query/src/main/config-template/etc/sessions/infinispan/infinispan-remote-query.xml index 389a18428745..9a3ca51f954a 100644 --- a/jetty-infinispan/infinispan-remote-query/src/main/config-template/etc/sessions/infinispan/infinispan-remote-query.xml +++ b/jetty-infinispan/infinispan-remote-query/src/main/config-template/etc/sessions/infinispan/infinispan-remote-query.xml @@ -20,11 +20,11 @@ - + - + /resources/hotrod-client.properties @@ -34,7 +34,7 @@ - + @@ -49,7 +49,7 @@ - + @@ -57,7 +57,7 @@ - + @@ -84,7 +84,7 @@ - + @@ -93,10 +93,10 @@ - + - - - + + + From 9de2c2096b5ae04810d26beef9f656f8fd024ddd Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 3 Mar 2021 08:29:18 -0600 Subject: [PATCH 07/10] Issue #6021 - Simpler resolvePath Signed-off-by: Joakim Erdfelt --- .../java/org/eclipse/jetty/xml/XmlConfiguration.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index 7e2de36562c0..c192ea807568 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -344,15 +344,7 @@ public static String resolvePath(String baseDir, String destPath) if (StringUtil.isEmpty(baseDir) || StringUtil.isEmpty(destPath)) return null; - Path base = Paths.get(baseDir); - - if (!Files.exists(base)) - { - // Add warning to debug output - LOG.debug("Configured baseDir={} does not exist", baseDir); - } - - return base.resolve(destPath).normalize().toString(); + return Paths.get(baseDir).resolve(destPath).normalize().toString(); } private static class JettyXmlConfiguration implements ConfigurationProcessor From 48d296ac0c55b62385a7806407d23d367d6309d4 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 3 Mar 2021 08:38:15 -0600 Subject: [PATCH 08/10] Issue #6021 - Addressing naming Signed-off-by: Joakim Erdfelt --- .../org/eclipse/jetty/xml/XmlConfiguration.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index c192ea807568..ae876e62d038 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -28,7 +28,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.UnknownHostException; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.security.AccessController; @@ -333,18 +332,19 @@ public void initializeDefaults(Object object) } /** - * Utility method to resolve a provided path against a base directory. + * Utility method to resolve a provided path against a directory. * - * @param baseDir the base directory - * @param destPath the destination path (can be relative or absolute, syntax depends on OS + FileSystem in use) + * @param dir the directory (should be a directory reference, does not have to exist) + * @param destPath the destination path (can be relative or absolute, syntax depends on OS + FileSystem in use, + * and does not need to exist) * @return String to resolved and normalized path, or null if baseDir or destPath is empty. */ - public static String resolvePath(String baseDir, String destPath) + public static String resolvePath(String dir, String destPath) { - if (StringUtil.isEmpty(baseDir) || StringUtil.isEmpty(destPath)) + if (StringUtil.isEmpty(dir) || StringUtil.isEmpty(destPath)) return null; - return Paths.get(baseDir).resolve(destPath).normalize().toString(); + return Paths.get(dir).resolve(destPath).normalize().toString(); } private static class JettyXmlConfiguration implements ConfigurationProcessor From 40e9cd08e12e87d11c58325adb5d1cda6d8680bf Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 3 Mar 2021 08:39:15 -0600 Subject: [PATCH 09/10] Issue #6021 - Addressing naming Signed-off-by: Joakim Erdfelt --- .../src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index ae876e62d038..17f5ae4d2617 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -337,7 +337,7 @@ public void initializeDefaults(Object object) * @param dir the directory (should be a directory reference, does not have to exist) * @param destPath the destination path (can be relative or absolute, syntax depends on OS + FileSystem in use, * and does not need to exist) - * @return String to resolved and normalized path, or null if baseDir or destPath is empty. + * @return String to resolved and normalized path, or null if dir or destPath is empty. */ public static String resolvePath(String dir, String destPath) { From 6d2ea3d5da206f41722630055d7ff1210c7001ba Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 3 Mar 2021 09:41:41 -0600 Subject: [PATCH 10/10] Issue #6021 - Addressing defaults Signed-off-by: Joakim Erdfelt --- .../modules/global-webapp-common.d/global-webapp-common.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetty-deploy/src/main/config/modules/global-webapp-common.d/global-webapp-common.xml b/jetty-deploy/src/main/config/modules/global-webapp-common.d/global-webapp-common.xml index 93959f7423b0..7f28fd55ca50 100644 --- a/jetty-deploy/src/main/config/modules/global-webapp-common.d/global-webapp-common.xml +++ b/jetty-deploy/src/main/config/modules/global-webapp-common.d/global-webapp-common.xml @@ -9,7 +9,7 @@ - /etc/webapp-common.xml +