From 088788e086eb37ffb3c8e25c388342732b57a52b Mon Sep 17 00:00:00 2001 From: gregw Date: Thu, 23 May 2024 11:37:05 +1000 Subject: [PATCH] remove more system/server classes from ee11 --- .../annotations/AnnotationConfiguration.java | 2 +- .../jetty/ee11/osgi/boot/EE11Activator.java | 10 ++--- .../ee11/plus/webapp/EnvConfiguration.java | 2 +- .../ee11/webapp/JettyWebXmlConfiguration.java | 2 +- .../jetty/ee11/webapp/WebAppClassLoader.java | 24 +++++----- .../jetty/ee11/webapp/WebAppContext.java | 44 ++++--------------- .../ee11/webapp/WebAppClassLoaderTest.java | 4 +- .../jetty/ee11/webapp/WebAppContextTest.java | 4 +- 8 files changed, 32 insertions(+), 60 deletions(-) diff --git a/jetty-ee11/jetty-ee11-annotations/src/main/java/org/eclipse/jetty/ee11/annotations/AnnotationConfiguration.java b/jetty-ee11/jetty-ee11-annotations/src/main/java/org/eclipse/jetty/ee11/annotations/AnnotationConfiguration.java index 2d18fa87518..5db25568522 100644 --- a/jetty-ee11/jetty-ee11-annotations/src/main/java/org/eclipse/jetty/ee11/annotations/AnnotationConfiguration.java +++ b/jetty-ee11/jetty-ee11-annotations/src/main/java/org/eclipse/jetty/ee11/annotations/AnnotationConfiguration.java @@ -351,7 +351,7 @@ public class AnnotationConfiguration extends AbstractConfiguration protected Set> resolveStartupClasses() throws Exception { final Set> classes = new HashSet<>(); - WebAppClassLoader.runWithServerClassAccess(() -> + WebAppClassLoader.runWithHiddenClassAccess(() -> { for (String name:_startupClassNames) { diff --git a/jetty-ee11/jetty-ee11-osgi/jetty-ee11-osgi-boot/src/main/java/org/eclipse/jetty/ee11/osgi/boot/EE11Activator.java b/jetty-ee11/jetty-ee11-osgi/jetty-ee11-osgi-boot/src/main/java/org/eclipse/jetty/ee11/osgi/boot/EE11Activator.java index 93bf311400f..2782247b908 100644 --- a/jetty-ee11/jetty-ee11-osgi/jetty-ee11-osgi-boot/src/main/java/org/eclipse/jetty/ee11/osgi/boot/EE11Activator.java +++ b/jetty-ee11/jetty-ee11-osgi/jetty-ee11-osgi-boot/src/main/java/org/eclipse/jetty/ee11/osgi/boot/EE11Activator.java @@ -293,10 +293,10 @@ public class EE11Activator implements BundleActivator try { Thread.currentThread().setContextClassLoader(contextHandler.getClassLoader()); - WebAppClassLoader.runWithServerClassAccess(() -> + WebAppClassLoader.runWithHiddenClassAccess(() -> { XmlConfiguration xmlConfiguration = new XmlConfiguration(ResourceFactory.of(contextHandler).newResource(contextXmlURI)); - WebAppClassLoader.runWithServerClassAccess(() -> + WebAppClassLoader.runWithHiddenClassAccess(() -> { Map properties = new HashMap<>(); xmlConfiguration.getIdMap().put("Server", osgiApp.getDeploymentManager().getServer()); @@ -382,7 +382,7 @@ public class EE11Activator implements BundleActivator try { Thread.currentThread().setContextClassLoader(environmentLoader); - WebAppClassLoader.runWithServerClassAccess(() -> + WebAppClassLoader.runWithHiddenClassAccess(() -> { Configurations.getKnown(); return null; @@ -468,10 +468,10 @@ public class EE11Activator implements BundleActivator try { Thread.currentThread().setContextClassLoader(webApp.getClassLoader()); - WebAppClassLoader.runWithServerClassAccess(() -> + WebAppClassLoader.runWithHiddenClassAccess(() -> { XmlConfiguration xmlConfiguration = new XmlConfiguration(ResourceFactory.of(webApp).newResource(contextXmlUri)); - WebAppClassLoader.runWithServerClassAccess(() -> + WebAppClassLoader.runWithHiddenClassAccess(() -> { Map properties = new HashMap<>(); xmlConfiguration.getIdMap().put("Server", osgiApp.getDeploymentManager().getServer()); diff --git a/jetty-ee11/jetty-ee11-plus/src/main/java/org/eclipse/jetty/ee11/plus/webapp/EnvConfiguration.java b/jetty-ee11/jetty-ee11-plus/src/main/java/org/eclipse/jetty/ee11/plus/webapp/EnvConfiguration.java index 5119d801b28..684fa5e0983 100644 --- a/jetty-ee11/jetty-ee11-plus/src/main/java/org/eclipse/jetty/ee11/plus/webapp/EnvConfiguration.java +++ b/jetty-ee11/jetty-ee11-plus/src/main/java/org/eclipse/jetty/ee11/plus/webapp/EnvConfiguration.java @@ -87,7 +87,7 @@ public class EnvConfiguration extends AbstractConfiguration { XmlConfiguration configuration = new XmlConfiguration(jettyEnvXmlResource); configuration.setJettyStandardIdsAndProperties(context.getServer(), null); - WebAppClassLoader.runWithServerClassAccess(() -> + WebAppClassLoader.runWithHiddenClassAccess(() -> { configuration.configure(context); return null; diff --git a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/JettyWebXmlConfiguration.java b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/JettyWebXmlConfiguration.java index 12b532b49f0..e3c9419c76a 100644 --- a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/JettyWebXmlConfiguration.java +++ b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/JettyWebXmlConfiguration.java @@ -69,7 +69,7 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration try { - WebAppClassLoader.runWithServerClassAccess(() -> + WebAppClassLoader.runWithHiddenClassAccess(() -> { jetty_config.configure(context); return null; diff --git a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppClassLoader.java b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppClassLoader.java index da46960c538..6c73bf678c4 100644 --- a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppClassLoader.java +++ b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppClassLoader.java @@ -71,7 +71,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility } private static final Logger LOG = LoggerFactory.getLogger(WebAppClassLoader.class); - private static final ThreadLocal __loadServerClasses = new ThreadLocal<>(); + private static final ThreadLocal __loadHiddenClasses = new ThreadLocal<>(); private final Context _context; private final ClassLoader _parent; @@ -117,7 +117,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility } /** - * Run an action with access to ServerClasses + * Run an action with access to Hidden Classes *

Run the passed {@link PrivilegedExceptionAction} with the classloader * configured so as to allow server classes to be visible

* @@ -126,20 +126,20 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility * @return The return from the action * @throws Exception if thrown by the action */ - public static T runWithServerClassAccess(PrivilegedExceptionAction action) throws Exception + public static T runWithHiddenClassAccess(PrivilegedExceptionAction action) throws Exception { - Boolean lsc = __loadServerClasses.get(); + Boolean lsc = __loadHiddenClasses.get(); try { - __loadServerClasses.set(true); + __loadHiddenClasses.set(true); return action.run(); } finally { if (lsc == null) - __loadServerClasses.remove(); + __loadHiddenClasses.remove(); else - __loadServerClasses.set(lsc); + __loadHiddenClasses.set(lsc); } } @@ -297,7 +297,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility while (urls != null && urls.hasMoreElements()) { URL url = urls.nextElement(); - if (Boolean.TRUE.equals(__loadServerClasses.get()) || !_context.isHiddenResource(name, url)) + if (Boolean.TRUE.equals(__loadHiddenClasses.get()) || !_context.isHiddenResource(name, url)) fromParent.add(url); } @@ -345,7 +345,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility // return if we have a url the webapp is allowed to see if (parentUrl != null && - (Boolean.TRUE.equals(__loadServerClasses.get()) || + (Boolean.TRUE.equals(__loadHiddenClasses.get()) || !_context.isHiddenResource(name, parentUrl))) resource = parentUrl; else @@ -373,7 +373,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility // Couldn't find or see a webapp resource, so try a parent URL parentUrl = _parent.getResource(name); if (parentUrl != null && - (Boolean.TRUE.equals(__loadServerClasses.get()) || + (Boolean.TRUE.equals(__loadHiddenClasses.get()) || !_context.isHiddenResource(name, parentUrl))) resource = parentUrl; // We couldn't find a parent resource, so OK to return a webapp one if it exists @@ -420,7 +420,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility throw new ClassNotFoundException("Bad ClassLoader: returned null for loadClass(" + name + ")"); // If the webapp is allowed to see this class - if (Boolean.TRUE.equals(__loadServerClasses.get()) || !_context.isHiddenClass(parentClass)) + if (Boolean.TRUE.equals(__loadHiddenClasses.get()) || !_context.isHiddenClass(parentClass)) { return parentClass; } @@ -468,7 +468,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility { parentClass = _parent.loadClass(name); // If the webapp is allowed to see this class - if (Boolean.TRUE.equals(__loadServerClasses.get()) || !_context.isHiddenClass(parentClass)) + if (Boolean.TRUE.equals(__loadHiddenClasses.get()) || !_context.isHiddenClass(parentClass)) { return parentClass; } diff --git a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppContext.java b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppContext.java index c2bd0ef0465..f8d65006a83 100644 --- a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppContext.java +++ b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppContext.java @@ -841,18 +841,18 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL @Override public void dump(Appendable out, String indent) throws IOException { - List systemClasses = null; + List protectedClasses = null; if (_protectedClasses != null) { - systemClasses = new ArrayList<>(_protectedClasses); - Collections.sort(systemClasses); + protectedClasses = new ArrayList<>(_protectedClasses); + Collections.sort(protectedClasses); } - List serverClasses = null; + List hiddenClasses = null; if (_hiddenClasses != null) { - serverClasses = new ArrayList<>(_hiddenClasses); - Collections.sort(serverClasses); + hiddenClasses = new ArrayList<>(_hiddenClasses); + Collections.sort(hiddenClasses); } String name = getDisplayName(); @@ -883,8 +883,8 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL dumpObjects(out, indent, new ClassLoaderDump(getClassLoader()), - new DumpableCollection("Systemclasses " + name, systemClasses), - new DumpableCollection("Serverclasses " + name, serverClasses), + new DumpableCollection("Protected classes " + name, protectedClasses), + new DumpableCollection("Hidden classes " + name, hiddenClasses), new DumpableCollection("Configurations " + name, _configurations), new DumpableCollection("Handler attributes " + name, asAttributeMap().entrySet()), new DumpableCollection("Context attributes " + name, getContext().asAttributeMap().entrySet()), @@ -1464,32 +1464,4 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL { return _metadata; } - - /** - * Add a Server Class pattern to use for all WebAppContexts. - * @param server The {@link Server} instance to add classes to - * @param patterns the patterns to use - * @see #getHiddenClassMatcher() - * @see #getHiddenClasses() - * @deprecated use {@link WebAppClassLoading#addProtectedClasses(Server, String...)} - */ - @Deprecated(since = "12.0.8", forRemoval = true) - public static void addServerClasses(Server server, String... patterns) - { - WebAppClassLoading.addHiddenClasses(server, patterns); - } - - /** - * Add a System Class pattern to use for all WebAppContexts. - * @param server The {@link Server} instance to add classes to - * @param patterns the patterns to use - * @see #getProtectedClassMatcher() - * @see #getProtectedClasses() - * @deprecated use {@link WebAppClassLoading#addHiddenClasses(Server, String...)} - */ - @Deprecated(since = "12.0.8", forRemoval = true) - public static void addSystemClasses(Server server, String... patterns) - { - WebAppClassLoading.addProtectedClasses(server, patterns); - } } diff --git a/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/WebAppClassLoaderTest.java b/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/WebAppClassLoaderTest.java index 72c8c9dcd5e..1811843d5db 100644 --- a/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/WebAppClassLoaderTest.java +++ b/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/WebAppClassLoaderTest.java @@ -353,7 +353,7 @@ public class WebAppClassLoaderTest expected.add(webappWebInfLibAcme); expected.add(webappWebInfClasses); - assertThat("Resources Found (Parent Loader Priority == true) (with serverClasses filtering)", resources, ordered(expected)); + assertThat("Resources Found (Parent Loader Priority == true) (with hiddenClasses filtering)", resources, ordered(expected)); // dump(resources); // assertEquals(2,resources.size()); @@ -374,7 +374,7 @@ public class WebAppClassLoaderTest expected.clear(); expected.add(targetTestClasses); - assertThat("Resources Found (Parent Loader Priority == true) (with systemClasses filtering)", resources, ordered(expected)); + assertThat("Resources Found (Parent Loader Priority == true) (with hiddenClasses filtering)", resources, ordered(expected)); } @Test diff --git a/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/WebAppContextTest.java b/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/WebAppContextTest.java index bc4a2119ce2..20252099aff 100644 --- a/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/WebAppContextTest.java +++ b/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/WebAppContextTest.java @@ -951,7 +951,7 @@ public class WebAppContextTest WebAppContext context = new WebAppContext(); context.setContextPath("/"); - Path testPath = MavenPaths.targetTestDir("testAddServerClasses"); + Path testPath = MavenPaths.targetTestDir("testAddHiddenClasses"); FS.ensureDirExists(testPath); FS.ensureEmpty(testPath); Path warPath = createWar(testPath, "test.war"); @@ -984,7 +984,7 @@ public class WebAppContextTest WebAppContext context = new WebAppContext(); context.setContextPath("/"); - Path testPath = MavenPaths.targetTestDir("testAddServerClasses"); + Path testPath = MavenPaths.targetTestDir("testAddHiddenClasses"); FS.ensureDirExists(testPath); FS.ensureEmpty(testPath); Path warPath = createWar(testPath, "test.war");