Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce2011-02-07 00:38:02 +0000
committerShawn O. Pearce2011-02-15 02:28:21 +0000
commit1b7a5a29600e9711548bed267b61e198a058f50b (patch)
treec9fa99c9707e2a0737f1794f86078b554bf55702 /org.eclipse.jgit.http.server
parent8235b88a4bb453b6bf5dbfbb6f12f25d3c23793e (diff)
downloadjgit-1b7a5a29600e9711548bed267b61e198a058f50b.tar.gz
jgit-1b7a5a29600e9711548bed267b61e198a058f50b.tar.xz
jgit-1b7a5a29600e9711548bed267b61e198a058f50b.zip
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 <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.http.server')
-rw-r--r--org.eclipse.jgit.http.server/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.jgit.http.server/resources/org/eclipse/jgit/http/server/HttpServerText.properties2
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/AsIsFileFilter.java4
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitServlet.java29
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/HttpServerText.java2
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java6
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java6
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java4
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java6
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/AsIsFileService.java2
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java6
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java6
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/FileResolver.java167
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ReceivePackFactory.java79
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/RepositoryResolver.java77
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotAuthorizedException.java56
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/ServiceNotEnabledException.java56
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/UploadPackFactory.java79
18 files changed, 42 insertions, 546 deletions
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<HttpServletRequest> resolver;
private AsIsFileService asIs = new AsIsFileService();
- private UploadPackFactory uploadPackFactory = new DefaultUploadPackFactory();
+ private UploadPackFactory<HttpServletRequest> uploadPackFactory = new DefaultUploadPackFactory();
- private ReceivePackFactory receivePackFactory = new DefaultReceivePackFactory();
+ private ReceivePackFactory<HttpServletRequest> 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<HttpServletRequest> 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<HttpServletRequest> f) {
assertNotInitialized();
- this.uploadPackFactory = f != null ? f : UploadPackFactory.DISABLED;
+ this.uploadPackFactory = f != null ? f : (UploadPackFactory<HttpServletRequest>)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<HttpServletRequest> f) {
assertNotInitialized();
- this.receivePackFactory = f != null ? f : ReceivePackFactory.DISABLED;
+ this.receivePackFactory = f != null ? f : (ReceivePackFactory<HttpServletRequest>)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<HttpServletRequest>(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;
* </ul>
* and explicitly rejected otherwise.
*/
-public class DefaultReceivePackFactory implements ReceivePackFactory {
+public class DefaultReceivePackFactory implements
+ ReceivePackFactory<HttpServletRequest> {
private static final SectionParser<ServiceConfig> CONFIG = new SectionParser<ServiceConfig>() {
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<HttpServletRequest> {
private static final SectionParser<ServiceConfig> CONFIG = new SectionParser<ServiceConfig>() {
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.
- * <p>
- * 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}.
- * <p>
- * 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;
-}

Back to the top