diff --git a/jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/ServletCallbackHandler.java b/jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/ServletCallbackHandler.java index 65819e5fd9a..e65d97a2589 100644 --- a/jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/ServletCallbackHandler.java +++ b/jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/ServletCallbackHandler.java @@ -126,14 +126,14 @@ public class ServletCallbackHandler implements CallbackHandler public CallerPrincipalCallback getThreadCallerPrincipalCallback() { CallerPrincipalCallback callerPrincipalCallback = _callerPrincipals.get(); - _callerPrincipals.remove(); + _callerPrincipals.set(null); return callerPrincipalCallback; } public GroupPrincipalCallback getThreadGroupPrincipalCallback() { GroupPrincipalCallback groupPrincipalCallback = _groupPrincipals.get(); - _groupPrincipals.remove(); + _groupPrincipals.set(null); return groupPrincipalCallback; } } diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java index 8e0a5f7d19a..e170c0ddbc0 100644 --- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java +++ b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java @@ -211,7 +211,6 @@ public class ContextFactory implements ObjectFactory return (Context)__contextMap.get(loader); } - /** * Associate the given Context with the current thread. * disassociate method should be called to reset the context. @@ -227,10 +226,9 @@ public class ContextFactory implements ObjectFactory public static void disassociateContext(final Context ctx) { - __threadContext.remove(); + __threadContext.set(null); } - public static ClassLoader associateClassLoader(final ClassLoader loader) { ClassLoader prev = (ClassLoader)__threadClassLoader.get(); @@ -238,10 +236,9 @@ public class ContextFactory implements ObjectFactory return prev; } - public static void disassociateClassLoader () { - __threadClassLoader.remove(); + __threadClassLoader.set(null); } public static void dump(Appendable out, String indent) throws IOException @@ -259,5 +256,4 @@ public class ContextFactory implements ObjectFactory context.dump(out,indent+(last?" ":" | ")); } } - } diff --git a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ConnectHandler.java b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ConnectHandler.java index a80344839d6..7119cb32579 100644 --- a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ConnectHandler.java +++ b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ConnectHandler.java @@ -28,6 +28,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.Executor; + import javax.servlet.AsyncContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -44,6 +45,7 @@ import org.eclipse.jetty.io.SelectChannelEndPoint; import org.eclipse.jetty.io.SelectorManager; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpConnection; +import org.eclipse.jetty.server.HttpTransport; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.HandlerWrapper; import org.eclipse.jetty.util.BufferUtil; @@ -210,14 +212,14 @@ public class ConnectHandler extends HandlerWrapper *

CONNECT requests may have authentication headers such as {@code Proxy-Authorization} * that authenticate the client with the proxy.

* - * @param jettyRequest Jetty-specific http request + * @param baseRequest Jetty-specific http request * @param request the http request * @param response the http response * @param serverAddress the remote server address in the form {@code host:port} */ - protected void handleConnect(Request jettyRequest, HttpServletRequest request, HttpServletResponse response, String serverAddress) + protected void handleConnect(Request baseRequest, HttpServletRequest request, HttpServletResponse response, String serverAddress) { - jettyRequest.setHandled(true); + baseRequest.setHandled(true); try { boolean proceed = handleAuthentication(request, response, serverAddress); @@ -256,8 +258,18 @@ public class ConnectHandler extends HandlerWrapper if (LOG.isDebugEnabled()) LOG.debug("Connecting to {}", address); - - ConnectContext connectContext = new ConnectContext(request, response, asyncContext, HttpConnection.getCurrentConnection()); + + HttpTransport transport = baseRequest.getHttpChannel().getHttpTransport(); + + if (!(transport instanceof HttpConnection)) + { + if (LOG.isDebugEnabled()) + LOG.debug("CONNECT forbidden for {}", transport); + sendConnectResponse(request, response, HttpServletResponse.SC_FORBIDDEN); + return; + } + + ConnectContext connectContext = new ConnectContext(request, response, asyncContext, (HttpConnection)transport); if (channel.connect(address)) selector.accept(channel, connectContext); else diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyTunnellingTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyTunnellingTest.java index c12b9f266f3..c98d7bc2292 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyTunnellingTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyTunnellingTest.java @@ -347,9 +347,9 @@ public class ProxyTunnellingTest startProxy(new ConnectHandler() { @Override - protected void handleConnect(Request jettyRequest, HttpServletRequest request, HttpServletResponse response, String serverAddress) + protected void handleConnect(Request baseRequest, HttpServletRequest request, HttpServletResponse response, String serverAddress) { - HttpConnection.getCurrentConnection().close(); + ((HttpConnection)baseRequest.getHttpChannel().getHttpTransport()).close(); } }); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java index deb137606f3..7399ed6d855 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java @@ -80,10 +80,7 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor protected static HttpChannel setCurrentHttpChannel(HttpChannel channel) { HttpChannel last=__currentChannel.get(); - if (channel==null) - __currentChannel.remove(); - else - __currentChannel.set(channel); + __currentChannel.set(channel); return last; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index 605fc1b679e..bd1160f6e79 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -75,10 +75,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http protected static HttpConnection setCurrentConnection(HttpConnection connection) { HttpConnection last=__currentConnection.get(); - if (connection==null) - __currentConnection.remove(); - else - __currentConnection.set(connection); + __currentConnection.set(connection); return last; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/SecuredRedirectHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/SecuredRedirectHandler.java index ec564a05969..de4697582ec 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/SecuredRedirectHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/SecuredRedirectHandler.java @@ -42,14 +42,14 @@ public class SecuredRedirectHandler extends AbstractHandler @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - HttpConnection connection = HttpConnection.getCurrentConnection(); - if (baseRequest.isSecure() || (connection == null)) + HttpChannel channel = baseRequest.getHttpChannel(); + if (baseRequest.isSecure() || (channel == null)) { // nothing to do return; } - HttpConfiguration httpConfig = connection.getHttpConfiguration(); + HttpConfiguration httpConfig = channel.getHttpConfiguration(); if (httpConfig == null) { // no config, show error diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/NonBlockingThread.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/NonBlockingThread.java index 4fb75c7fb0c..fc0a4224208 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/NonBlockingThread.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/NonBlockingThread.java @@ -53,7 +53,7 @@ public class NonBlockingThread implements Runnable } finally { - __nonBlockingThread.remove(); + __nonBlockingThread.set(Boolean.FALSE); } } }