From 539bd0881ceb45d06a30a00014b82e8a0a7c2bea Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Thu, 5 Dec 2024 12:16:13 -0600 Subject: [PATCH] ARTEMIS-5208 bump Jetty from 10.0.24 to 12.0.15 --- artemis-pom/pom.xml | 8 ++++ artemis-web/pom.xml | 20 +++++++--- .../component/AuthenticationFilter.java | 12 +++--- .../artemis/component/DefaultHandler.java | 20 ++++------ .../artemis/component/JolokiaFilter.java | 10 ++--- .../artemis/component/WebServerComponent.java | 39 +++++++++---------- .../WebServerComponentTestAccessor.java | 2 +- .../activemq/cli/test/TestCustomizer.java | 5 ++- .../cli/test/WebServerComponentTest.java | 14 +++---- pom.xml | 2 +- .../isolated/web/WebServerComponentTest.java | 2 +- 11 files changed, 72 insertions(+), 62 deletions(-) diff --git a/artemis-pom/pom.xml b/artemis-pom/pom.xml index 4b0c827b72..77c7a14612 100644 --- a/artemis-pom/pom.xml +++ b/artemis-pom/pom.xml @@ -525,6 +525,14 @@ import + + org.eclipse.jetty.ee8 + jetty-ee8-bom + ${jetty.version} + pom + import + + org.eclipse.jetty.toolchain jetty-servlet-api diff --git a/artemis-web/pom.xml b/artemis-web/pom.xml index 3865727291..f86b8f63f8 100644 --- a/artemis-web/pom.xml +++ b/artemis-web/pom.xml @@ -67,21 +67,29 @@ jetty-server - org.eclipse.jetty - jetty-servlet + org.eclipse.jetty.ee8 + jetty-ee8-servlet - org.eclipse.jetty - jetty-webapp + org.eclipse.jetty.ee8 + jetty-ee8-webapp - org.eclipse.jetty - jetty-security + org.eclipse.jetty.ee8 + jetty-ee8-nested + + + org.eclipse.jetty.ee8 + jetty-ee8-security org.eclipse.jetty jetty-util + + org.eclipse.jetty + jetty-http + org.apache.activemq artemis-server diff --git a/artemis-web/src/main/java/org/apache/activemq/artemis/component/AuthenticationFilter.java b/artemis-web/src/main/java/org/apache/activemq/artemis/component/AuthenticationFilter.java index 37aa0d1199..25b46dc24e 100644 --- a/artemis-web/src/main/java/org/apache/activemq/artemis/component/AuthenticationFilter.java +++ b/artemis-web/src/main/java/org/apache/activemq/artemis/component/AuthenticationFilter.java @@ -16,10 +16,6 @@ */ package org.apache.activemq.artemis.component; -import org.apache.activemq.artemis.logs.AuditLogger; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Response; - import javax.security.auth.Subject; import javax.servlet.Filter; import javax.servlet.FilterChain; @@ -27,9 +23,13 @@ import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -import javax.servlet.http.HttpSession; import java.io.IOException; +import org.apache.activemq.artemis.logs.AuditLogger; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Response; +import org.eclipse.jetty.server.Session; + /* * This filter intercepts the login and audits its results * */ @@ -47,7 +47,7 @@ public class AuthenticationFilter implements Filter { //Successful responses (200 – 299) //the user has been authenticated if the session isn't empty //the hawtio logout servlet cleans the session and redirects to the login servlet - HttpSession session = ((Request) servletRequest).getSession(false); + Session session = ((Request) servletRequest).getSession(false); if (session != null) { AuditLogger.userSuccesfullyAuthenticatedInAudit((Subject) session.getAttribute("subject")); } diff --git a/artemis-web/src/main/java/org/apache/activemq/artemis/component/DefaultHandler.java b/artemis-web/src/main/java/org/apache/activemq/artemis/component/DefaultHandler.java index a53da3de76..52657c704c 100644 --- a/artemis-web/src/main/java/org/apache/activemq/artemis/component/DefaultHandler.java +++ b/artemis-web/src/main/java/org/apache/activemq/artemis/component/DefaultHandler.java @@ -16,12 +16,9 @@ */ package org.apache.activemq.artemis.component; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Response; +import org.eclipse.jetty.util.Callback; public class DefaultHandler extends org.eclipse.jetty.server.handler.DefaultHandler { private String rootRedirectLocation; @@ -35,14 +32,13 @@ public class DefaultHandler extends org.eclipse.jetty.server.handler.DefaultHand } @Override - public void handle(String target, - Request baseRequest, - HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - if (rootRedirectLocation != null && target.matches("^$|/")) { - response.sendRedirect(rootRedirectLocation); + public boolean handle(Request request, Response response, Callback callback) throws Exception { + if (rootRedirectLocation != null && request.getHttpURI().getPath().matches("^$|/")) { + Response.sendRedirect(request, response, callback, Response.toRedirectURI(request, rootRedirectLocation)); + callback.succeeded(); + return true; } else { - super.handle(target, baseRequest, request, response); + return super.handle(request, response, callback); } } } diff --git a/artemis-web/src/main/java/org/apache/activemq/artemis/component/JolokiaFilter.java b/artemis-web/src/main/java/org/apache/activemq/artemis/component/JolokiaFilter.java index 462709ab0c..c87e97f801 100644 --- a/artemis-web/src/main/java/org/apache/activemq/artemis/component/JolokiaFilter.java +++ b/artemis-web/src/main/java/org/apache/activemq/artemis/component/JolokiaFilter.java @@ -16,9 +16,6 @@ */ package org.apache.activemq.artemis.component; -import org.apache.activemq.artemis.logs.AuditLogger; -import org.eclipse.jetty.server.Request; - import javax.security.auth.Subject; import javax.servlet.Filter; import javax.servlet.FilterChain; @@ -26,9 +23,12 @@ import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -import javax.servlet.http.HttpSession; import java.io.IOException; +import org.apache.activemq.artemis.logs.AuditLogger; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Session; + /* * This intercepts all calls made via jolokia * */ @@ -54,7 +54,7 @@ public class JolokiaFilter implements Filter { * */ if (AuditLogger.isAnyLoggingEnabled()) { try { - HttpSession session = ((Request) servletRequest).getSession(); + Session session = ((Request) servletRequest).getSession(true); Subject subject = (Subject) session.getAttribute("subject"); AuditLogger.setCurrentCaller(subject); } catch (Throwable e) { diff --git a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java b/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java index 907dfcb4d0..90b59679d9 100644 --- a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java +++ b/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java @@ -32,6 +32,7 @@ import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; import java.util.EnumSet; import java.util.HashMap; import java.util.List; @@ -49,9 +50,12 @@ import org.apache.activemq.artemis.logs.AuditLogger; import org.apache.activemq.artemis.marker.WebServerComponentMarker; import org.apache.activemq.artemis.utils.ClassloadingUtil; import org.apache.activemq.artemis.utils.PemConfigUtil; -import org.eclipse.jetty.security.DefaultAuthenticatorFactory; +import org.eclipse.jetty.ee8.security.DefaultAuthenticatorFactory; +import org.eclipse.jetty.ee8.servlet.FilterHolder; +import org.eclipse.jetty.ee8.webapp.WebAppContext; import org.eclipse.jetty.server.ConnectionFactory; import org.eclipse.jetty.server.CustomRequestLog; +import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.RequestLog; @@ -61,14 +65,11 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.SslConnectionFactory; import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.server.handler.ResourceHandler; -import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler; -import org.eclipse.jetty.webapp.WebAppContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -77,7 +78,6 @@ import static org.apache.activemq.artemis.core.remoting.impl.ssl.SSLSupport.chec public class WebServerComponent implements ExternalComponent, WebServerComponentMarker { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - public static final String DIR_ALLOWED = "org.eclipse.jetty.servlet.Default.dirAllowed"; // this should match the value of in the console war's WEB-INF/web.xml public static final String WEB_CONSOLE_DISPLAY_NAME = System.getProperty("org.apache.activemq.artemis.webConsoleDisplayName", "hawtio"); @@ -91,7 +91,7 @@ public class WebServerComponent implements ExternalComponent, WebServerComponent public static final int DEFAULT_SCAN_PERIOD_VALUE = 5; private Server server; - private HandlerList handlers; + private Handler.Sequence handlers; private WebServerDTO webServerConfig; private final List consoleUrls = new ArrayList<>(); private final List jolokiaUrls = new ArrayList<>(); @@ -134,7 +134,7 @@ public class WebServerComponent implements ExternalComponent, WebServerComponent ActiveMQWebLogger.LOGGER.startingEmbeddedWebServer(); server = new Server(new QueuedThreadPool(webServerConfig.maxThreads, webServerConfig.minThreads, webServerConfig.idleThreadTimeout)); - handlers = new HandlerList(); + handlers = new Handler.Sequence(); HttpConfiguration httpConfiguration = new HttpConfiguration(); @@ -179,7 +179,6 @@ public class WebServerComponent implements ExternalComponent, WebServerComponent } WebAppContext webContext = createWebAppContext(app.url, app.war, dirToUse, virtualHosts[i]); handlers.addHandler(webContext); - webContext.setInitParameter(DIR_ALLOWED, "false"); webContext.getSessionHandler().getSessionCookieConfig().setComment("__SAME_SITE_STRICT__"); webContext.addEventListener(new ServletContextListener() { @Override @@ -202,31 +201,29 @@ public class WebServerComponent implements ExternalComponent, WebServerComponent server.setConnectors(connectors); ResourceHandler homeResourceHandler = new ResourceHandler(); - homeResourceHandler.setResourceBase(homeWarDir.toString()); - homeResourceHandler.setDirectoriesListed(false); - homeResourceHandler.setWelcomeFiles(new String[]{"index.html"}); + homeResourceHandler.setBaseResourceAsString(homeWarDir.toString()); + homeResourceHandler.setDirAllowed(false); + homeResourceHandler.setWelcomeFiles("index.html"); ContextHandler homeContext = new ContextHandler(); homeContext.setContextPath("/"); - homeContext.setResourceBase(homeWarDir.toString()); + homeContext.setBaseResourceAsString(homeWarDir.toString()); homeContext.setHandler(homeResourceHandler); - homeContext.setVirtualHosts(virtualHosts); - homeContext.setInitParameter(DIR_ALLOWED, "false"); + homeContext.setVirtualHosts(Arrays.asList(virtualHosts)); ResourceHandler instanceResourceHandler = new ResourceHandler(); - instanceResourceHandler.setResourceBase(instanceWarDir.toString()); - instanceResourceHandler.setDirectoriesListed(false); - instanceResourceHandler.setWelcomeFiles(new String[]{"index.html"}); + instanceResourceHandler.setBaseResourceAsString(instanceWarDir.toString()); + instanceResourceHandler.setDirAllowed(false); + instanceResourceHandler.setWelcomeFiles("index.html"); ContextHandler instanceContext = new ContextHandler(); instanceContext.setContextPath("/"); - instanceContext.setResourceBase(instanceWarDir.toString()); + instanceContext.setBaseResourceAsString(instanceWarDir.toString()); instanceContext.setHandler(instanceResourceHandler); - instanceContext.setVirtualHosts(virtualHosts); - homeContext.setInitParameter(DIR_ALLOWED, "false"); + instanceContext.setVirtualHosts(Arrays.asList(virtualHosts)); DefaultHandler defaultHandler = new DefaultHandler(); - defaultHandler.setServeIcon(false); + defaultHandler.setServeFavIcon(false); defaultHandler.setRootRedirectLocation(this.webServerConfig.rootRedirectLocation); if (this.webServerConfig.requestLog != null && diff --git a/artemis-web/src/test/java/org/apache/activemq/artemis/component/WebServerComponentTestAccessor.java b/artemis-web/src/test/java/org/apache/activemq/artemis/component/WebServerComponentTestAccessor.java index b13571b040..f0f1cd5060 100644 --- a/artemis-web/src/test/java/org/apache/activemq/artemis/component/WebServerComponentTestAccessor.java +++ b/artemis-web/src/test/java/org/apache/activemq/artemis/component/WebServerComponentTestAccessor.java @@ -18,7 +18,7 @@ package org.apache.activemq.artemis.component; import java.nio.file.Path; -import org.eclipse.jetty.webapp.WebAppContext; +import org.eclipse.jetty.ee8.webapp.WebAppContext; public class WebServerComponentTestAccessor { diff --git a/artemis-web/src/test/java/org/apache/activemq/cli/test/TestCustomizer.java b/artemis-web/src/test/java/org/apache/activemq/cli/test/TestCustomizer.java index d00380aa73..608f7984c5 100644 --- a/artemis-web/src/test/java/org/apache/activemq/cli/test/TestCustomizer.java +++ b/artemis-web/src/test/java/org/apache/activemq/cli/test/TestCustomizer.java @@ -16,7 +16,7 @@ */ package org.apache.activemq.cli.test; -import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.Request; @@ -27,7 +27,8 @@ public class TestCustomizer implements HttpConfiguration.Customizer { } @Override - public void customize(Connector connector, HttpConfiguration httpConfiguration, Request request) { + public Request customize(Request request, HttpFields.Mutable responseHeaders) { count++; + return request; } } diff --git a/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java b/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java index cec7bb443f..8f260a3a36 100644 --- a/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java +++ b/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java @@ -95,10 +95,10 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.DefaultRoutePlanner; import org.apache.http.protocol.HttpContext; import org.apache.http.ssl.SSLContextBuilder; +import org.eclipse.jetty.ee8.webapp.WebAppContext; +import org.eclipse.jetty.ee8.webapp.WebInfConfiguration; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.ThreadPool; -import org.eclipse.jetty.webapp.WebAppContext; -import org.eclipse.jetty.webapp.WebInfConfiguration; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -164,7 +164,7 @@ public class WebServerComponentTest extends ArtemisTestCase { } WebServerComponent webServerComponent = new WebServerComponent(); assertFalse(webServerComponent.isStarted()); - webServerComponent.configure(webServerDTO, "./src/test/resources/", "./src/test/resources/"); + webServerComponent.configure(webServerDTO, "src/test/resources/", "src/test/resources/"); testedComponents.add(webServerComponent); webServerComponent.start(); final int port = webServerComponent.getPort(); @@ -227,7 +227,7 @@ public class WebServerComponentTest extends ArtemisTestCase { webServerDTO.webContentEnabled = true; WebServerComponent webServerComponent = new WebServerComponent(); assertFalse(webServerComponent.isStarted()); - webServerComponent.configure(webServerDTO, "./src/test/resources/", "./src/test/resources/"); + webServerComponent.configure(webServerDTO, "src/test/resources/", "src/test/resources/"); webServerComponent.start(); // Make the connection attempt. verifyConnection(webServerComponent.getPort()); @@ -251,7 +251,7 @@ public class WebServerComponentTest extends ArtemisTestCase { webServerDTO.webContentEnabled = true; WebServerComponent webServerComponent = new WebServerComponent(); assertFalse(webServerComponent.isStarted()); - webServerComponent.configure(webServerDTO, "./src/test/resources/", "./src/test/resources/"); + webServerComponent.configure(webServerDTO, "src/test/resources/", "src/test/resources/"); webServerComponent.start(); // Make the connection attempt. verifyConnection(webServerComponent.getPort()); @@ -305,7 +305,7 @@ public class WebServerComponentTest extends ArtemisTestCase { WebServerComponent webServerComponent = new WebServerComponent(); assertFalse(webServerComponent.isStarted()); - webServerComponent.configure(webServerDTO, "./src/test/resources/", "./src/test/resources/"); + webServerComponent.configure(webServerDTO, "src/test/resources/", "src/test/resources/"); testedComponents.add(webServerComponent); webServerComponent.start(); @@ -660,7 +660,7 @@ public class WebServerComponentTest extends ArtemisTestCase { WebServerComponent webServerComponent = new WebServerComponent(); assertFalse(webServerComponent.isStarted()); - webServerComponent.configure(webServerDTO, "./src/test/resources/", "./src/test/resources/"); + webServerComponent.configure(webServerDTO, "src/test/resources/", "src/test/resources/"); testedComponents.add(webServerComponent); webServerComponent.start(); final int port = webServerComponent.getPort(); diff --git a/pom.xml b/pom.xml index f6dc21df28..82208296fb 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,7 @@ 33.3.1-jre 2.17.7 3.0.2 - 10.0.24 + 12.0.15 4.0.6 5.3.13.Final 2.31.0 diff --git a/tests/integration-tests-isolated/src/test/java/org/apache/activemq/artemis/tests/integration/isolated/web/WebServerComponentTest.java b/tests/integration-tests-isolated/src/test/java/org/apache/activemq/artemis/tests/integration/isolated/web/WebServerComponentTest.java index 9e6345df5c..6c69a45a49 100644 --- a/tests/integration-tests-isolated/src/test/java/org/apache/activemq/artemis/tests/integration/isolated/web/WebServerComponentTest.java +++ b/tests/integration-tests-isolated/src/test/java/org/apache/activemq/artemis/tests/integration/isolated/web/WebServerComponentTest.java @@ -102,7 +102,7 @@ public class WebServerComponentTest { webServerDTO.setRequestLog(requestLogDTO); WebServerComponent webServerComponent = new WebServerComponent(); assertFalse(webServerComponent.isStarted()); - webServerComponent.configure(webServerDTO, "./src/test/resources/", "./src/test/resources/"); + webServerComponent.configure(webServerDTO, "src/test/resources/", "src/test/resources/"); testedComponents.add(webServerComponent); webServerComponent.start();