updates from review

This commit is contained in:
gregw 2024-04-04 22:48:02 +02:00
parent 1296040329
commit aff96fe739
6 changed files with 86 additions and 22 deletions

View File

@ -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

View File

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

View File

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

View File

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

View File

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

View File

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