diff --git a/plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitCGIServlet.java b/plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitCGIServlet.java new file mode 100644 index 0000000000..c2f06eddac --- /dev/null +++ b/plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitCGIServlet.java @@ -0,0 +1,80 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + + + +package sonia.scm.web; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.inject.Singleton; + +import sonia.scm.web.cgi.AbstractCGIServlet; +import sonia.scm.web.cgi.EnvList; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; + +/** + * + * @author Sebastian Sdorra + */ +@Singleton +public class GitCGIServlet extends AbstractCGIServlet +{ + + /** Field description */ + public static final String ENV_HTTP_EXPORT_ALL = "GIT_HTTP_EXPORT_ALL"; + + /** Field description */ + public static final String ENV_PROJECT_ROOT = "GIT_PROJECT_ROOT"; + + /** Field description */ + private static final long serialVersionUID = 9147517765161830847L; + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @Override + protected EnvList createEnvironment() + { + EnvList list = super.createEnvironment(); + + list.set(ENV_PROJECT_ROOT, "/tmp/git"); + list.set(ENV_HTTP_EXPORT_ALL, ""); + + return list; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param req + * + * @return + * + * @throws IOException + * @throws ServletException + */ + @Override + protected File getCommand(HttpServletRequest req) + throws ServletException, IOException + { + return new File("/opt/local/libexec/git-core/git-http-backend/"); + } +} diff --git a/plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitWebPlugin.java b/plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitWebPlugin.java index d55a202a31..c7eb3113cf 100644 --- a/plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitWebPlugin.java +++ b/plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitWebPlugin.java @@ -7,6 +7,12 @@ package sonia.scm.web; +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.inject.servlet.ServletModule; + +import sonia.scm.web.filter.BasicAuthenticationFilter; + /** * * @author Sebastian Sdorra @@ -14,8 +20,11 @@ package sonia.scm.web; public class GitWebPlugin implements ScmWebPlugin { + /** Field description */ public static final String SCRIPT = "/sonia/scm/git.config.js"; + //~--- methods -------------------------------------------------------------- + /** * Method description * @@ -38,7 +47,15 @@ public class GitWebPlugin implements ScmWebPlugin @Override public void contextInitialized(ScmWebPluginContext context) { - context.addScriptResource( new ClasspathWebResource(SCRIPT) ); - + context.addScriptResource(new ClasspathWebResource(SCRIPT)); + context.addInjectModule(new ServletModule() + { + @Override + protected void configureServlets() + { + filter("/git/*").through(BasicAuthenticationFilter.class); + serve("/git/*").with(GitCGIServlet.class); + } + }); } }