diff --git a/jetty-deploy/src/main/config/etc/jetty-deploy.xml b/jetty-deploy/src/main/config/etc/jetty-deploy.xml index d244576c146..45d71dde039 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 41f3d202a63..7f28fd55ca5 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 - - + + + + diff --git a/jetty-home/src/main/resources/modules/hawtio/hawtio.xml b/jetty-home/src/main/resources/modules/hawtio/hawtio.xml index 922bcac7f46..8b66e036292 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 14e2e6ea1e4..e4356d4833f 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 d8f511fbca1..5c46f501a55 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 bb0b18061d8..7a434e8bb48 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 a0175b02b7f..ee0b60b7ab9 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 6faf65608f8..9a3ca51f954 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,13 +20,13 @@ - + - - /resources/hotrod-client.properties - + + /resources/hotrod-client.properties + @@ -34,7 +34,7 @@ - + @@ -49,7 +49,7 @@ - + @@ -57,7 +57,7 @@ - + @@ -84,7 +84,7 @@ - + @@ -93,10 +93,10 @@ - + - - - + + + 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 64d34bf32f9..479daf8f657 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 8debcd88e69..7fa442548a0 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 d973ec20eb0..881b23292a0 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 3781bc57f81..e7c39859657 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 6198f30e36e..dca5a651831 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 36dec030c94..98cf64733c3 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 178ae88fa36..b25525dec5c 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 3e87e5c0555..58a201e96ba 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 0c8c739c90b..8e4fbbc87bf 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 b00f608546a..d868e2b4a9c 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 abstract class SslContextFactory extends AbstractLifeCycle implements Dum */ 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 7872e931953..17f5ae4d261 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 @@ -331,6 +331,22 @@ public class XmlConfiguration { } + /** + * Utility method to resolve a provided path against a directory. + * + * @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 dir or destPath is empty. + */ + public static String resolvePath(String dir, String destPath) + { + if (StringUtil.isEmpty(dir) || StringUtil.isEmpty(destPath)) + return null; + + return Paths.get(dir).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 4a977c6a78b..81d00277499 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 @@ -31,10 +31,12 @@ import java.util.Map; 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; @@ -43,11 +45,12 @@ import org.eclipse.jetty.util.resource.PathResource; 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; 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 +1591,129 @@ public class XmlConfigurationTest assertEquals(6, warnings.size()); } + public static Stream resolvePathCases() + { + 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 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"; + + // Not configured, default (in xml) is used. + cases.add(Arguments.of(resolvePathCasesJettyBase, null, "\\\\machine\\share\\apps\\jetty-base\\etc\\keystore.p12")); + // Configured using normal relative path + 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 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 + { + 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 jettyBasePath, String configValue, String expectedPath) throws Exception + { + Path war = MavenTestingUtils.getTargetPath("no.war"); + XmlConfiguration configuration = + asXmlConfiguration( + "" + + " " + + " " + + " " + + " " + + " " + + " " + + ""); + + try + { + configuration.setJettyStandardIdsAndProperties(null, Resource.newResource(war)); + configuration.getProperties().put("jetty.base", jettyBasePath); + if (configValue != null) + configuration.getProperties().put("jetty.sslContext.keyStorePath", configValue); + + TestConfiguration tc = new TestConfiguration(); + configuration.configure(tc); + + assertThat(tc.getTestString(), is(expectedPath)); + } + finally + { + // cleanup after myself + configuration.getProperties().remove("jetty.base"); + } + } + + @Test + public void testResolvePathRelative() + { + Path testPath = MavenTestingUtils.getTargetTestingPath("testResolvePathRelative"); + FS.ensureDirExists(testPath); + String resolved = XmlConfiguration.resolvePath(testPath.toString(), "etc/keystore"); + assertEquals(testPath.resolve("etc/keystore").toString(), resolved); + } + + @Test + public void testResolvePathAbsolute() + { + Path testPath = MavenTestingUtils.getTargetTestingPath("testResolvePathRelative"); + FS.ensureDirExists(testPath); + String resolved = XmlConfiguration.resolvePath(testPath.toString(), "/tmp/etc/keystore"); + assertEquals(testPath.resolve("/tmp/etc/keystore").toString(), 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"); + assertEquals(baseDir.resolve("etc/keystore").toString(), resolved); + } + private ByteArrayOutputStream captureLoggingBytes(ThrowableAction action) throws Exception { Logger slf4jLogger = LoggerFactory.getLogger(XmlConfiguration.class);