Cleanup for http protocol servlet changes

This commit is contained in:
René Pfeuffer
2018-09-11 10:50:53 +02:00
parent bf9de8ea8e
commit e90dc11bc7
27 changed files with 32 additions and 596 deletions

View File

@@ -33,8 +33,6 @@
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Closeables;
import sonia.scm.repository.Repository;
@@ -46,8 +44,6 @@ import java.io.IOException;
import java.util.Collections;
import java.util.Set;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra

View File

@@ -32,67 +32,34 @@
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;
/**
*
* @author Sebastian Sdorra
*/
@Extension
public class SvnRepositoryServiceResolver implements RepositoryServiceResolver
{
public class SvnRepositoryServiceResolver implements RepositoryServiceResolver {
/** Field description */
public static final String TYPE = "svn";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param handler
* @param protocolWrapper
*/
@Inject
public SvnRepositoryServiceResolver(SvnRepositoryHandler handler, SvnScmProtocolProviderWrapper protocolWrapper)
{
public SvnRepositoryServiceResolver(SvnRepositoryHandler handler, SvnScmProtocolProviderWrapper protocolWrapper) {
this.handler = handler;
this.protocolWrapper = protocolWrapper;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param repository
*
* @return
*/
@Override
public SvnRepositoryServiceProvider resolve(Repository repository)
{
public SvnRepositoryServiceProvider resolve(Repository repository) {
SvnRepositoryServiceProvider provider = null;
if (TYPE.equalsIgnoreCase(repository.getType()))
{
if (TYPE.equalsIgnoreCase(repository.getType())) {
provider = new SvnRepositoryServiceProvider(handler, repository, protocolWrapper.get(repository));
}
return provider;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private SvnRepositoryHandler handler;
private final InitializingHttpScmProtocolWrapper protocolWrapper;

View File

@@ -1,96 +0,0 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. 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. 3. Neither the name of SCM-Manager;
* 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 REGENTS 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.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.repository.SvnUtil;
import sonia.scm.util.HttpUtil;
import sonia.scm.web.filter.AuthenticationFilter;
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)
public class SvnBasicAuthenticationFilter extends AuthenticationFilter
{
/**
* Constructs ...
*
*
* @param configuration
* @param webTokenGenerators
*/
@Inject
public SvnBasicAuthenticationFilter(ScmConfiguration configuration, Set<WebTokenGenerator> webTokenGenerators) {
super(configuration, webTokenGenerators);
}
//~--- methods --------------------------------------------------------------
/**
* Sends unauthorized instead of forbidden for svn clients, because the
* svn client prompts again for authentication.
*
*
* @param request http request
* @param response http response
*
* @throws IOException
*/
@Override
protected void sendFailedAuthenticationError(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
if (SvnUtil.isSvnClient(request))
{
HttpUtil.sendUnauthorized(response, configuration.getRealmDescription());
}
else
{
super.sendFailedAuthenticationError(request, response);
}
}
}

View File

@@ -33,8 +33,6 @@
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.slf4j.Logger;
@@ -55,8 +53,6 @@ import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra

View File

@@ -33,30 +33,24 @@
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import sonia.scm.ClientMessages;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.repository.ScmSvnErrorCode;
import sonia.scm.repository.SvnUtil;
import sonia.scm.web.filter.ProviderPermissionFilter;
import sonia.scm.web.filter.PermissionFilter;
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)
public class SvnPermissionFilter extends ProviderPermissionFilter
public class SvnPermissionFilter extends PermissionFilter
{
/** Field description */

View File

@@ -12,10 +12,11 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.util.Enumeration;
import static sonia.scm.web.SvnServletModule.PARAMETER_SVN_PARENTPATH;
@Singleton
public class SvnScmProtocolProviderWrapper extends InitializingHttpScmProtocolWrapper {
public static final String PARAMETER_SVN_PARENTPATH = "SVNParentPath";
@Inject
public SvnScmProtocolProviderWrapper(Provider<SvnDAVServlet> servletProvider, Provider<SvnPermissionFilter> permissionFilter, Provider<UriInfoStore> uriInfoStore) {
super(servletProvider, permissionFilter, uriInfoStore);
@@ -24,14 +25,14 @@ public class SvnScmProtocolProviderWrapper extends InitializingHttpScmProtocolWr
@Override
protected void initializeServlet(ServletConfig config, ScmProviderHttpServlet httpServlet) throws ServletException {
super.initializeServlet(new X(config), httpServlet);
super.initializeServlet(new SvnConfigEnhancer(config), httpServlet);
}
private static class X implements ServletConfig {
private static class SvnConfigEnhancer implements ServletConfig {
private final ServletConfig originalConfig;
private X(ServletConfig originalConfig) {
private SvnConfigEnhancer(ServletConfig originalConfig) {
this.originalConfig = originalConfig;
}

View File

@@ -33,43 +33,21 @@
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.servlet.ServletModule;
import org.mapstruct.factory.Mappers;
import sonia.scm.api.v2.resources.SvnConfigDtoToSvnConfigMapper;
import sonia.scm.api.v2.resources.SvnConfigToSvnConfigDtoMapper;
import sonia.scm.plugin.Extension;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra
*/
@Extension
public class SvnServletModule extends ServletModule
{
public class SvnServletModule extends ServletModule {
/** Field description */
public static final String PARAMETER_SVN_PARENTPATH = "SVNParentPath";
/** Field description */
public static final String PATTERN_SVN = "/svn/*";
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*/
@Override
protected void configureServlets()
{
filter(PATTERN_SVN).through(SvnGZipFilter.class);
// filter(PATTERN_SVN).through(SvnBasicAuthenticationFilter.class);
// filter(PATTERN_SVN).through(SvnPermissionFilter.class);
protected void configureServlets() {
bind(SvnConfigDtoToSvnConfigMapper.class).to(Mappers.getMapper(SvnConfigDtoToSvnConfigMapper.class).getClass());
bind(SvnConfigToSvnConfigDtoMapper.class).to(Mappers.getMapper(SvnConfigToSvnConfigDtoMapper.class).getClass());
}