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);