From d44ba7e24a86d3f16d275b151f1e7fc9755b1ad3 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 19 Aug 2015 16:28:36 +1000 Subject: [PATCH] Improved Context pluggability --- .../jetty/server/handler/ContextHandler.java | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index a9e28d051c4..cbdde7fae5c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -125,6 +125,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu private static final ThreadLocal __context = new ThreadLocal(); + private static String __serverInfo = "jetty/" + Server.getVersion(); + /** * If a context attribute with this name is set, it is interpreted as a comma separated list of attribute name. Any other context attributes that are set * with a name from this list will result in a call to {@link #setManagedAttribute(String, Object)}, which typically initiates the creation of a JMX MBean @@ -154,6 +156,20 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu return null; } + /* ------------------------------------------------------------ */ + public static String getServerInfo() + { + return __serverInfo; + } + + /* ------------------------------------------------------------ */ + public static void setServerInfo(String serverInfo) + { + __serverInfo = serverInfo; + } + + + protected Context _scontext; private final AttributesMap _attributes; private final Map _initParams; @@ -174,6 +190,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu private int _maxFormKeys = Integer.getInteger("org.eclipse.jetty.server.Request.maxFormKeys",-1).intValue(); private int _maxFormContentSize = Integer.getInteger("org.eclipse.jetty.server.Request.maxFormContentSize",-1).intValue(); private boolean _compactPath = false; + private boolean _usingSecurityManager = System.getSecurityManager()!=null; private final List _eventListeners=new CopyOnWriteArrayList<>(); private final List _programmaticListeners=new CopyOnWriteArrayList<>(); @@ -273,6 +290,18 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu _errorHandler.setServer(server); } + /* ------------------------------------------------------------ */ + public boolean isUsingSecurityManager() + { + return _usingSecurityManager; + } + + /* ------------------------------------------------------------ */ + public void setUsingSecurityManager(boolean usingSecurityManager) + { + _usingSecurityManager = usingSecurityManager; + } + /* ------------------------------------------------------------ */ /** * Set the virtual hosts for the context. Only requests that have a matching host header or fully qualified URL will be passed to that context with a @@ -2343,7 +2372,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu throw new UnsupportedOperationException(); //no security manager just return the classloader - if (System.getSecurityManager() == null) + if (!_usingSecurityManager) return _classLoader; else { @@ -2498,12 +2527,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu @Override public String getServerInfo() { - // NOTE: DO NOT CHANGE - // this is used by weld to detect Jetty - // implementation version - // See: https://github.com/weld/core/blob/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/jetty/JettyContainer.java - // and its touch(ContainerContext) method - return "jetty/" + Server.getVersion(); + return __serverInfo; } @Override @@ -2728,7 +2752,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu @Override public ClassLoader getClassLoader() { - AccessController.checkPermission(new RuntimePermission("getClassLoader")); return ContextHandler.class.getClassLoader(); }