remove more system/server classes from ee11
This commit is contained in:
parent
24335af115
commit
088788e086
|
@ -351,7 +351,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
||||||
protected Set<Class<?>> resolveStartupClasses() throws Exception
|
protected Set<Class<?>> resolveStartupClasses() throws Exception
|
||||||
{
|
{
|
||||||
final Set<Class<?>> classes = new HashSet<>();
|
final Set<Class<?>> classes = new HashSet<>();
|
||||||
WebAppClassLoader.runWithServerClassAccess(() ->
|
WebAppClassLoader.runWithHiddenClassAccess(() ->
|
||||||
{
|
{
|
||||||
for (String name:_startupClassNames)
|
for (String name:_startupClassNames)
|
||||||
{
|
{
|
||||||
|
|
|
@ -293,10 +293,10 @@ public class EE11Activator implements BundleActivator
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.currentThread().setContextClassLoader(contextHandler.getClassLoader());
|
Thread.currentThread().setContextClassLoader(contextHandler.getClassLoader());
|
||||||
WebAppClassLoader.runWithServerClassAccess(() ->
|
WebAppClassLoader.runWithHiddenClassAccess(() ->
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(ResourceFactory.of(contextHandler).newResource(contextXmlURI));
|
XmlConfiguration xmlConfiguration = new XmlConfiguration(ResourceFactory.of(contextHandler).newResource(contextXmlURI));
|
||||||
WebAppClassLoader.runWithServerClassAccess(() ->
|
WebAppClassLoader.runWithHiddenClassAccess(() ->
|
||||||
{
|
{
|
||||||
Map<String, String> properties = new HashMap<>();
|
Map<String, String> properties = new HashMap<>();
|
||||||
xmlConfiguration.getIdMap().put("Server", osgiApp.getDeploymentManager().getServer());
|
xmlConfiguration.getIdMap().put("Server", osgiApp.getDeploymentManager().getServer());
|
||||||
|
@ -382,7 +382,7 @@ public class EE11Activator implements BundleActivator
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.currentThread().setContextClassLoader(environmentLoader);
|
Thread.currentThread().setContextClassLoader(environmentLoader);
|
||||||
WebAppClassLoader.runWithServerClassAccess(() ->
|
WebAppClassLoader.runWithHiddenClassAccess(() ->
|
||||||
{
|
{
|
||||||
Configurations.getKnown();
|
Configurations.getKnown();
|
||||||
return null;
|
return null;
|
||||||
|
@ -468,10 +468,10 @@ public class EE11Activator implements BundleActivator
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.currentThread().setContextClassLoader(webApp.getClassLoader());
|
Thread.currentThread().setContextClassLoader(webApp.getClassLoader());
|
||||||
WebAppClassLoader.runWithServerClassAccess(() ->
|
WebAppClassLoader.runWithHiddenClassAccess(() ->
|
||||||
{
|
{
|
||||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(ResourceFactory.of(webApp).newResource(contextXmlUri));
|
XmlConfiguration xmlConfiguration = new XmlConfiguration(ResourceFactory.of(webApp).newResource(contextXmlUri));
|
||||||
WebAppClassLoader.runWithServerClassAccess(() ->
|
WebAppClassLoader.runWithHiddenClassAccess(() ->
|
||||||
{
|
{
|
||||||
Map<String, String> properties = new HashMap<>();
|
Map<String, String> properties = new HashMap<>();
|
||||||
xmlConfiguration.getIdMap().put("Server", osgiApp.getDeploymentManager().getServer());
|
xmlConfiguration.getIdMap().put("Server", osgiApp.getDeploymentManager().getServer());
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class EnvConfiguration extends AbstractConfiguration
|
||||||
{
|
{
|
||||||
XmlConfiguration configuration = new XmlConfiguration(jettyEnvXmlResource);
|
XmlConfiguration configuration = new XmlConfiguration(jettyEnvXmlResource);
|
||||||
configuration.setJettyStandardIdsAndProperties(context.getServer(), null);
|
configuration.setJettyStandardIdsAndProperties(context.getServer(), null);
|
||||||
WebAppClassLoader.runWithServerClassAccess(() ->
|
WebAppClassLoader.runWithHiddenClassAccess(() ->
|
||||||
{
|
{
|
||||||
configuration.configure(context);
|
configuration.configure(context);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WebAppClassLoader.runWithServerClassAccess(() ->
|
WebAppClassLoader.runWithHiddenClassAccess(() ->
|
||||||
{
|
{
|
||||||
jetty_config.configure(context);
|
jetty_config.configure(context);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(WebAppClassLoader.class);
|
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 Context _context;
|
||||||
private final ClassLoader _parent;
|
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
|
* <p>Run the passed {@link PrivilegedExceptionAction} with the classloader
|
||||||
* configured so as to allow server classes to be visible</p>
|
* 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
|
* @return The return from the action
|
||||||
* @throws Exception if thrown by 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
|
try
|
||||||
{
|
{
|
||||||
__loadServerClasses.set(true);
|
__loadHiddenClasses.set(true);
|
||||||
return action.run();
|
return action.run();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (lsc == null)
|
if (lsc == null)
|
||||||
__loadServerClasses.remove();
|
__loadHiddenClasses.remove();
|
||||||
else
|
else
|
||||||
__loadServerClasses.set(lsc);
|
__loadHiddenClasses.set(lsc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility
|
||||||
while (urls != null && urls.hasMoreElements())
|
while (urls != null && urls.hasMoreElements())
|
||||||
{
|
{
|
||||||
URL url = urls.nextElement();
|
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);
|
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
|
// return if we have a url the webapp is allowed to see
|
||||||
if (parentUrl != null &&
|
if (parentUrl != null &&
|
||||||
(Boolean.TRUE.equals(__loadServerClasses.get()) ||
|
(Boolean.TRUE.equals(__loadHiddenClasses.get()) ||
|
||||||
!_context.isHiddenResource(name, parentUrl)))
|
!_context.isHiddenResource(name, parentUrl)))
|
||||||
resource = parentUrl;
|
resource = parentUrl;
|
||||||
else
|
else
|
||||||
|
@ -373,7 +373,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility
|
||||||
// Couldn't find or see a webapp resource, so try a parent
|
// Couldn't find or see a webapp resource, so try a parent
|
||||||
URL parentUrl = _parent.getResource(name);
|
URL parentUrl = _parent.getResource(name);
|
||||||
if (parentUrl != null &&
|
if (parentUrl != null &&
|
||||||
(Boolean.TRUE.equals(__loadServerClasses.get()) ||
|
(Boolean.TRUE.equals(__loadHiddenClasses.get()) ||
|
||||||
!_context.isHiddenResource(name, parentUrl)))
|
!_context.isHiddenResource(name, parentUrl)))
|
||||||
resource = parentUrl;
|
resource = parentUrl;
|
||||||
// We couldn't find a parent resource, so OK to return a webapp one if it exists
|
// 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 + ")");
|
throw new ClassNotFoundException("Bad ClassLoader: returned null for loadClass(" + name + ")");
|
||||||
|
|
||||||
// If the webapp is allowed to see this class
|
// 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;
|
return parentClass;
|
||||||
}
|
}
|
||||||
|
@ -468,7 +468,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility
|
||||||
{
|
{
|
||||||
parentClass = _parent.loadClass(name);
|
parentClass = _parent.loadClass(name);
|
||||||
// If the webapp is allowed to see this class
|
// 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;
|
return parentClass;
|
||||||
}
|
}
|
||||||
|
|
|
@ -841,18 +841,18 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
||||||
@Override
|
@Override
|
||||||
public void dump(Appendable out, String indent) throws IOException
|
public void dump(Appendable out, String indent) throws IOException
|
||||||
{
|
{
|
||||||
List<String> systemClasses = null;
|
List<String> protectedClasses = null;
|
||||||
if (_protectedClasses != null)
|
if (_protectedClasses != null)
|
||||||
{
|
{
|
||||||
systemClasses = new ArrayList<>(_protectedClasses);
|
protectedClasses = new ArrayList<>(_protectedClasses);
|
||||||
Collections.sort(systemClasses);
|
Collections.sort(protectedClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> serverClasses = null;
|
List<String> hiddenClasses = null;
|
||||||
if (_hiddenClasses != null)
|
if (_hiddenClasses != null)
|
||||||
{
|
{
|
||||||
serverClasses = new ArrayList<>(_hiddenClasses);
|
hiddenClasses = new ArrayList<>(_hiddenClasses);
|
||||||
Collections.sort(serverClasses);
|
Collections.sort(hiddenClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = getDisplayName();
|
String name = getDisplayName();
|
||||||
|
@ -883,8 +883,8 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
||||||
|
|
||||||
dumpObjects(out, indent,
|
dumpObjects(out, indent,
|
||||||
new ClassLoaderDump(getClassLoader()),
|
new ClassLoaderDump(getClassLoader()),
|
||||||
new DumpableCollection("Systemclasses " + name, systemClasses),
|
new DumpableCollection("Protected classes " + name, protectedClasses),
|
||||||
new DumpableCollection("Serverclasses " + name, serverClasses),
|
new DumpableCollection("Hidden classes " + name, hiddenClasses),
|
||||||
new DumpableCollection("Configurations " + name, _configurations),
|
new DumpableCollection("Configurations " + name, _configurations),
|
||||||
new DumpableCollection("Handler attributes " + name, asAttributeMap().entrySet()),
|
new DumpableCollection("Handler attributes " + name, asAttributeMap().entrySet()),
|
||||||
new DumpableCollection("Context attributes " + name, getContext().asAttributeMap().entrySet()),
|
new DumpableCollection("Context attributes " + name, getContext().asAttributeMap().entrySet()),
|
||||||
|
@ -1464,32 +1464,4 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
||||||
{
|
{
|
||||||
return _metadata;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -353,7 +353,7 @@ public class WebAppClassLoaderTest
|
||||||
expected.add(webappWebInfLibAcme);
|
expected.add(webappWebInfLibAcme);
|
||||||
expected.add(webappWebInfClasses);
|
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);
|
// dump(resources);
|
||||||
// assertEquals(2,resources.size());
|
// assertEquals(2,resources.size());
|
||||||
|
@ -374,7 +374,7 @@ public class WebAppClassLoaderTest
|
||||||
expected.clear();
|
expected.clear();
|
||||||
expected.add(targetTestClasses);
|
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
|
@Test
|
||||||
|
|
|
@ -951,7 +951,7 @@ public class WebAppContextTest
|
||||||
WebAppContext context = new WebAppContext();
|
WebAppContext context = new WebAppContext();
|
||||||
context.setContextPath("/");
|
context.setContextPath("/");
|
||||||
|
|
||||||
Path testPath = MavenPaths.targetTestDir("testAddServerClasses");
|
Path testPath = MavenPaths.targetTestDir("testAddHiddenClasses");
|
||||||
FS.ensureDirExists(testPath);
|
FS.ensureDirExists(testPath);
|
||||||
FS.ensureEmpty(testPath);
|
FS.ensureEmpty(testPath);
|
||||||
Path warPath = createWar(testPath, "test.war");
|
Path warPath = createWar(testPath, "test.war");
|
||||||
|
@ -984,7 +984,7 @@ public class WebAppContextTest
|
||||||
|
|
||||||
WebAppContext context = new WebAppContext();
|
WebAppContext context = new WebAppContext();
|
||||||
context.setContextPath("/");
|
context.setContextPath("/");
|
||||||
Path testPath = MavenPaths.targetTestDir("testAddServerClasses");
|
Path testPath = MavenPaths.targetTestDir("testAddHiddenClasses");
|
||||||
FS.ensureDirExists(testPath);
|
FS.ensureDirExists(testPath);
|
||||||
FS.ensureEmpty(testPath);
|
FS.ensureEmpty(testPath);
|
||||||
Path warPath = createWar(testPath, "test.war");
|
Path warPath = createWar(testPath, "test.war");
|
||||||
|
|
Loading…
Reference in New Issue