From aff96fe739951bd2a2d00f88477b01e9af7d0620 Mon Sep 17 00:00:00 2001 From: gregw Date: Thu, 4 Apr 2024 22:48:02 +0200 Subject: [PATCH] updates from review --- .../eclipse/jetty/ee/WebAppClassLoading.java | 23 +++++++++++ .../jetty/util/ClassVisibilityChecker.java | 40 ++++++++++++++++--- .../jetty/ee10/webapp/ClassMatcher.java | 5 +++ .../jetty/ee10/webapp/WebAppContext.java | 10 +++-- .../jetty/ee9/webapp/WebAppContext.java | 23 ++++++----- .../jetty/ee9/webapp/WebAppContextTest.java | 7 ++-- 6 files changed, 86 insertions(+), 22 deletions(-) diff --git a/jetty-core/jetty-ee/src/main/java/org/eclipse/jetty/ee/WebAppClassLoading.java b/jetty-core/jetty-ee/src/main/java/org/eclipse/jetty/ee/WebAppClassLoading.java index 81437a26a29..eaf13e52a64 100644 --- a/jetty-core/jetty-ee/src/main/java/org/eclipse/jetty/ee/WebAppClassLoading.java +++ b/jetty-core/jetty-ee/src/main/java/org/eclipse/jetty/ee/WebAppClassLoading.java @@ -102,6 +102,17 @@ public class WebAppClassLoading DEFAULT_PROTECTED_CLASSES.add(patterns); } + /** + * Add a protected (system) Class pattern to use for all WebAppContexts of a given {@link Server}. + * @param attributes The {@link Attributes} instance to add classes to + * @param patterns the patterns to use + */ + public static void addProtectedClasses(Attributes attributes, String... patterns) + { + if (patterns != null && patterns.length > 0) + getClassMatcher(attributes, PROTECTED_CLASSES_ATTRIBUTE, null).add(patterns); + } + /** * Add a protected (system) Class pattern to use for all WebAppContexts of a given {@link Server}. * @param server The {@link Server} instance to add classes to @@ -154,6 +165,18 @@ public class WebAppClassLoading DEFAULT_HIDDEN_CLASSES.add(patterns); } + /** + * Add a hidden (server) Class pattern to use for all WebAppContexts of a given {@link Server}. + * @param attributes The {@link Attributes} instance to add classes to + * @param patterns the patterns to use + */ + @Deprecated (forRemoval = true) + public static void addHiddenClasses(Attributes attributes, String... patterns) + { + if (patterns != null && patterns.length > 0) + getClassMatcher(attributes, HIDDEN_CLASSES_ATTRIBUTE, null).add(patterns); + } + /** * Add a hidden (server) Class pattern to use for all WebAppContexts of a given {@link Server}. * @param server The {@link Server} instance to add classes to diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ClassVisibilityChecker.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ClassVisibilityChecker.java index a2e170c41a0..12bfaec2322 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ClassVisibilityChecker.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ClassVisibilityChecker.java @@ -14,16 +14,13 @@ package org.eclipse.jetty.util; /** - * ClassVisibilityChecker - * * Interface to be implemented by classes capable of checking class visibility * for a context. */ public interface ClassVisibilityChecker { - /** - * Is the class a System Class. + * Is the class a Protected (System) Class. * A System class is a class that is visible to a webapplication, * but that cannot be overridden by the contents of WEB-INF/lib or * WEB-INF/classes @@ -34,7 +31,7 @@ public interface ClassVisibilityChecker boolean isProtectedClass(Class clazz); /** - * Is the class a Server Class. + * Is the class a Hidden (Server) Class. * A Server class is a class that is part of the implementation of * the server and is NIT visible to a webapplication. The web * application may provide it's own implementation of the class, @@ -44,4 +41,37 @@ public interface ClassVisibilityChecker * @return True if the class is a server class. */ boolean isHiddenClass(Class clazz); + + /** + * Is the class a System Class. + * A System class is a class that is visible to a webapplication, + * but that cannot be overridden by the contents of WEB-INF/lib or + * WEB-INF/classes + * + * @param clazz The fully qualified name of the class. + * @return True if the class is a system class. + * @deprecated use {@link #isProtectedClass(Class)} + */ + @Deprecated (forRemoval = true, since = "12.0.9") + default boolean isSystemClass(Class clazz) + { + return isProtectedClass(clazz); + } + + /** + * Is the class a Server Class. + * A Server class is a class that is part of the implementation of + * the server and is NIT visible to a webapplication. The web + * application may provide it's own implementation of the class, + * to be loaded from WEB-INF/lib or WEB-INF/classes + * + * @param clazz The fully qualified name of the class. + * @return True if the class is a server class. + * @deprecated use {@link #isHiddenClass(Class)} + */ + @Deprecated (forRemoval = true, since = "12.0.9") + default boolean isServerClass(Class clazz) + { + return isHiddenClass(clazz); + } } diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java index ed921b5c9df..3e9fa15cb81 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java @@ -25,6 +25,11 @@ public class ClassMatcher extends org.eclipse.jetty.util.ClassMatcher super(); } + public ClassMatcher(ClassMatcher patterns) + { + super(patterns); + } + public ClassMatcher(org.eclipse.jetty.util.ClassMatcher patterns) { super(patterns); diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebAppContext.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebAppContext.java index 3dda93ba881..57614176c4a 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebAppContext.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebAppContext.java @@ -90,14 +90,16 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL /** * @deprecated use {@link WebAppClassLoading#DEFAULT_PROTECTED_CLASSES} */ - @Deprecated - public static final ClassMatcher __dftSystemClasses = WebAppClassLoading.DEFAULT_PROTECTED_CLASSES; + @Deprecated (forRemoval = true, since = "12.0.9") + public static final org.eclipse.jetty.ee10.webapp.ClassMatcher __dftSystemClasses = + new org.eclipse.jetty.ee10.webapp.ClassMatcher(WebAppClassLoading.DEFAULT_PROTECTED_CLASSES); /** * @deprecated use {@link WebAppClassLoading#DEFAULT_HIDDEN_CLASSES} */ - @Deprecated - public static final ClassMatcher __dftServerClasses = WebAppClassLoading.DEFAULT_HIDDEN_CLASSES; + @Deprecated (forRemoval = true, since = "12.0.9") + public static final org.eclipse.jetty.ee10.webapp.ClassMatcher __dftServerClasses = + new org.eclipse.jetty.ee10.webapp.ClassMatcher(WebAppClassLoading.DEFAULT_HIDDEN_CLASSES); private final ClassMatcher _protectedClasses = new ClassMatcher(WebAppClassLoading.getProtectedClasses(ServletContextHandler.ENVIRONMENT)); private final ClassMatcher _hiddenClasses = new ClassMatcher(WebAppClassLoading.getHiddenClasses(ServletContextHandler.ENVIRONMENT)); diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebAppContext.java b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebAppContext.java index d0054a26f1e..3a00f13369c 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebAppContext.java +++ b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebAppContext.java @@ -54,6 +54,7 @@ import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Deployable; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.Attributes; import org.eclipse.jetty.util.ClassMatcher; import org.eclipse.jetty.util.ExceptionUtil; import org.eclipse.jetty.util.IO; @@ -96,14 +97,16 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL /** * @deprecated use {@link WebAppClassLoading#DEFAULT_PROTECTED_CLASSES} */ - @Deprecated - public static final ClassMatcher __dftSystemClasses = WebAppClassLoading.DEFAULT_PROTECTED_CLASSES; + @Deprecated(forRemoval = true, since = "12.0.9") + public static final org.eclipse.jetty.ee9.webapp.ClassMatcher __dftSystemClasses = + new org.eclipse.jetty.ee9.webapp.ClassMatcher(WebAppClassLoading.DEFAULT_PROTECTED_CLASSES); /** * @deprecated use {@link WebAppClassLoading#DEFAULT_HIDDEN_CLASSES} */ - @Deprecated - public static final ClassMatcher __dftServerClasses = WebAppClassLoading.DEFAULT_HIDDEN_CLASSES; + @Deprecated(forRemoval = true, since = "12.0.9") + public static final org.eclipse.jetty.ee9.webapp.ClassMatcher __dftServerClasses = + new org.eclipse.jetty.ee9.webapp.ClassMatcher(WebAppClassLoading.DEFAULT_HIDDEN_CLASSES); private final ClassMatcher _systemClasses = new ClassMatcher(WebAppClassLoading.getProtectedClasses(ServletContextHandler.ENVIRONMENT)); private final ClassMatcher _serverClasses = new ClassMatcher(WebAppClassLoading.getHiddenClasses(ServletContextHandler.ENVIRONMENT)); @@ -1467,29 +1470,29 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL /** * Add a Server Class pattern to use for all ee9 WebAppContexts. - * @param server The {@link Server} instance to add classes to + * @param attributes The {@link Server} instance to add classes to * @param patterns the patterns to use * @see #getServerClassMatcher() * @see #getServerClasses() * @deprecated use {@link WebAppClassLoading#addProtectedClasses(Server, String...)} */ @Deprecated(since = "12.0.8", forRemoval = true) - public static void addServerClasses(Server server, String... patterns) + public static void addServerClasses(Attributes attributes, String... patterns) { - WebAppClassLoading.addHiddenClasses(server, patterns); + WebAppClassLoading.addHiddenClasses(attributes, patterns); } /** * Add a System Class pattern to use for all ee9 WebAppContexts. - * @param server The {@link Server} instance to add classes to + * @param attributes The {@link Server} instance to add classes to * @param patterns the patterns to use * @see #getSystemClassMatcher() * @see #getSystemClasses() * @deprecated use {@link WebAppClassLoading#addHiddenClasses(Server, String...)} */ @Deprecated(since = "12.0.8", forRemoval = true) - public static void addSystemClasses(Server server, String... patterns) + public static void addSystemClasses(Attributes attributes, String... patterns) { - WebAppClassLoading.addProtectedClasses(server, patterns); + WebAppClassLoading.addProtectedClasses(attributes, patterns); } } diff --git a/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppContextTest.java b/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppContextTest.java index 43bf4053e83..9e9ee0bd01b 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppContextTest.java +++ b/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppContextTest.java @@ -34,6 +34,7 @@ import jakarta.servlet.GenericServlet; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; +import org.eclipse.jetty.ee.WebAppClassLoading; import org.eclipse.jetty.ee9.nested.ContextHandler; import org.eclipse.jetty.ee9.servlet.ErrorPageErrorHandler; import org.eclipse.jetty.ee9.servlet.ServletContextHandler; @@ -117,7 +118,7 @@ public class WebAppContextTest * @param name the name of the war * @return the Path of the generated war * - * @throws Exception + * @throws Exception if the war cannot be created */ private Path createWar(Path tempDir, String name) throws Exception { @@ -873,7 +874,7 @@ public class WebAppContextTest assertThat("Should have environment specific test pattern", serverClasses, hasItem(testPattern)); assertThat("Should have pattern from defaults", serverClasses, hasItem("org.eclipse.jetty.")); assertThat("Should have pattern from JaasConfiguration", serverClasses, hasItem("-org.eclipse.jetty.security.jaas.")); - for (String defaultServerClass: WebAppContext.__dftServerClasses) + for (String defaultServerClass: WebAppClassLoading.DEFAULT_HIDDEN_CLASSES) assertThat("Should have default patterns", serverClasses, hasItem(defaultServerClass)); } @@ -902,7 +903,7 @@ public class WebAppContextTest assertThat("Should have pattern from defaults", systemClasses, hasItem("javax.")); assertThat("Should have pattern from defaults", systemClasses, hasItem("jakarta.")); assertThat("Should have pattern from JaasConfiguration", systemClasses, hasItem("org.eclipse.jetty.security.jaas.")); - for (String defaultSystemClass : WebAppContext.__dftSystemClasses) + for (String defaultSystemClass : WebAppClassLoading.DEFAULT_PROTECTED_CLASSES) { assertThat("Should have default patterns", systemClasses, hasItem(defaultSystemClass)); }