From bfc76bcad76f8db5381aed4d3a6d09c2f17bc5dc Mon Sep 17 00:00:00 2001 From: Michael Gorovoy Date: Wed, 16 Jun 2010 10:30:25 +0000 Subject: [PATCH] Revert changes that were committed prematurely git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2011 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../eclipse/jetty/embedded/ProxyServer.java | 4 +- .../jetty/server/handler/ProxyHandler.java | 155 ------------------ .../eclipse/jetty/servlets/ProxyServlet.java | 103 +----------- .../java/org/eclipse/jetty/util/HostMap.java | 85 ---------- .../org/eclipse/jetty/util/IPAddressMap.java | 6 +- 5 files changed, 9 insertions(+), 344 deletions(-) delete mode 100644 jetty-util/src/main/java/org/eclipse/jetty/util/HostMap.java diff --git a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ProxyServer.java b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ProxyServer.java index 8662dd5acf1..d8862c0c4b8 100644 --- a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ProxyServer.java +++ b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ProxyServer.java @@ -33,9 +33,7 @@ public class ProxyServer server.setHandler(handler); handler.addServletWithMapping(ProxyServlet.class,"/"); - handler.getServlets()[0].setInitParameter("whiteList","www.google.com, galaxisweb.com/support/*"); - handler.getServlets()[0].setInitParameter("blackList","www.google.com/calendar/*"); - + server.start(); server.join(); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ProxyHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ProxyHandler.java index 0e41e87fa25..a1f28329557 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ProxyHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ProxyHandler.java @@ -5,21 +5,16 @@ import java.net.InetSocketAddress; import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; -import java.util.Collections; -import java.util.List; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; - import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.HttpMethods; import org.eclipse.jetty.http.HttpParser; -import org.eclipse.jetty.http.PathMap; import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.ConnectedEndPoint; import org.eclipse.jetty.io.Connection; @@ -31,8 +26,6 @@ import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpConnection; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.util.HostMap; -import org.eclipse.jetty.util.IPAddressMap; import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -55,8 +48,6 @@ public class ProxyHandler extends HandlerWrapper private volatile int _writeTimeout = 30000; private volatile ThreadPool _threadPool; private volatile boolean _privateThreadPool; - private HostMap _white = new HostMap(); - private HostMap _black = new HostMap(); public ProxyHandler() { @@ -68,13 +59,6 @@ public class ProxyHandler extends HandlerWrapper setHandler(handler); } - public ProxyHandler(Handler handler, String[] white, String[] black) - { - setHandler(handler); - set(white, _white); - set(black, _black); - } - /** * @return the timeout, in milliseconds, to connect to the remote server */ @@ -224,12 +208,6 @@ public class ProxyHandler extends HandlerWrapper host = serverAddress.substring(0, colon); port = Integer.parseInt(serverAddress.substring(colon + 1)); } - - String uri = request.getRequestURI(); - if (validateDestination(host, uri)) - { - throw new ServletException("Forbidden: "+host+uri); - } SocketChannel channel = connectToServer(request, host, port); @@ -727,137 +705,4 @@ public class ProxyHandler extends HandlerWrapper } } } - - /* ------------------------------------------------------------ */ - /** - * Add a whitelist entry to an existing handler configuration - * - * @param entry new whitelist entry - */ - public void addWhite(String entry) - { - add(entry, _white); - } - - /* ------------------------------------------------------------ */ - /** - * Add a blacklist entry to an existing handler configuration - * - * @param entry new blacklist entry - */ - public void addBlack(String entry) - { - add(entry, _black); - } - - /* ------------------------------------------------------------ */ - /** - * Re-initialize the whitelist of existing handler object - * - * @param entries array of whitelist entries - */ - public void setWhite(String[] entries) - { - set(entries, _white); - } - - /* ------------------------------------------------------------ */ - /** - * Re-initialize the blacklist of existing handler object - * - * @param entries array of blacklist entries - */ - public void setBlack(String[] entries) - { - set(entries, _black); - } - - /* ------------------------------------------------------------ */ - /** - * Helper method to process a list of new entries and replace - * the content of the specified host map - * - * @param entries new entries - * @param patternMap target host map - */ - protected void set(String[] entries, HostMap hostMap) - { - hostMap.clear(); - - for (String addrPath:entries) - { - add(addrPath, hostMap); - } - } - - /* ------------------------------------------------------------ */ - /** - * Helper method to parse the new entry and add it to - * the specified host map. - * - * @param entry new entry - * @param patternMap target host map - */ - private void add(String entry, HostMap hostMap) - { - if (entry != null && entry.length() > 0) - { - int idx = entry.indexOf('/'); - - String host = idx > 0 ? entry.substring(0,idx) : entry; - String path = idx > 0 ? entry.substring(idx) : "/*"; - - host = host.trim(); - PathMap pathMap = hostMap.get(host); - if (pathMap == null) - { - pathMap = new PathMap(true); - hostMap.put(host,pathMap); - } - if (path != null) - pathMap.put(path,path); - } - } - - public boolean validateDestination(String host, String path) - { - if (_white.size()>0) - { - boolean match = false; - - Object whiteObj = _white.getLazyMatches(host); - if (whiteObj != null) - { - List whiteList = (whiteObj instanceof List) ? (List)whiteObj : Collections.singletonList(whiteObj); - - for (Object entry: whiteList) - { - PathMap pathMap = ((Map.Entry)entry).getValue(); - if (match = (pathMap!=null && (pathMap.size()==0 || pathMap.match(path)!=null))) - break; - } - } - - if (!match) - return false; - } - - if (_black.size() > 0) - { - Object blackObj = _black.getLazyMatches(host); - if (blackObj != null) - { - List blackList = (blackObj instanceof List) ? (List)blackObj : Collections.singletonList(blackObj); - - for (Object entry: blackList) - { - PathMap pathMap = ((Map.Entry)entry).getValue(); - if (pathMap!=null && (pathMap.size()==0 || pathMap.match(path)!=null)) - return false; - } - } - } - - return true; - } } diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java index 50254355c07..9197b6834f8 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java +++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java @@ -22,14 +22,8 @@ import java.net.MalformedURLException; import java.net.Socket; import java.net.URI; import java.net.URISyntaxException; -import java.util.Collections; import java.util.Enumeration; -import java.util.HashMap; import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; - import javax.servlet.Servlet; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -48,10 +42,8 @@ import org.eclipse.jetty.http.HttpHeaderValues; import org.eclipse.jetty.http.HttpHeaders; import org.eclipse.jetty.http.HttpSchemes; import org.eclipse.jetty.http.HttpURI; -import org.eclipse.jetty.http.PathMap; import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.EofException; -import org.eclipse.jetty.util.HostMap; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -80,8 +72,8 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; public class ProxyServlet implements Servlet { protected Logger _log; - protected HttpClient _client; - protected String _hostHeader; + HttpClient _client; + String _hostHeader; protected HashSet _DontProxyHeaders = new HashSet(); { @@ -98,8 +90,6 @@ public class ProxyServlet implements Servlet protected ServletConfig _config; protected ServletContext _context; - protected HostMap _white = new HostMap(); - protected HostMap _black = new HostMap(); /* ------------------------------------------------------------ */ /* (non-Javadoc) @@ -139,17 +129,6 @@ public class ProxyServlet implements Servlet _context.setAttribute(config.getServletName()+".ThreadPool",_client.getThreadPool()); _context.setAttribute(config.getServletName()+".HttpClient",_client); } - - String white = config.getInitParameter("whiteList"); - if (white != null) - { - parseList(white, _white); - } - String black = config.getInitParameter("blackList"); - if (black != null) - { - parseList(black, _black); - } } catch (Exception e) { @@ -157,74 +136,6 @@ public class ProxyServlet implements Servlet } } - private void parseList(String list, HostMap hostMap) - { - int idx; - String entry; - - StringTokenizer entries = new StringTokenizer(list, ","); - while(entries.hasMoreTokens()) - { - entry = entries.nextToken(); - idx = entry.indexOf('/'); - - String host = idx > 0 ? entry.substring(0,idx) : entry; - String path = idx > 0 ? entry.substring(idx) : "/*"; - - host = host.trim(); - PathMap pathMap = hostMap.get(host); - if (pathMap == null) - { - pathMap = new PathMap(true); - hostMap.put(host,pathMap); - } - if (path != null) - pathMap.put(path,path); - } - } - - public boolean validateDestination(String host, String path) - { - if (_white.size()>0) - { - boolean match = false; - - Object whiteObj = _white.getLazyMatches(host); - if (whiteObj != null) - { - List whiteList = (whiteObj instanceof List) ? (List)whiteObj : Collections.singletonList(whiteObj); - - for (Object entry: whiteList) - { - PathMap pathMap = ((Map.Entry)entry).getValue(); - if (match = (pathMap!=null && (pathMap.size()==0 || pathMap.match(path)!=null))) - break; - } - } - - if (!match) - return false; - } - - if (_black.size() > 0) - { - Object blackObj = _black.getLazyMatches(host); - if (blackObj != null) - { - List blackList = (blackObj instanceof List) ? (List)blackObj : Collections.singletonList(blackObj); - - for (Object entry: blackList) - { - PathMap pathMap = ((Map.Entry)entry).getValue(); - if (pathMap!=null && (pathMap.size()==0 || pathMap.match(path)!=null)) - return false; - } - } - } - - return true; - } - /* ------------------------------------------------------------ */ /* (non-Javadoc) * @see javax.servlet.Servlet#getServletConfig() @@ -512,9 +423,6 @@ public class ProxyServlet implements Servlet protected HttpURI proxyHttpURI(String scheme, String serverName, int serverPort, String uri) throws MalformedURLException { - if (!validateDestination(serverName, uri)) - return null; - return new HttpURI(scheme+"://"+serverName+":"+serverPort+uri); } @@ -609,13 +517,8 @@ public class ProxyServlet implements Servlet { if (!uri.startsWith(_prefix)) return null; - - URI dstUri = new URI(_proxyTo + uri.substring(_prefix.length())).normalize(); - - if (!validateDestination(dstUri.getHost(),dstUri.getPath())) - return null; - return new HttpURI(dstUri.toString()); + return new HttpURI(new URI(_proxyTo + uri.substring(_prefix.length())).normalize().toString()); } catch (URISyntaxException ex) { diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/HostMap.java b/jetty-util/src/main/java/org/eclipse/jetty/util/HostMap.java deleted file mode 100644 index cc934d40829..00000000000 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/HostMap.java +++ /dev/null @@ -1,85 +0,0 @@ -// ======================================================================== -// Copyright (c) 2010 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== - - -package org.eclipse.jetty.util; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; - -/* ------------------------------------------------------------ */ -/** - */ -public class HostMap extends HashMap -{ - /* --------------------------------------------------------------- */ - /** Construct empty HostMap. - */ - public HostMap() - { - super(11); - } - - /* --------------------------------------------------------------- */ - /** Construct empty HostMap. - * - * @param capacity initial capacity - */ - public HostMap(int capacity) - { - super (capacity); - } - - @Override - public TYPE put(String host, TYPE object) - throws IllegalArgumentException - { - return super.put(host, object); - } - - @Override - public TYPE get(Object key) - { - return super.get(key); - } - - public Object getLazyMatches(String host) - { - if (host == null) - return LazyList.getList(super.entrySet()); - - int idx = 0; - String domain = host.trim(); - HashSet domains = new HashSet(); - do { - domains.add(domain); - if ((idx = domain.indexOf('.')) > 0) - { - domain = domain.substring(idx+1); - } - } while (idx > 0); - - Object entries = null; - for(Map.Entry entry: super.entrySet()) - { - if (domains.contains(entry.getKey())) - { - entries = LazyList.add(entries,entry); - } - } - - return entries; - } - -} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/IPAddressMap.java b/jetty-util/src/main/java/org/eclipse/jetty/util/IPAddressMap.java index 631d25a473d..53345a1088d 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/IPAddressMap.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/IPAddressMap.java @@ -49,7 +49,7 @@ public class IPAddressMap extends HashMap } /* --------------------------------------------------------------- */ - /** Construct empty IPAddressMap. + /** Construct empty AddrPatternMap. * * @param capacity initial capacity */ @@ -84,6 +84,10 @@ public class IPAddressMap extends HashMap * * @see java.util.HashMap#get(java.lang.Object) */ + /* ------------------------------------------------------------ */ + /** + * @see java.util.HashMap#get(java.lang.Object) + */ @Override public TYPE get(Object key) {