From 1b7a5a29600e9711548bed267b61e198a058f50b Mon Sep 17 00:00:00 2001 From: Shawn O. Pearce Date: Sun, 6 Feb 2011 16:38:02 -0800 Subject: daemon: Use HTTP's resolver and factory pattern Using a resolver and factory pattern for the anonymous git:// Daemon class makes transport.Daemon more useful on non-file storage systems, or in embedded applications where the caller wants more precise control over the work tasks constructed within the daemon. Rather than defining new interfaces, move the existing HTTP ones into transport.resolver and make them generic on the connection handle type. For HTTP, continue to use HttpServletRequest, and for transport.Daemon use DaemonClient. To remain compatible with transport.Daemon, FileResolver needs to learn how to use multiple base directories, and how to export any Repository instance at a fixed name. Change-Id: I1efa6b2bd7c6567e983fbbf346947238ea2e847e Signed-off-by: Shawn O. Pearce --- org.eclipse.jgit.http.server/META-INF/MANIFEST.MF | 1 + .../jgit/http/server/HttpServerText.properties | 2 - .../eclipse/jgit/http/server/AsIsFileFilter.java | 4 +- .../org/eclipse/jgit/http/server/GitServlet.java | 29 +-- .../eclipse/jgit/http/server/HttpServerText.java | 2 - .../jgit/http/server/ReceivePackServlet.java | 6 +- .../eclipse/jgit/http/server/RepositoryFilter.java | 6 +- .../jgit/http/server/SmartServiceInfoRefs.java | 4 +- .../jgit/http/server/UploadPackServlet.java | 6 +- .../jgit/http/server/resolver/AsIsFileService.java | 2 + .../server/resolver/DefaultReceivePackFactory.java | 6 +- .../server/resolver/DefaultUploadPackFactory.java | 6 +- .../jgit/http/server/resolver/FileResolver.java | 167 -------------- .../http/server/resolver/ReceivePackFactory.java | 79 ------- .../http/server/resolver/RepositoryResolver.java | 77 ------- .../resolver/ServiceNotAuthorizedException.java | 56 ----- .../resolver/ServiceNotEnabledException.java | 56 ----- .../http/server/resolver/UploadPackFactory.java | 79 ------- org.eclipse.jgit.http.test/META-INF/MANIFEST.MF | 1 + .../eclipse/jgit/http/test/AdvertiseErrorTest.java | 8 +- .../eclipse/jgit/http/test/AsIsServiceTest.java | 4 +- .../http/test/DefaultReceivePackFactoryTest.java | 6 +- .../http/test/DefaultUploadPackFactoryTest.java | 6 +- .../jgit/http/test/DumbClientSmartServerTest.java | 6 +- .../eclipse/jgit/http/test/FileResolverTest.java | 4 +- .../eclipse/jgit/http/test/HookMessageTest.java | 8 +- .../eclipse/jgit/http/test/HttpClientTests.java | 6 +- .../jgit/http/test/SmartClientSmartServerTest.java | 6 +- org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF | 1 + .../eclipse/jgit/junit/http/SimpleHttpServer.java | 6 +- org.eclipse.jgit.pgm/META-INF/MANIFEST.MF | 1 + .../src/org/eclipse/jgit/pgm/Daemon.java | 16 +- org.eclipse.jgit/META-INF/MANIFEST.MF | 1 + .../resources/org/eclipse/jgit/JGitText.properties | 2 + .../src/org/eclipse/jgit/JGitText.java | 2 + .../src/org/eclipse/jgit/transport/Daemon.java | 247 ++++++++++---------- .../org/eclipse/jgit/transport/DaemonClient.java | 7 +- .../org/eclipse/jgit/transport/DaemonService.java | 10 +- .../jgit/transport/resolver/FileResolver.java | 256 +++++++++++++++++++++ .../transport/resolver/ReceivePackFactory.java | 82 +++++++ .../transport/resolver/RepositoryResolver.java | 87 +++++++ .../resolver/ServiceNotAuthorizedException.java | 56 +++++ .../resolver/ServiceNotEnabledException.java | 56 +++++ .../jgit/transport/resolver/UploadPackFactory.java | 82 +++++++ 44 files changed, 839 insertions(+), 716 deletions(-) delete mode 100644 org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/FileResolver.java delete mode 100644 org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ReceivePackFactory.java delete mode 100644 org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/RepositoryResolver.java delete mode 100644 org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotAuthorizedException.java delete mode 100644 org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotEnabledException.java delete mode 100644 org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/UploadPackFactory.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/FileResolver.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/ReceivePackFactory.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/RepositoryResolver.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/ServiceNotAuthorizedException.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/ServiceNotEnabledException.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/UploadPackFactory.java diff --git a/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF b/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF index 982e4c40c0..1a833562e5 100644 --- a/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF @@ -19,5 +19,6 @@ Import-Package: javax.servlet;version="[2.5.0,3.0.0)", org.eclipse.jgit.revwalk;version="[0.12.0,0.13.0)", org.eclipse.jgit.storage.file;version="[0.12.0,0.13.0)", org.eclipse.jgit.transport;version="[0.12.0,0.13.0)", + org.eclipse.jgit.transport.resolver;version="[0.12.0,0.13.0)", org.eclipse.jgit.util;version="[0.12.0,0.13.0)", org.eclipse.jgit.util.io;version="[0.12.0,0.13.0)" diff --git a/org.eclipse.jgit.http.server/resources/org/eclipse/jgit/http/server/HttpServerText.properties b/org.eclipse.jgit.http.server/resources/org/eclipse/jgit/http/server/HttpServerText.properties index 8e36aab28b..6232f47f05 100644 --- a/org.eclipse.jgit.http.server/resources/org/eclipse/jgit/http/server/HttpServerText.properties +++ b/org.eclipse.jgit.http.server/resources/org/eclipse/jgit/http/server/HttpServerText.properties @@ -13,8 +13,6 @@ noResolverAvailable=No resolver available parameterNotSet=Parameter {0} not set pathForParamNotFound={0} (for {1}) not found pathNotSupported={0} not supported -serviceNotEnabled=Service not enabled -serviceNotPermitted=Service not permitted servletAlreadyInitialized=Servlet already initialized servletMustNotBeNull=servlet must not be null servletWasAlreadyBound=servlet was already bound diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/AsIsFileFilter.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/AsIsFileFilter.java index 810f694202..b2250e3ef3 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/AsIsFileFilter.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/AsIsFileFilter.java @@ -59,9 +59,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jgit.http.server.resolver.AsIsFileService; -import org.eclipse.jgit.http.server.resolver.ServiceNotAuthorizedException; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; class AsIsFileFilter implements Filter { private final AsIsFileService asIs; diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java index e28e4eeb29..9be5fa7e9f 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java @@ -48,6 +48,7 @@ import java.text.MessageFormat; import javax.servlet.ServletConfig; import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jgit.http.server.glue.ErrorServlet; @@ -56,14 +57,14 @@ import org.eclipse.jgit.http.server.glue.RegexGroupFilter; import org.eclipse.jgit.http.server.glue.ServletBinder; import org.eclipse.jgit.http.server.resolver.DefaultReceivePackFactory; import org.eclipse.jgit.http.server.resolver.DefaultUploadPackFactory; -import org.eclipse.jgit.http.server.resolver.FileResolver; import org.eclipse.jgit.http.server.resolver.AsIsFileService; -import org.eclipse.jgit.http.server.resolver.ReceivePackFactory; -import org.eclipse.jgit.http.server.resolver.RepositoryResolver; import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.http.server.resolver.UploadPackFactory; import org.eclipse.jgit.transport.ReceivePack; import org.eclipse.jgit.transport.UploadPack; +import org.eclipse.jgit.transport.resolver.FileResolver; +import org.eclipse.jgit.transport.resolver.ReceivePackFactory; +import org.eclipse.jgit.transport.resolver.RepositoryResolver; +import org.eclipse.jgit.transport.resolver.UploadPackFactory; import org.eclipse.jgit.util.StringUtils; /** @@ -105,13 +106,13 @@ public class GitServlet extends MetaServlet { private volatile boolean initialized; - private RepositoryResolver resolver; + private RepositoryResolver resolver; private AsIsFileService asIs = new AsIsFileService(); - private UploadPackFactory uploadPackFactory = new DefaultUploadPackFactory(); + private UploadPackFactory uploadPackFactory = new DefaultUploadPackFactory(); - private ReceivePackFactory receivePackFactory = new DefaultReceivePackFactory(); + private ReceivePackFactory receivePackFactory = new DefaultReceivePackFactory(); /** * New servlet that will load its base directory from {@code web.xml}. @@ -132,7 +133,7 @@ public class GitServlet extends MetaServlet { * parameter table during init, which usually comes from the * {@code web.xml} file of the web application. */ - public void setRepositoryResolver(RepositoryResolver resolver) { + public void setRepositoryResolver(RepositoryResolver resolver) { assertNotInitialized(); this.resolver = resolver; } @@ -153,9 +154,10 @@ public class GitServlet extends MetaServlet { * the factory to construct and configure an {@link UploadPack} * session when a fetch or clone is requested by a client. */ - public void setUploadPackFactory(UploadPackFactory f) { + @SuppressWarnings("unchecked") + public void setUploadPackFactory(UploadPackFactory f) { assertNotInitialized(); - this.uploadPackFactory = f != null ? f : UploadPackFactory.DISABLED; + this.uploadPackFactory = f != null ? f : (UploadPackFactory)UploadPackFactory.DISABLED; } /** @@ -163,9 +165,10 @@ public class GitServlet extends MetaServlet { * the factory to construct and configure a {@link ReceivePack} * session when a push is requested by a client. */ - public void setReceivePackFactory(ReceivePackFactory f) { + @SuppressWarnings("unchecked") + public void setReceivePackFactory(ReceivePackFactory f) { assertNotInitialized(); - this.receivePackFactory = f != null ? f : ReceivePackFactory.DISABLED; + this.receivePackFactory = f != null ? f : (ReceivePackFactory)ReceivePackFactory.DISABLED; } private void assertNotInitialized() { @@ -180,7 +183,7 @@ public class GitServlet extends MetaServlet { if (resolver == null) { final File root = getFile("base-path"); final boolean exportAll = getBoolean("export-all"); - setRepositoryResolver(new FileResolver(root, exportAll)); + setRepositoryResolver(new FileResolver(root, exportAll)); } initialized = true; diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/HttpServerText.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/HttpServerText.java index 8ad0eb0497..fc10014427 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/HttpServerText.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/HttpServerText.java @@ -73,8 +73,6 @@ public class HttpServerText extends TranslationBundle { /***/ public String parameterNotSet; /***/ public String pathForParamNotFound; /***/ public String pathNotSupported; - /***/ public String serviceNotEnabled; - /***/ public String serviceNotPermitted; /***/ public String servletAlreadyInitialized; /***/ public String servletMustNotBeNull; /***/ public String servletWasAlreadyBound; diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java index 4bc05c1886..a85e84b210 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java @@ -56,12 +56,12 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jgit.http.server.resolver.ReceivePackFactory; -import org.eclipse.jgit.http.server.resolver.ServiceNotAuthorizedException; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.ReceivePack; import org.eclipse.jgit.transport.RefAdvertiser.PacketLineOutRefAdvertiser; +import org.eclipse.jgit.transport.resolver.ReceivePackFactory; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; /** Server side implementation of smart push over HTTP. */ class ReceivePackServlet extends HttpServlet { diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java index 7975809e87..ceac043ea5 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java @@ -63,10 +63,10 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jgit.errors.RepositoryNotFoundException; -import org.eclipse.jgit.http.server.resolver.RepositoryResolver; -import org.eclipse.jgit.http.server.resolver.ServiceNotAuthorizedException; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.transport.resolver.RepositoryResolver; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; /** * Opens a repository named by the path info through {@link RepositoryResolver}. diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java index 94e2e7f6f7..f9be95f04e 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java @@ -58,11 +58,11 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jgit.http.server.resolver.ServiceNotAuthorizedException; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.PacketLineOut; import org.eclipse.jgit.transport.RefAdvertiser.PacketLineOutRefAdvertiser; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; /** Filter in front of {@link InfoRefsServlet} to catch smart service requests. */ abstract class SmartServiceInfoRefs implements Filter { diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java index 602d66a90c..ff5e5d53c8 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java @@ -56,12 +56,12 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jgit.http.server.resolver.ServiceNotAuthorizedException; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; -import org.eclipse.jgit.http.server.resolver.UploadPackFactory; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.UploadPack; import org.eclipse.jgit.transport.RefAdvertiser.PacketLineOutRefAdvertiser; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; +import org.eclipse.jgit.transport.resolver.UploadPackFactory; /** Server side implementation of smart fetch over HTTP. */ class UploadPackServlet extends HttpServlet { diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/AsIsFileService.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/AsIsFileService.java index b9545f9101..43a7e246d6 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/AsIsFileService.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/AsIsFileService.java @@ -49,6 +49,8 @@ import org.eclipse.jgit.http.server.GitServlet; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Config.SectionParser; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; /** * Controls access to bare files in a repository. diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java index 2495751da2..38a3ec2f15 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java @@ -50,6 +50,9 @@ import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Config.SectionParser; import org.eclipse.jgit.transport.ReceivePack; +import org.eclipse.jgit.transport.resolver.ReceivePackFactory; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; /** * Create and configure {@link ReceivePack} service instance. @@ -63,7 +66,8 @@ import org.eclipse.jgit.transport.ReceivePack; * * and explicitly rejected otherwise. */ -public class DefaultReceivePackFactory implements ReceivePackFactory { +public class DefaultReceivePackFactory implements + ReceivePackFactory { private static final SectionParser CONFIG = new SectionParser() { public ServiceConfig parse(final Config cfg) { return new ServiceConfig(cfg); diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java index a8c953e186..76f40c58a9 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java @@ -49,6 +49,9 @@ import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Config.SectionParser; import org.eclipse.jgit.transport.UploadPack; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; +import org.eclipse.jgit.transport.resolver.UploadPackFactory; /** * Create and configure {@link UploadPack} service instance. @@ -56,7 +59,8 @@ import org.eclipse.jgit.transport.UploadPack; * Reading by upload-pack is permitted unless {@code http.uploadpack} is * explicitly set to false. */ -public class DefaultUploadPackFactory implements UploadPackFactory { +public class DefaultUploadPackFactory implements + UploadPackFactory { private static final SectionParser CONFIG = new SectionParser() { public ServiceConfig parse(final Config cfg) { return new ServiceConfig(cfg); diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/FileResolver.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/FileResolver.java deleted file mode 100644 index 296725b678..0000000000 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/FileResolver.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (C) 2009-2010, Google Inc. - * and other copyright owners as documented in the project's IP log. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.eclipse.jgit.http.server.resolver; - -import java.io.File; -import java.io.IOException; - -import javax.servlet.http.HttpServletRequest; - -import org.eclipse.jgit.errors.RepositoryNotFoundException; -import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.lib.RepositoryCache; -import org.eclipse.jgit.lib.RepositoryCache.FileKey; -import org.eclipse.jgit.util.FS; - -/** Default resolver serving from a single root path in local filesystem. */ -public class FileResolver implements RepositoryResolver { - private final File basePath; - - private final boolean exportAll; - - /** - * Create a new resolver for the given path. - * - * @param basePath - * the base path all repositories are rooted under. - * @param exportAll - * if true, exports all repositories, ignoring the check for the - * {@code git-daemon-export-ok} files. - */ - public FileResolver(final File basePath, final boolean exportAll) { - this.basePath = basePath; - this.exportAll = exportAll; - } - - public Repository open(final HttpServletRequest req, - final String repositoryName) throws RepositoryNotFoundException, - ServiceNotEnabledException { - if (isUnreasonableName(repositoryName)) - throw new RepositoryNotFoundException(repositoryName); - - final Repository db; - try { - final File gitdir = new File(basePath, repositoryName); - db = RepositoryCache.open(FileKey.lenient(gitdir, FS.DETECTED), true); - } catch (IOException e) { - throw new RepositoryNotFoundException(repositoryName, e); - } - - try { - if (isExportOk(req, repositoryName, db)) { - // We have to leak the open count to the caller, they - // are responsible for closing the repository if we - // complete successfully. - return db; - } else - throw new ServiceNotEnabledException(); - - } catch (RuntimeException e) { - db.close(); - throw new RepositoryNotFoundException(repositoryName, e); - - } catch (IOException e) { - db.close(); - throw new RepositoryNotFoundException(repositoryName, e); - - } catch (ServiceNotEnabledException e) { - db.close(); - throw e; - } - } - - /** @return {@code true} if all repositories are to be exported. */ - protected boolean isExportAll() { - return exportAll; - } - - /** - * Check if this repository can be served over HTTP. - *

- * The default implementation of this method returns true only if either - * {@link #isExportAll()} is true, or the {@code git-daemon-export-ok} file - * is present in the repository's directory. - * - * @param req - * the current HTTP request. - * @param repositoryName - * name of the repository, as present in the URL. - * @param db - * the opened repository instance. - * @return true if the repository is accessible; false if not. - * @throws IOException - * the repository could not be accessed, the caller will claim - * the repository does not exist. - */ - protected boolean isExportOk(HttpServletRequest req, String repositoryName, - Repository db) throws IOException { - if (isExportAll()) - return true; - else if (db.getDirectory() != null) - return new File(db.getDirectory(), "git-daemon-export-ok").exists(); - else - return false; - } - - private static boolean isUnreasonableName(final String name) { - if (name.length() == 0) - return true; // no empty paths - - if (name.indexOf('\\') >= 0) - return true; // no windows/dos style paths - if (new File(name).isAbsolute()) - return true; // no absolute paths - - if (name.startsWith("../")) - return true; // no "l../etc/passwd" - if (name.contains("/../")) - return true; // no "foo/../etc/passwd" - if (name.contains("/./")) - return true; // "foo/./foo" is insane to ask - if (name.contains("//")) - return true; // double slashes is sloppy, don't use it - - return false; // is a reasonable name - } -} diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ReceivePackFactory.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ReceivePackFactory.java deleted file mode 100644 index 2432632c01..0000000000 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ReceivePackFactory.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2009-2010, Google Inc. - * and other copyright owners as documented in the project's IP log. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.eclipse.jgit.http.server.resolver; - -import javax.servlet.http.HttpServletRequest; - -import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.transport.ReceivePack; - -/** Create and configure {@link ReceivePack} service instance. */ -public interface ReceivePackFactory { - /** A factory disabling the ReceivePack service for all repositories. */ - public static final ReceivePackFactory DISABLED = new ReceivePackFactory() { - public ReceivePack create(HttpServletRequest req, Repository db) - throws ServiceNotEnabledException { - throw new ServiceNotEnabledException(); - } - }; - - /** - * Create and configure a new ReceivePack instance for a repository. - * - * @param req - * current HTTP request, in case information from the request may - * help configure the ReceivePack instance. - * @param db - * the repository the receive would write into. - * @return the newly configured ReceivePack instance, must not be null. - * @throws ServiceNotEnabledException - * this factory refuses to create the instance because it is not - * allowed on the target repository, by any user. - * @throws ServiceNotAuthorizedException - * this factory refuses to create the instance for this HTTP - * request and repository, such as due to a permission error. - */ - ReceivePack create(HttpServletRequest req, Repository db) - throws ServiceNotEnabledException, ServiceNotAuthorizedException; -} diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/RepositoryResolver.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/RepositoryResolver.java deleted file mode 100644 index ba17dac45b..0000000000 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/RepositoryResolver.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2009-2010, Google Inc. - * and other copyright owners as documented in the project's IP log. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.eclipse.jgit.http.server.resolver; - -import javax.servlet.http.HttpServletRequest; - -import org.eclipse.jgit.errors.RepositoryNotFoundException; -import org.eclipse.jgit.lib.Repository; - -/** Locate a Git {@link Repository} by name from the URL. */ -public interface RepositoryResolver { - /** - * Locate and open a reference to a {@link Repository}. - *

- * The caller is responsible for closing the returned Repository. - * - * @param req - * the current HTTP request, may be used to inspect session state - * including cookies or user authentication. - * @param name - * name of the repository, as parsed out of the URL. - * @return the opened repository instance, never null. - * @throws RepositoryNotFoundException - * the repository does not exist or the name is incorrectly - * formatted as a repository name. - * @throws ServiceNotAuthorizedException - * the repository exists, but HTTP access is not allowed for the - * current user. - * @throws ServiceNotEnabledException - * the repository exists, but HTTP access is not allowed on the - * target repository, by any user. - */ - Repository open(HttpServletRequest req, String name) - throws RepositoryNotFoundException, ServiceNotAuthorizedException, - ServiceNotEnabledException; -} diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotAuthorizedException.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotAuthorizedException.java deleted file mode 100644 index 6c9bf693d3..0000000000 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotAuthorizedException.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2009-2010, Google Inc. - * and other copyright owners as documented in the project's IP log. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.eclipse.jgit.http.server.resolver; - -import org.eclipse.jgit.http.server.HttpServerText; - -/** Indicates the request service is not authorized for current user. */ -public class ServiceNotAuthorizedException extends Exception { - private static final long serialVersionUID = 1L; - - /** Indicates the request service is not available. */ - public ServiceNotAuthorizedException() { - super(HttpServerText.get().serviceNotPermitted); - } -} diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotEnabledException.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotEnabledException.java deleted file mode 100644 index adc132df3d..0000000000 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotEnabledException.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2009-2010, Google Inc. - * and other copyright owners as documented in the project's IP log. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.eclipse.jgit.http.server.resolver; - -import org.eclipse.jgit.http.server.HttpServerText; - -/** Indicates the request service is not enabled on a repository. */ -public class ServiceNotEnabledException extends Exception { - private static final long serialVersionUID = 1L; - - /** Indicates the request service is not available. */ - public ServiceNotEnabledException() { - super(HttpServerText.get().serviceNotEnabled); - } -} diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/UploadPackFactory.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/UploadPackFactory.java deleted file mode 100644 index 83bf9be07d..0000000000 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/UploadPackFactory.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2009-2010, Google Inc. - * and other copyright owners as documented in the project's IP log. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.eclipse.jgit.http.server.resolver; - -import javax.servlet.http.HttpServletRequest; - -import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.transport.UploadPack; - -/** Create and configure {@link UploadPack} service instance. */ -public interface UploadPackFactory { - /** A factory disabling the UploadPack service for all repositories. */ - public static final UploadPackFactory DISABLED = new UploadPackFactory() { - public UploadPack create(HttpServletRequest req, Repository db) - throws ServiceNotEnabledException { - throw new ServiceNotEnabledException(); - } - }; - - /** - * Create and configure a new UploadPack instance for a repository. - * - * @param req - * current HTTP request, in case information from the request may - * help configure the UploadPack instance. - * @param db - * the repository the upload would read from. - * @return the newly configured UploadPack instance, must not be null. - * @throws ServiceNotEnabledException - * this factory refuses to create the instance because it is not - * allowed on the target repository, by any user. - * @throws ServiceNotAuthorizedException - * this factory refuses to create the instance for this HTTP - * request and repository, such as due to a permission error. - */ - UploadPack create(HttpServletRequest req, Repository db) - throws ServiceNotEnabledException, ServiceNotAuthorizedException; -} diff --git a/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF index 4924eabb59..1b861d5f6d 100644 --- a/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF @@ -32,6 +32,7 @@ Import-Package: javax.servlet;version="[2.5.0,3.0.0)", org.eclipse.jgit.revwalk;version="[0.12.0,0.13.0)", org.eclipse.jgit.storage.file;version="[0.12.0,0.13.0)", org.eclipse.jgit.transport;version="[0.12.0,0.13.0)", + org.eclipse.jgit.transport.resolver;version="[0.12.0,0.13.0)", org.eclipse.jgit.util;version="[0.12.0,0.13.0)", org.eclipse.jgit.junit.http;version="[0.12.0,0.13.0)", org.junit;version="[4.0.0,5.0.0)", diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java index 4aa0919a1c..36c351841a 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java @@ -56,9 +56,6 @@ import org.eclipse.jgit.errors.RemoteRepositoryException; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.http.server.GitServlet; import org.eclipse.jgit.http.server.resolver.DefaultReceivePackFactory; -import org.eclipse.jgit.http.server.resolver.RepositoryResolver; -import org.eclipse.jgit.http.server.resolver.ServiceNotAuthorizedException; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.http.HttpTestCase; import org.eclipse.jgit.lib.Constants; @@ -73,6 +70,9 @@ import org.eclipse.jgit.transport.ReceivePack; import org.eclipse.jgit.transport.RemoteRefUpdate; import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.URIish; +import org.eclipse.jgit.transport.resolver.RepositoryResolver; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.junit.Before; import org.junit.Test; @@ -90,7 +90,7 @@ public class AdvertiseErrorTest extends HttpTestCase { ServletContextHandler app = server.addContext("/git"); GitServlet gs = new GitServlet(); - gs.setRepositoryResolver(new RepositoryResolver() { + gs.setRepositoryResolver(new RepositoryResolver() { public Repository open(HttpServletRequest req, String name) throws RepositoryNotFoundException, ServiceNotEnabledException { diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java index 6bdb4969f5..a86ae0930a 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java @@ -51,11 +51,11 @@ import javax.servlet.http.HttpServletRequestWrapper; import org.eclipse.jetty.server.Request; import org.eclipse.jgit.http.server.resolver.AsIsFileService; -import org.eclipse.jgit.http.server.resolver.ServiceNotAuthorizedException; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java index ff6c43d454..e35197ad42 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java @@ -54,14 +54,14 @@ import javax.servlet.http.HttpServletRequestWrapper; import org.eclipse.jetty.server.Request; import org.eclipse.jgit.http.server.resolver.DefaultReceivePackFactory; -import org.eclipse.jgit.http.server.resolver.ReceivePackFactory; -import org.eclipse.jgit.http.server.resolver.ServiceNotAuthorizedException; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.transport.ReceivePack; +import org.eclipse.jgit.transport.resolver.ReceivePackFactory; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java index def29dc027..38dc72fa33 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java @@ -53,13 +53,13 @@ import javax.servlet.http.HttpServletRequestWrapper; import org.eclipse.jetty.server.Request; import org.eclipse.jgit.http.server.resolver.DefaultUploadPackFactory; -import org.eclipse.jgit.http.server.resolver.ServiceNotAuthorizedException; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; -import org.eclipse.jgit.http.server.resolver.UploadPackFactory; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.transport.UploadPack; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; +import org.eclipse.jgit.transport.resolver.UploadPackFactory; import org.junit.Before; import org.junit.Test; diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java index 2347d06cff..b81cca1ca4 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java @@ -65,8 +65,6 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.http.server.GitServlet; -import org.eclipse.jgit.http.server.resolver.RepositoryResolver; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.http.AccessEvent; import org.eclipse.jgit.junit.http.HttpTestCase; @@ -81,6 +79,8 @@ import org.eclipse.jgit.transport.HttpTransport; import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.TransportHttp; import org.eclipse.jgit.transport.URIish; +import org.eclipse.jgit.transport.resolver.RepositoryResolver; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.junit.Before; import org.junit.Test; @@ -102,7 +102,7 @@ public class DumbClientSmartServerTest extends HttpTestCase { ServletContextHandler app = server.addContext("/git"); GitServlet gs = new GitServlet(); - gs.setRepositoryResolver(new RepositoryResolver() { + gs.setRepositoryResolver(new RepositoryResolver() { public Repository open(HttpServletRequest req, String name) throws RepositoryNotFoundException, ServiceNotEnabledException { diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/FileResolverTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/FileResolverTest.java index 7009cf98a3..f249098849 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/FileResolverTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/FileResolverTest.java @@ -53,10 +53,10 @@ import java.io.File; import java.io.IOException; import org.eclipse.jgit.errors.RepositoryNotFoundException; -import org.eclipse.jgit.http.server.resolver.FileResolver; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.transport.resolver.FileResolver; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.eclipse.jgit.util.FileUtils; import org.junit.Test; diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java index 31f4bb4357..2f56e42aa0 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java @@ -58,9 +58,6 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.http.server.GitServlet; import org.eclipse.jgit.http.server.resolver.DefaultReceivePackFactory; -import org.eclipse.jgit.http.server.resolver.RepositoryResolver; -import org.eclipse.jgit.http.server.resolver.ServiceNotAuthorizedException; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.http.AccessEvent; import org.eclipse.jgit.junit.http.HttpTestCase; @@ -79,6 +76,9 @@ import org.eclipse.jgit.transport.ReceivePack; import org.eclipse.jgit.transport.RemoteRefUpdate; import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.URIish; +import org.eclipse.jgit.transport.resolver.RepositoryResolver; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.junit.Before; import org.junit.Test; @@ -96,7 +96,7 @@ public class HookMessageTest extends HttpTestCase { ServletContextHandler app = server.addContext("/git"); GitServlet gs = new GitServlet(); - gs.setRepositoryResolver(new RepositoryResolver() { + gs.setRepositoryResolver(new RepositoryResolver() { public Repository open(HttpServletRequest req, String name) throws RepositoryNotFoundException, ServiceNotEnabledException { diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java index 063d9d4da6..c48d9b10fa 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java @@ -64,8 +64,6 @@ import org.eclipse.jgit.errors.NoRemoteRepositoryException; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.http.server.GitServlet; -import org.eclipse.jgit.http.server.resolver.RepositoryResolver; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.http.AccessEvent; import org.eclipse.jgit.junit.http.AppServer; @@ -81,6 +79,8 @@ import org.eclipse.jgit.transport.FetchConnection; import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; +import org.eclipse.jgit.transport.resolver.RepositoryResolver; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; public class HttpClientTests extends HttpTestCase { private TestRepository remoteRepository; @@ -127,7 +127,7 @@ public class HttpClientTests extends HttpTestCase { private ServletContextHandler smart(final String path) { GitServlet gs = new GitServlet(); - gs.setRepositoryResolver(new RepositoryResolver() { + gs.setRepositoryResolver(new RepositoryResolver() { public Repository open(HttpServletRequest req, String name) throws RepositoryNotFoundException, ServiceNotEnabledException { diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java index e764fe5424..209f161c9b 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java @@ -76,8 +76,6 @@ import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.http.server.GitServlet; -import org.eclipse.jgit.http.server.resolver.RepositoryResolver; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRng; import org.eclipse.jgit.junit.http.AccessEvent; @@ -98,6 +96,8 @@ import org.eclipse.jgit.transport.RemoteRefUpdate; import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.TransportHttp; import org.eclipse.jgit.transport.URIish; +import org.eclipse.jgit.transport.resolver.RepositoryResolver; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.junit.Before; import org.junit.Test; @@ -123,7 +123,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { ServletContextHandler app = server.addContext("/git"); GitServlet gs = new GitServlet(); - gs.setRepositoryResolver(new RepositoryResolver() { + gs.setRepositoryResolver(new RepositoryResolver() { public Repository open(HttpServletRequest req, String name) throws RepositoryNotFoundException, ServiceNotEnabledException { diff --git a/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF index 226a09a207..58324fc486 100644 --- a/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF @@ -30,5 +30,6 @@ Import-Package: javax.servlet;version="[2.5.0,3.0.0)", org.eclipse.jgit.revwalk;version="[0.12.0,0.13.0)", org.eclipse.jgit.storage.file;version="[0.12.0,0.13.0)", org.eclipse.jgit.transport;version="[0.12.0,0.13.0)", + org.eclipse.jgit.transport.resolver;version="[0.12.0,0.13.0)", org.junit;version="[4.0.0,5.0.0)" Export-Package: org.eclipse.jgit.junit.http;version="0.12.0" diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java index 987f2118ea..1221e1c887 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java @@ -52,11 +52,11 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.http.server.GitServlet; -import org.eclipse.jgit.http.server.resolver.RepositoryResolver; -import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.storage.file.FileRepository; import org.eclipse.jgit.transport.URIish; +import org.eclipse.jgit.transport.resolver.RepositoryResolver; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; /** * Simple http server for testing http access to Git repositories. @@ -92,7 +92,7 @@ public class SimpleHttpServer { private ServletContextHandler smart(final String path) { GitServlet gs = new GitServlet(); - gs.setRepositoryResolver(new RepositoryResolver() { + gs.setRepositoryResolver(new RepositoryResolver() { public Repository open(HttpServletRequest req, String name) throws RepositoryNotFoundException, ServiceNotEnabledException { diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF index af5937e3ff..f27bcf5fd9 100644 --- a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF @@ -21,6 +21,7 @@ Import-Package: org.eclipse.jgit.api;version="[0.12.0,0.13.0)", org.eclipse.jgit.storage.file;version="[0.12.0,0.13.0)", org.eclipse.jgit.storage.pack;version="[0.12.0,0.13.0)", org.eclipse.jgit.transport;version="[0.12.0,0.13.0)", + org.eclipse.jgit.transport.resolver;version="[0.12.0,0.13.0)", org.eclipse.jgit.treewalk;version="[0.12.0,0.13.0)", org.eclipse.jgit.treewalk.filter;version="[0.12.0,0.13.0)", org.eclipse.jgit.util;version="[0.12.0,0.13.0)", diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java index 3cca87abe8..9b637cdb31 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Daemon.java @@ -54,7 +54,9 @@ import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.storage.file.WindowCache; import org.eclipse.jgit.storage.file.WindowCacheConfig; import org.eclipse.jgit.storage.pack.PackConfig; +import org.eclipse.jgit.transport.DaemonClient; import org.eclipse.jgit.transport.DaemonService; +import org.eclipse.jgit.transport.resolver.FileResolver; import org.eclipse.jgit.util.FS; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -123,13 +125,19 @@ class Daemon extends TextBuiltin { if (1 < threads) packConfig.setExecutor(Executors.newFixedThreadPool(threads)); - final org.eclipse.jgit.transport.Daemon d; + final FileResolver resolver = new FileResolver(); + for (final File f : directory) { + out.println(MessageFormat.format(CLIText.get().exporting, f.getAbsolutePath())); + resolver.exportDirectory(f); + } + resolver.setExportAll(exportAll); + final org.eclipse.jgit.transport.Daemon d; d = new org.eclipse.jgit.transport.Daemon( host != null ? new InetSocketAddress(host, port) : new InetSocketAddress(port)); - d.setExportAll(exportAll); d.setPackConfig(packConfig); + d.setRepositoryResolver(resolver); if (0 <= timeout) d.setTimeout(timeout); @@ -143,10 +151,6 @@ class Daemon extends TextBuiltin { for (final String n : forbidOverride) service(d, n).setOverridable(false); - for (final File f : directory) { - out.println(MessageFormat.format(CLIText.get().exporting, f.getAbsolutePath())); - d.exportDirectory(f); - } d.start(); out.println(MessageFormat.format(CLIText.get().listeningOn, d.getAddress())); } diff --git a/org.eclipse.jgit/META-INF/MANIFEST.MF b/org.eclipse.jgit/META-INF/MANIFEST.MF index e3152606ca..9d1f957c53 100644 --- a/org.eclipse.jgit/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit/META-INF/MANIFEST.MF @@ -25,6 +25,7 @@ Export-Package: org.eclipse.jgit;version="0.12.0", org.eclipse.jgit.storage.file;version="0.12.0", org.eclipse.jgit.storage.pack;version="0.12.0", org.eclipse.jgit.transport;version="0.12.0", + org.eclipse.jgit.transport.resolver;version="0.12.0", org.eclipse.jgit.treewalk;version="0.12.0", org.eclipse.jgit.treewalk.filter;version="0.12.0", org.eclipse.jgit.util;version="0.12.0", diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties index 4681daa662..e48638397d 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties @@ -384,7 +384,9 @@ rewinding=Rewinding to commit {0} searchForReuse=Finding sources searchForSizes=Getting sizes sequenceTooLargeForDiffAlgorithm=Sequence too large for difference algorithm. +serviceNotEnabledNoName=Service not enabled serviceNotPermitted={0} not permitted +serviceNotPermittedNoName=Service not permitted shortCompressedStreamAt=Short compressed stream at {0} shortReadOfBlock=Short read of block. shortReadOfOptionalDIRCExtensionExpectedAnotherBytes=Short read of optional DIRC extension {0}; expected another {1} bytes within the section. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java index e29c9bc24e..7276dd26fb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java @@ -444,7 +444,9 @@ public class JGitText extends TranslationBundle { /***/ public String searchForReuse; /***/ public String searchForSizes; /***/ public String sequenceTooLargeForDiffAlgorithm; + /***/ public String serviceNotEnabledNoName; /***/ public String serviceNotPermitted; + /***/ public String serviceNotPermittedNoName; /***/ public String shortCompressedStreamAt; /***/ public String shortReadOfBlock; /***/ public String shortReadOfOptionalDIRCExtensionExpectedAnotherBytes; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java index 0bc5fb3a2b..feeabb2e61 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java @@ -43,28 +43,26 @@ package org.eclipse.jgit.transport; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InterruptedIOException; +import java.io.OutputStream; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketAddress; -import java.util.Collection; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; import org.eclipse.jgit.JGitText; -import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.lib.RepositoryCache; -import org.eclipse.jgit.lib.RepositoryCache.FileKey; import org.eclipse.jgit.storage.pack.PackConfig; -import org.eclipse.jgit.util.FS; +import org.eclipse.jgit.transport.resolver.ReceivePackFactory; +import org.eclipse.jgit.transport.resolver.RepositoryResolver; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; +import org.eclipse.jgit.transport.resolver.UploadPackFactory; /** Basic daemon for the anonymous git:// transport protocol. */ public class Daemon { @@ -79,12 +77,6 @@ public class Daemon { private final ThreadGroup processors; - private volatile boolean exportAll; - - private Map exports; - - private Collection exportBase; - private boolean run; private Thread acceptThread; @@ -93,6 +85,12 @@ public class Daemon { private PackConfig packConfig; + private volatile RepositoryResolver repositoryResolver; + + private volatile UploadPackFactory uploadPackFactory; + + private volatile ReceivePackFactory receivePackFactory; + /** Configure a daemon to listen on any available network port. */ public Daemon() { this(null); @@ -107,10 +105,40 @@ public class Daemon { */ public Daemon(final InetSocketAddress addr) { myAddress = addr; - exports = new ConcurrentHashMap(); - exportBase = new CopyOnWriteArrayList(); processors = new ThreadGroup("Git-Daemon"); + repositoryResolver = (RepositoryResolver) RepositoryResolver.NONE; + + uploadPackFactory = new UploadPackFactory() { + public UploadPack create(DaemonClient req, Repository db) + throws ServiceNotEnabledException, + ServiceNotAuthorizedException { + UploadPack up = new UploadPack(db); + up.setTimeout(getTimeout()); + up.setPackConfig(getPackConfig()); + return up; + } + }; + + receivePackFactory = new ReceivePackFactory() { + public ReceivePack create(DaemonClient req, Repository db) + throws ServiceNotEnabledException, + ServiceNotAuthorizedException { + ReceivePack rp = new ReceivePack(db); + + InetAddress peer = req.getRemoteAddress(); + String host = peer.getCanonicalHostName(); + if (host == null) + host = peer.getHostAddress(); + String name = "anonymous"; + String email = name + "@" + host; + rp.setRefLogIdent(new PersonIdent(name, email)); + rp.setTimeout(getTimeout()); + + return rp; + } + }; + services = new DaemonService[] { new DaemonService("upload-pack", "uploadpack") { { @@ -119,12 +147,13 @@ public class Daemon { @Override protected void execute(final DaemonClient dc, - final Repository db) throws IOException { - final UploadPack rp = new UploadPack(db); - final InputStream in = dc.getInputStream(); - rp.setTimeout(Daemon.this.getTimeout()); - rp.setPackConfig(Daemon.this.packConfig); - rp.upload(in, dc.getOutputStream(), null); + final Repository db) throws IOException, + ServiceNotEnabledException, + ServiceNotAuthorizedException { + UploadPack up = uploadPackFactory.create(dc, db); + InputStream in = dc.getInputStream(); + OutputStream out = dc.getOutputStream(); + up.upload(in, out, null); } }, new DaemonService("receive-pack", "receivepack") { { @@ -133,18 +162,13 @@ public class Daemon { @Override protected void execute(final DaemonClient dc, - final Repository db) throws IOException { - final InetAddress peer = dc.getRemoteAddress(); - String host = peer.getCanonicalHostName(); - if (host == null) - host = peer.getHostAddress(); - final ReceivePack rp = new ReceivePack(db); - final InputStream in = dc.getInputStream(); - final String name = "anonymous"; - final String email = name + "@" + host; - rp.setRefLogIdent(new PersonIdent(name, email)); - rp.setTimeout(Daemon.this.getTimeout()); - rp.receive(in, dc.getOutputStream(), null); + final Repository db) throws IOException, + ServiceNotEnabledException, + ServiceNotAuthorizedException { + ReceivePack rp = receivePackFactory.create(dc, db); + InputStream in = dc.getInputStream(); + OutputStream out = dc.getOutputStream(); + rp.receive(in, out, null); } } }; } @@ -173,62 +197,6 @@ public class Daemon { return null; } - /** - * @return false if git-daemon-export-ok is required to export - * a repository; true if git-daemon-export-ok is - * ignored. - * @see #setExportAll(boolean) - */ - public boolean isExportAll() { - return exportAll; - } - - /** - * Set whether or not to export all repositories. - *

- * If false (the default), repositories must have a - * git-daemon-export-ok file to be accessed through this - * daemon. - *

- * If true, all repositories are available through the daemon, whether or - * not git-daemon-export-ok exists. - * - * @param export - */ - public void setExportAll(final boolean export) { - exportAll = export; - } - - /** - * Add a single repository to the set that is exported by this daemon. - *

- * The existence (or lack-thereof) of git-daemon-export-ok is - * ignored by this method. The repository is always published. - * - * @param name - * name the repository will be published under. - * @param db - * the repository instance. - */ - public void exportRepository(String name, final Repository db) { - if (!name.endsWith(Constants.DOT_GIT_EXT)) - name = name + Constants.DOT_GIT_EXT; - exports.put(name, db); - RepositoryCache.register(db); - } - - /** - * Recursively export all Git repositories within a directory. - * - * @param dir - * the directory to export. This directory must not itself be a - * git repository, but any directory below it which has a file - * named git-daemon-export-ok will be published. - */ - public void exportDirectory(final File dir) { - exportBase.add(dir); - } - /** @return timeout (in seconds) before aborting an IO operation. */ public int getTimeout() { return timeout; @@ -246,6 +214,11 @@ public class Daemon { timeout = seconds; } + /** @return configuration controlling packing, may be null. */ + public PackConfig getPackConfig() { + return packConfig; + } + /** * Set the configuration used by the pack generator. * @@ -257,6 +230,44 @@ public class Daemon { this.packConfig = pc; } + /** + * Set the resolver used to locate a repository by name. + * + * @param resolver + * the resolver instance. + */ + public void setRepositoryResolver(RepositoryResolver resolver) { + repositoryResolver = resolver; + } + + /** + * Set the factory to construct and configure per-request UploadPack. + * + * @param factory + * the factory. If null upload-pack is disabled. + */ + @SuppressWarnings("unchecked") + public void setUploadPackFactory(UploadPackFactory factory) { + if (factory != null) + uploadPackFactory = factory; + else + uploadPackFactory = (UploadPackFactory) UploadPackFactory.DISABLED; + } + + /** + * Set the factory to construct and configure per-request ReceivePack. + * + * @param factory + * the factory. If null receive-pack is disabled. + */ + @SuppressWarnings("unchecked") + public void setReceivePackFactory(ReceivePackFactory factory) { + if (factory != null) + receivePackFactory = factory; + else + receivePackFactory = (ReceivePackFactory) ReceivePackFactory.DISABLED; + } + /** * Start this daemon on a background thread. * @@ -325,6 +336,12 @@ public class Daemon { public void run() { try { dc.execute(s); + } catch (RepositoryNotFoundException e) { + // Ignored. Client cannot use this repository. + } catch (ServiceNotEnabledException e) { + // Ignored. Client cannot use this repository. + } catch (ServiceNotAuthorizedException e) { + // Ignored. Client cannot use this repository. } catch (IOException e) { // Ignore unexpected IO exceptions from clients e.printStackTrace(); @@ -352,7 +369,7 @@ public class Daemon { return null; } - Repository openRepository(String name) { + Repository openRepository(DaemonClient client, String name) { // Assume any attempt to use \ was by a Windows client // and correct to the more typical / used in Git URIs. // @@ -363,48 +380,20 @@ public class Daemon { if (!name.startsWith("/")) return null; - // Forbid Windows UNC paths as they might escape the base - // - if (name.startsWith("//")) + try { + return repositoryResolver.open(client, name.substring(1)); + } catch (RepositoryNotFoundException e) { + // null signals it "wasn't found", which is all that is suitable + // for the remote client to know. return null; - - // Forbid funny paths which contain an up-reference, they - // might be trying to escape and read /../etc/password. - // - if (name.contains("/../")) + } catch (ServiceNotAuthorizedException e) { + // null signals it "wasn't found", which is all that is suitable + // for the remote client to know. return null; - name = name.substring(1); - - Repository db; - db = exports.get(name.endsWith(Constants.DOT_GIT_EXT) ? name : name - + Constants.DOT_GIT_EXT); - if (db != null) { - db.incrementOpen(); - return db; - } - - for (final File baseDir : exportBase) { - final File gitdir = FileKey.resolve(new File(baseDir, name), FS.DETECTED); - if (gitdir != null && canExport(gitdir)) - return openRepository(gitdir); - } - return null; - } - - private static Repository openRepository(final File gitdir) { - try { - return RepositoryCache.open(FileKey.exact(gitdir, FS.DETECTED)); - } catch (IOException err) { + } catch (ServiceNotEnabledException e) { // null signals it "wasn't found", which is all that is suitable // for the remote client to know. return null; } } - - private boolean canExport(final File d) { - if (isExportAll()) { - return true; - } - return new File(d, "git-daemon-export-ok").exists(); - } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java index 0b8de03439..23e3379f91 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java @@ -51,6 +51,9 @@ import java.io.OutputStream; import java.net.InetAddress; import java.net.Socket; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; + /** Active network client of {@link Daemon}. */ public class DaemonClient { private final Daemon daemon; @@ -89,8 +92,8 @@ public class DaemonClient { return rawOut; } - void execute(final Socket sock) - throws IOException { + void execute(final Socket sock) throws IOException, + ServiceNotEnabledException, ServiceNotAuthorizedException { rawIn = new BufferedInputStream(sock.getInputStream()); rawOut = new BufferedOutputStream(sock.getOutputStream()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java index 2b94957983..e88b4abb7a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java @@ -49,6 +49,8 @@ import java.io.IOException; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Config.SectionParser; +import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; +import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; /** A service exposed by {@link Daemon} over anonymous git://. */ public abstract class DaemonService { @@ -125,9 +127,10 @@ public abstract class DaemonService { } void execute(final DaemonClient client, final String commandLine) - throws IOException { + throws IOException, ServiceNotEnabledException, + ServiceNotAuthorizedException { final String name = commandLine.substring(command.length() + 1); - final Repository db = client.getDaemon().openRepository(name); + Repository db = client.getDaemon().openRepository(client, name); if (db == null) return; try { @@ -145,5 +148,6 @@ public abstract class DaemonService { } abstract void execute(DaemonClient client, Repository db) - throws IOException; + throws IOException, ServiceNotEnabledException, + ServiceNotAuthorizedException; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/FileResolver.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/FileResolver.java new file mode 100644 index 0000000000..1d4f2beb18 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/FileResolver.java @@ -0,0 +1,256 @@ +/* + * Copyright (C) 2009-2010, Google Inc. + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.eclipse.jgit.transport.resolver; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.eclipse.jgit.errors.RepositoryNotFoundException; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.RepositoryCache; +import org.eclipse.jgit.lib.RepositoryCache.FileKey; +import org.eclipse.jgit.util.FS; + +/** + * Default resolver serving from the local filesystem. + * + * @param + * type of connection + */ +public class FileResolver implements RepositoryResolver { + private volatile boolean exportAll; + + private final Map exports; + + private final Collection exportBase; + + /** Initialize an empty file based resolver. */ + public FileResolver() { + exports = new ConcurrentHashMap(); + exportBase = new CopyOnWriteArrayList(); + } + + /** + * Create a new resolver for the given path. + * + * @param basePath + * the base path all repositories are rooted under. + * @param exportAll + * if true, exports all repositories, ignoring the check for the + * {@code git-daemon-export-ok} files. + */ + public FileResolver(final File basePath, final boolean exportAll) { + this(); + exportDirectory(basePath); + setExportAll(exportAll); + } + + public Repository open(final C req, final String name) + throws RepositoryNotFoundException, ServiceNotEnabledException { + if (isUnreasonableName(name)) + throw new RepositoryNotFoundException(name); + + Repository db = exports.get(nameWithDotGit(name)); + if (db != null) { + db.incrementOpen(); + return db; + } + + for (File base : exportBase) { + File dir = FileKey.resolve(new File(base, name), FS.DETECTED); + if (dir == null) + continue; + + try { + FileKey key = FileKey.exact(dir, FS.DETECTED); + db = RepositoryCache.open(key, true); + } catch (IOException e) { + throw new RepositoryNotFoundException(name, e); + } + + try { + if (isExportOk(req, name, db)) { + // We have to leak the open count to the caller, they + // are responsible for closing the repository if we + // complete successfully. + return db; + } else + throw new ServiceNotEnabledException(); + + } catch (RuntimeException e) { + db.close(); + throw new RepositoryNotFoundException(name, e); + + } catch (IOException e) { + db.close(); + throw new RepositoryNotFoundException(name, e); + + } catch (ServiceNotEnabledException e) { + db.close(); + throw e; + } + } + + if (exportBase.size() == 1) { + File dir = new File(exportBase.iterator().next(), name); + throw new RepositoryNotFoundException(name, + new RepositoryNotFoundException(dir)); + } + + throw new RepositoryNotFoundException(name); + } + + /** + * @return false if git-daemon-export-ok is required to export + * a repository; true if git-daemon-export-ok is + * ignored. + * @see #setExportAll(boolean) + */ + public boolean isExportAll() { + return exportAll; + } + + /** + * Set whether or not to export all repositories. + *

+ * If false (the default), repositories must have a + * git-daemon-export-ok file to be accessed through this + * daemon. + *

+ * If true, all repositories are available through the daemon, whether or + * not git-daemon-export-ok exists. + * + * @param export + */ + public void setExportAll(final boolean export) { + exportAll = export; + } + + /** + * Add a single repository to the set that is exported by this daemon. + *

+ * The existence (or lack-thereof) of git-daemon-export-ok is + * ignored by this method. The repository is always published. + * + * @param name + * name the repository will be published under. + * @param db + * the repository instance. + */ + public void exportRepository(String name, Repository db) { + exports.put(nameWithDotGit(name), db); + } + + /** + * Recursively export all Git repositories within a directory. + * + * @param dir + * the directory to export. This directory must not itself be a + * git repository, but any directory below it which has a file + * named git-daemon-export-ok will be published. + */ + public void exportDirectory(final File dir) { + exportBase.add(dir); + } + + /** + * Check if this repository can be served. + *

+ * The default implementation of this method returns true only if either + * {@link #isExportAll()} is true, or the {@code git-daemon-export-ok} file + * is present in the repository's directory. + * + * @param req + * the current HTTP request. + * @param repositoryName + * name of the repository, as present in the URL. + * @param db + * the opened repository instance. + * @return true if the repository is accessible; false if not. + * @throws IOException + * the repository could not be accessed, the caller will claim + * the repository does not exist. + */ + protected boolean isExportOk(C req, String repositoryName, Repository db) + throws IOException { + if (isExportAll()) + return true; + else if (db.getDirectory() != null) + return new File(db.getDirectory(), "git-daemon-export-ok").exists(); + else + return false; + } + + private static String nameWithDotGit(String name) { + if (name.endsWith(Constants.DOT_GIT_EXT)) + return name; + return name + Constants.DOT_GIT_EXT; + } + + private static boolean isUnreasonableName(final String name) { + if (name.length() == 0) + return true; // no empty paths + + if (name.indexOf('\\') >= 0) + return true; // no windows/dos style paths + if (new File(name).isAbsolute()) + return true; // no absolute paths + + if (name.startsWith("../")) + return true; // no "l../etc/passwd" + if (name.contains("/../")) + return true; // no "foo/../etc/passwd" + if (name.contains("/./")) + return true; // "foo/./foo" is insane to ask + if (name.contains("//")) + return true; // double slashes is sloppy, don't use it + + return false; // is a reasonable name + } +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/ReceivePackFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/ReceivePackFactory.java new file mode 100644 index 0000000000..4cf49f5531 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/ReceivePackFactory.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2009-2010, Google Inc. + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.eclipse.jgit.transport.resolver; + +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.transport.ReceivePack; + +/** + * Create and configure {@link ReceivePack} service instance. + * + * @param + * type of connection + */ +public interface ReceivePackFactory { + /** A factory disabling the ReceivePack service for all repositories */ + public static final ReceivePackFactory DISABLED = new ReceivePackFactory() { + public ReceivePack create(Object req, Repository db) + throws ServiceNotEnabledException { + throw new ServiceNotEnabledException(); + } + }; + + /** + * Create and configure a new ReceivePack instance for a repository. + * + * @param req + * current request, in case information from the request may help + * configure the ReceivePack instance. + * @param db + * the repository the receive would write into. + * @return the newly configured ReceivePack instance, must not be null. + * @throws ServiceNotEnabledException + * this factory refuses to create the instance because it is not + * allowed on the target repository, by any user. + * @throws ServiceNotAuthorizedException + * this factory refuses to create the instance for this HTTP + * request and repository, such as due to a permission error. + */ + ReceivePack create(C req, Repository db) throws ServiceNotEnabledException, + ServiceNotAuthorizedException; +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/RepositoryResolver.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/RepositoryResolver.java new file mode 100644 index 0000000000..b2354193e1 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/RepositoryResolver.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2009-2010, Google Inc. + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.eclipse.jgit.transport.resolver; + +import org.eclipse.jgit.errors.RepositoryNotFoundException; +import org.eclipse.jgit.lib.Repository; + +/** + * Locate a Git {@link Repository} by name from the URL. + * + * @param + * type of connection. + */ +public interface RepositoryResolver { + /** Resolver configured to open nothing. */ + public static final RepositoryResolver NONE = new RepositoryResolver() { + public Repository open(Object req, String name) + throws RepositoryNotFoundException { + throw new RepositoryNotFoundException(name); + } + }; + + /** + * Locate and open a reference to a {@link Repository}. + *

+ * The caller is responsible for closing the returned Repository. + * + * @param req + * the current request, may be used to inspect session state + * including cookies or user authentication. + * @param name + * name of the repository, as parsed out of the URL. + * @return the opened repository instance, never null. + * @throws RepositoryNotFoundException + * the repository does not exist or the name is incorrectly + * formatted as a repository name. + * @throws ServiceNotAuthorizedException + * the repository exists, but HTTP access is not allowed for the + * current user. + * @throws ServiceNotEnabledException + * the repository exists, but HTTP access is not allowed on the + * target repository, by any user. + */ + Repository open(C req, String name) throws RepositoryNotFoundException, + ServiceNotAuthorizedException, ServiceNotEnabledException; +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/ServiceNotAuthorizedException.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/ServiceNotAuthorizedException.java new file mode 100644 index 0000000000..3e2047b085 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/ServiceNotAuthorizedException.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2009-2010, Google Inc. + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.eclipse.jgit.transport.resolver; + +import org.eclipse.jgit.JGitText; + +/** Indicates the request service is not authorized for current user. */ +public class ServiceNotAuthorizedException extends Exception { + private static final long serialVersionUID = 1L; + + /** Indicates the request service is not available. */ + public ServiceNotAuthorizedException() { + super(JGitText.get().serviceNotPermittedNoName); + } +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/ServiceNotEnabledException.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/ServiceNotEnabledException.java new file mode 100644 index 0000000000..ac607f9b0e --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/ServiceNotEnabledException.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2009-2010, Google Inc. + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.eclipse.jgit.transport.resolver; + +import org.eclipse.jgit.JGitText; + +/** Indicates the request service is not enabled on a repository. */ +public class ServiceNotEnabledException extends Exception { + private static final long serialVersionUID = 1L; + + /** Indicates the request service is not available. */ + public ServiceNotEnabledException() { + super(JGitText.get().serviceNotEnabledNoName); + } +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/UploadPackFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/UploadPackFactory.java new file mode 100644 index 0000000000..f0d2ba865b --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/UploadPackFactory.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2009-2010, Google Inc. + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.eclipse.jgit.transport.resolver; + +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.transport.UploadPack; + +/** + * Create and configure {@link UploadPack} service instance. + * + * @param + * the connection type + */ +public interface UploadPackFactory { + /** A factory disabling the UploadPack service for all repositories. */ + public static final UploadPackFactory DISABLED = new UploadPackFactory() { + public UploadPack create(Object req, Repository db) + throws ServiceNotEnabledException { + throw new ServiceNotEnabledException(); + } + }; + + /** + * Create and configure a new UploadPack instance for a repository. + * + * @param req + * current request, in case information from the request may help + * configure the UploadPack instance. + * @param db + * the repository the upload would read from. + * @return the newly configured UploadPack instance, must not be null. + * @throws ServiceNotEnabledException + * this factory refuses to create the instance because it is not + * allowed on the target repository, by any user. + * @throws ServiceNotAuthorizedException + * this factory refuses to create the instance for this HTTP + * request and repository, such as due to a permission error. + */ + UploadPack create(C req, Repository db) throws ServiceNotEnabledException, + ServiceNotAuthorizedException; +} -- cgit v1.2.3