remove more system/server classes from ee11

This commit is contained in:
gregw 2024-05-23 11:37:05 +10:00
parent 24335af115
commit 088788e086
8 changed files with 32 additions and 60 deletions

View File

@ -351,7 +351,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
protected Set<Class<?>> resolveStartupClasses() throws Exception
{
final Set<Class<?>> classes = new HashSet<>();
WebAppClassLoader.runWithServerClassAccess(() ->
WebAppClassLoader.runWithHiddenClassAccess(() ->
{
for (String name:_startupClassNames)
{

View File

@ -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<String, String> 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<String, String> properties = new HashMap<>();
xmlConfiguration.getIdMap().put("Server", osgiApp.getDeploymentManager().getServer());

View File

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

View File

@ -69,7 +69,7 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
try
{
WebAppClassLoader.runWithServerClassAccess(() ->
WebAppClassLoader.runWithHiddenClassAccess(() ->
{
jetty_config.configure(context);
return null;

View File

@ -71,7 +71,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility
}
private static final Logger LOG = LoggerFactory.getLogger(WebAppClassLoader.class);
private static final ThreadLocal<Boolean> __loadServerClasses = new ThreadLocal<>();
private static final ThreadLocal<Boolean> __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
* <p>Run the passed {@link PrivilegedExceptionAction} with the classloader
* configured so as to allow server classes to be visible</p>
*
@ -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> T runWithServerClassAccess(PrivilegedExceptionAction<T> action) throws Exception
public static <T> T runWithHiddenClassAccess(PrivilegedExceptionAction<T> 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;
}

View File

@ -841,18 +841,18 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
@Override
public void dump(Appendable out, String indent) throws IOException
{
List<String> systemClasses = null;
List<String> protectedClasses = null;
if (_protectedClasses != null)
{
systemClasses = new ArrayList<>(_protectedClasses);
Collections.sort(systemClasses);
protectedClasses = new ArrayList<>(_protectedClasses);
Collections.sort(protectedClasses);
}
List<String> serverClasses = null;
List<String> 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);
}
}

View File

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

View File

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