mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-01 11:05:56 +01:00
Add POC protocol servlet with delegate to svn and hg
This commit is contained in:
@@ -28,7 +28,8 @@ public abstract class InitializingHttpScmProtocolWrapper implements HttpScmProto
|
||||
if (!isInitialized) {
|
||||
synchronized (this) {
|
||||
if (!isInitialized) {
|
||||
delegateProvider.get().init(config);
|
||||
HttpServlet httpServlet = delegateProvider.get();
|
||||
httpServlet.init(config);
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.Command;
|
||||
import sonia.scm.repository.api.ScmProtocol;
|
||||
import sonia.scm.web.HgCGIServlet;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -87,16 +86,17 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param hookManager
|
||||
* @param handler
|
||||
* @param hookManager
|
||||
* @param repository
|
||||
* @param httpScmProtocol
|
||||
*/
|
||||
HgRepositoryServiceProvider(HgRepositoryHandler handler,
|
||||
HgHookManager hookManager, Repository repository)
|
||||
HgHookManager hookManager, Repository repository, HttpScmProtocol httpScmProtocol)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.handler = handler;
|
||||
this.httpScmProtocol = httpScmProtocol;
|
||||
this.repositoryDirectory = handler.getDirectory(repository);
|
||||
this.context = new HgCommandContext(hookManager, handler, repository,
|
||||
repositoryDirectory);
|
||||
@@ -276,7 +276,7 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider
|
||||
|
||||
@Override
|
||||
public Set<ScmProtocol> getSupportedProtocols() {
|
||||
return Collections.singleton(new HgCGIServlet(null, null, null, null, null, null));
|
||||
return Collections.singleton(httpScmProtocol);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
@@ -292,4 +292,6 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider
|
||||
|
||||
/** Field description */
|
||||
private File repositoryDirectory;
|
||||
|
||||
private final HttpScmProtocol httpScmProtocol;
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ package sonia.scm.repository.spi;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.HgHookManager;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.web.HgScmProtocolProviderWrapper;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -65,10 +65,11 @@ public class HgRepositoryServiceResolver implements RepositoryServiceResolver
|
||||
*/
|
||||
@Inject
|
||||
public HgRepositoryServiceResolver(HgRepositoryHandler handler,
|
||||
HgHookManager hookManager)
|
||||
HgHookManager hookManager, HgScmProtocolProviderWrapper httpScmProtocol)
|
||||
{
|
||||
this.handler = handler;
|
||||
this.hookManager = hookManager;
|
||||
this.httpScmProtocol = httpScmProtocol;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -89,7 +90,7 @@ public class HgRepositoryServiceResolver implements RepositoryServiceResolver
|
||||
if (TYPE.equalsIgnoreCase(repository.getType()))
|
||||
{
|
||||
provider = new HgRepositoryServiceProvider(handler, hookManager,
|
||||
repository);
|
||||
repository, httpScmProtocol);
|
||||
}
|
||||
|
||||
return provider;
|
||||
@@ -102,4 +103,6 @@ public class HgRepositoryServiceResolver implements RepositoryServiceResolver
|
||||
|
||||
/** Field description */
|
||||
private HgHookManager hookManager;
|
||||
|
||||
private final HttpScmProtocol httpScmProtocol;
|
||||
}
|
||||
|
||||
@@ -135,19 +135,6 @@ public class HgCGIServlet extends HttpServlet implements HttpScmProtocol
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws ServletException
|
||||
*/
|
||||
@Override
|
||||
public void init() throws ServletException
|
||||
{
|
||||
|
||||
super.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -37,27 +37,22 @@ package sonia.scm.web;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import sonia.scm.Priority;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.filter.Filters;
|
||||
import sonia.scm.filter.WebElement;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
import sonia.scm.web.filter.ProviderPermissionFilter;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Permission filter for mercurial repositories.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Priority(Filters.PRIORITY_AUTHORIZATION)
|
||||
@WebElement(value = HgServletModule.MAPPING_HG)
|
||||
//@Priority(Filters.PRIORITY_AUTHORIZATION)
|
||||
//@WebElement(value = HgServletModule.MAPPING_HG)
|
||||
public class HgPermissionFilter extends ProviderPermissionFilter
|
||||
{
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import sonia.scm.repository.spi.InitializingHttpScmProtocolWrapper;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class HgScmProtocolProviderWrapper extends InitializingHttpScmProtocolWrapper {
|
||||
@Inject
|
||||
public HgScmProtocolProviderWrapper(Provider<HgCGIServlet> servletProvider) {
|
||||
super(servletProvider);
|
||||
}
|
||||
}
|
||||
@@ -81,8 +81,5 @@ public class HgServletModule extends ServletModule
|
||||
|
||||
// bind servlets
|
||||
serve(MAPPING_HOOK).with(HgHookCallbackServlet.class);
|
||||
|
||||
// register hg cgi servlet
|
||||
serve(MAPPING_HG).with(HgCGIServlet.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.SvnRepositoryHandler;
|
||||
import sonia.scm.repository.api.Command;
|
||||
import sonia.scm.repository.api.ScmProtocol;
|
||||
import sonia.scm.web.SvnDAVServlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
@@ -69,14 +68,15 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
* @param repository
|
||||
* @param httpScmProtocol
|
||||
*/
|
||||
SvnRepositoryServiceProvider(SvnRepositoryHandler handler,
|
||||
Repository repository)
|
||||
Repository repository, HttpScmProtocol httpScmProtocol)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.httpScmProtocol = httpScmProtocol;
|
||||
this.context = new SvnContext(handler.getDirectory(repository));
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider
|
||||
|
||||
@Override
|
||||
public Set<ScmProtocol> getSupportedProtocols() {
|
||||
return Collections.singleton(new SvnDAVServlet(null, null, null, null));
|
||||
return Collections.singleton(httpScmProtocol);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
@@ -204,4 +204,6 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider
|
||||
|
||||
/** Field description */
|
||||
private final Repository repository;
|
||||
|
||||
private final HttpScmProtocol httpScmProtocol;
|
||||
}
|
||||
|
||||
@@ -35,10 +35,10 @@ package sonia.scm.repository.spi;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.SvnRepositoryHandler;
|
||||
import sonia.scm.web.SvnScmProtocolProviderWrapper;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -58,11 +58,13 @@ public class SvnRepositoryServiceResolver implements RepositoryServiceResolver
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
* @param httpScmProtocol
|
||||
*/
|
||||
@Inject
|
||||
public SvnRepositoryServiceResolver(SvnRepositoryHandler handler)
|
||||
public SvnRepositoryServiceResolver(SvnRepositoryHandler handler, SvnScmProtocolProviderWrapper httpScmProtocol)
|
||||
{
|
||||
this.handler = handler;
|
||||
this.httpScmProtocol = httpScmProtocol;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -82,7 +84,7 @@ public class SvnRepositoryServiceResolver implements RepositoryServiceResolver
|
||||
|
||||
if (TYPE.equalsIgnoreCase(repository.getType()))
|
||||
{
|
||||
provider = new SvnRepositoryServiceProvider(handler, repository);
|
||||
provider = new SvnRepositoryServiceProvider(handler, repository, httpScmProtocol);
|
||||
}
|
||||
|
||||
return provider;
|
||||
@@ -92,4 +94,6 @@ public class SvnRepositoryServiceResolver implements RepositoryServiceResolver
|
||||
|
||||
/** Field description */
|
||||
private SvnRepositoryHandler handler;
|
||||
|
||||
private final HttpScmProtocol httpScmProtocol;
|
||||
}
|
||||
|
||||
@@ -34,30 +34,24 @@ package sonia.scm.web;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import sonia.scm.Priority;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.filter.Filters;
|
||||
import sonia.scm.filter.WebElement;
|
||||
import sonia.scm.repository.SvnUtil;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.web.filter.AuthenticationFilter;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Priority(Filters.PRIORITY_AUTHENTICATION)
|
||||
@WebElement(value = SvnServletModule.PATTERN_SVN)
|
||||
//@Priority(Filters.PRIORITY_AUTHENTICATION)
|
||||
//@WebElement(value = SvnServletModule.PATTERN_SVN)
|
||||
public class SvnBasicAuthenticationFilter extends AuthenticationFilter
|
||||
{
|
||||
|
||||
|
||||
@@ -37,32 +37,26 @@ package sonia.scm.web;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import sonia.scm.ClientMessages;
|
||||
import sonia.scm.Priority;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.filter.Filters;
|
||||
import sonia.scm.filter.WebElement;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
import sonia.scm.repository.ScmSvnErrorCode;
|
||||
import sonia.scm.repository.SvnUtil;
|
||||
import sonia.scm.web.filter.ProviderPermissionFilter;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Priority(Filters.PRIORITY_AUTHORIZATION)
|
||||
@WebElement(value = SvnServletModule.PATTERN_SVN)
|
||||
//@Priority(Filters.PRIORITY_AUTHORIZATION)
|
||||
//@WebElement(value = SvnServletModule.PATTERN_SVN)
|
||||
public class SvnPermissionFilter extends ProviderPermissionFilter
|
||||
{
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import sonia.scm.repository.spi.InitializingHttpScmProtocolWrapper;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class SvnScmProtocolProviderWrapper extends InitializingHttpScmProtocolWrapper {
|
||||
@Inject
|
||||
public SvnScmProtocolProviderWrapper(Provider<SvnDAVServlet> servletProvider) {
|
||||
super(servletProvider);
|
||||
}
|
||||
}
|
||||
@@ -70,8 +70,8 @@ public class SvnServletModule extends ServletModule
|
||||
protected void configureServlets()
|
||||
{
|
||||
filter(PATTERN_SVN).through(SvnGZipFilter.class);
|
||||
filter(PATTERN_SVN).through(SvnBasicAuthenticationFilter.class);
|
||||
filter(PATTERN_SVN).through(SvnPermissionFilter.class);
|
||||
// filter(PATTERN_SVN).through(SvnBasicAuthenticationFilter.class);
|
||||
// filter(PATTERN_SVN).through(SvnPermissionFilter.class);
|
||||
|
||||
bind(SvnConfigDtoToSvnConfigMapper.class).to(Mappers.getMapper(SvnConfigDtoToSvnConfigMapper.class).getClass());
|
||||
bind(SvnConfigToSvnConfigDtoMapper.class).to(Mappers.getMapper(SvnConfigToSvnConfigDtoMapper.class).getClass());
|
||||
@@ -80,6 +80,5 @@ public class SvnServletModule extends ServletModule
|
||||
|
||||
parameters.put(PARAMETER_SVN_PARENTPATH,
|
||||
System.getProperty("java.io.tmpdir"));
|
||||
serve(PATTERN_SVN).with(SvnDAVServlet.class, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
@Singleton
|
||||
@WebElement(value = HttpProtocolServlet.PATTERN)
|
||||
@Slf4j
|
||||
@@ -79,7 +81,8 @@ public class HttpProtocolServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
String namespace = uri.substring(0, uri.indexOf(HttpUtil.SEPARATOR_PATH));
|
||||
String name = uri.substring(uri.indexOf(HttpUtil.SEPARATOR_PATH) + 1, uri.indexOf(HttpUtil.SEPARATOR_PATH, uri.indexOf(HttpUtil.SEPARATOR_PATH) + 1));
|
||||
int endIndex = uri.indexOf(HttpUtil.SEPARATOR_PATH, uri.indexOf(HttpUtil.SEPARATOR_PATH) + 1);
|
||||
String name = uri.substring(uri.indexOf(HttpUtil.SEPARATOR_PATH) + 1, max(endIndex, uri.length()));
|
||||
|
||||
return new NamespaceAndName(namespace, name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user