Skip to content

Commit

Permalink
remove more system/server classes from ee11
Browse files Browse the repository at this point in the history
  • Loading branch information
gregw committed May 23, 2024
1 parent 24335af commit 088788e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public void addStartupClasses(Class<?>... clazzes)
protected Set<Class<?>> resolveStartupClasses() throws Exception
{
final Set<Class<?>> classes = new HashSet<>();
WebAppClassLoader.runWithServerClassAccess(() ->
WebAppClassLoader.runWithHiddenClassAccess(() ->
{
for (String name:_startupClassNames)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ public ContextHandler createContextHandler(AbstractContextProvider provider, App
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());
Expand Down Expand Up @@ -382,7 +382,7 @@ public ContextHandler createContextHandler(AbstractContextProvider provider, App
try
{
Thread.currentThread().setContextClassLoader(environmentLoader);
WebAppClassLoader.runWithServerClassAccess(() ->
WebAppClassLoader.runWithHiddenClassAccess(() ->
{
Configurations.getKnown();
return null;
Expand Down Expand Up @@ -468,10 +468,10 @@ public ContextHandler createContextHandler(AbstractContextProvider provider, App
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void configure(WebAppContext context) throws Exception
{
XmlConfiguration configuration = new XmlConfiguration(jettyEnvXmlResource);
configuration.setJettyStandardIdsAndProperties(context.getServer(), null);
WebAppClassLoader.runWithServerClassAccess(() ->
WebAppClassLoader.runWithHiddenClassAccess(() ->
{
configuration.configure(context);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void configure(WebAppContext context) throws Exception

try
{
WebAppClassLoader.runWithServerClassAccess(() ->
WebAppClassLoader.runWithHiddenClassAccess(() ->
{
jetty_config.configure(context);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,7 +117,7 @@ public interface Context extends ClassVisibilityChecker
}

/**
* 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>
*
Expand All @@ -126,20 +126,20 @@ public interface Context extends ClassVisibilityChecker
* @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);
}
}

Expand Down Expand Up @@ -297,7 +297,7 @@ public Enumeration<URL> getResources(String name) throws IOException
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);
}

Expand Down Expand Up @@ -345,7 +345,7 @@ public URL getResource(String name)

// 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
Expand Down Expand Up @@ -373,7 +373,7 @@ public URL getResource(String name)
// 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
Expand Down Expand Up @@ -420,7 +420,7 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
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;
}
Expand Down Expand Up @@ -468,7 +468,7 @@ else if (e != ex)
{
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,18 +841,18 @@ public String toString()
@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();
Expand Down Expand Up @@ -883,8 +883,8 @@ else if (getBaseResource() != null)

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()),
Expand Down Expand Up @@ -1464,32 +1464,4 @@ public MetaData getMetaData()
{
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public void testResources() throws Exception
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());
Expand All @@ -374,7 +374,7 @@ public void testResources() throws Exception
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ public void testAddHiddenClasses() throws Exception
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");
Expand Down Expand Up @@ -984,7 +984,7 @@ public void testAddProtectedClasses() throws Exception

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");
Expand Down

0 comments on commit 088788e

Please sign in to comment.