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

@@ -1,85 +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;
/**
*
* @author Sebastian Sdorra
* @since 1.17
*/
public class ArgumentIsInvalidException extends IllegalStateException
{
/**
* Constructs ...
*
*/
public ArgumentIsInvalidException()
{
super();
}
/**
* Constructs ...
*
*
* @param s
*/
public ArgumentIsInvalidException(String s)
{
super(s);
}
/**
* Constructs ...
*
*
* @param cause
*/
public ArgumentIsInvalidException(Throwable cause)
{
super(cause);
}
/**
* Constructs ...
*
*
* @param message
* @param cause
*/
public ArgumentIsInvalidException(String message, Throwable cause)
{
super(message, cause);
}
}

View File

@@ -4,7 +4,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.api.v2.resources.UriInfoStore;
import sonia.scm.repository.Repository;
import sonia.scm.web.filter.ProviderPermissionFilter;
import sonia.scm.web.filter.PermissionFilter;
import javax.inject.Provider;
import javax.servlet.ServletConfig;
@@ -19,13 +19,13 @@ public abstract class InitializingHttpScmProtocolWrapper {
LoggerFactory.getLogger(InitializingHttpScmProtocolWrapper.class);
private final Provider<? extends ScmProviderHttpServlet> delegateProvider;
private final Provider<? extends ProviderPermissionFilter> permissionFilterProvider;
private final Provider<? extends PermissionFilter> permissionFilterProvider;
private final Provider<UriInfoStore> uriInfoStore;
private volatile boolean isInitialized = false;
protected InitializingHttpScmProtocolWrapper(Provider<? extends ScmProviderHttpServlet> delegateProvider, Provider<? extends ProviderPermissionFilter> permissionFilterProvider, Provider<UriInfoStore> uriInfoStore) {
protected InitializingHttpScmProtocolWrapper(Provider<? extends ScmProviderHttpServlet> delegateProvider, Provider<? extends PermissionFilter> permissionFilterProvider, Provider<UriInfoStore> uriInfoStore) {
this.delegateProvider = delegateProvider;
this.permissionFilterProvider = permissionFilterProvider;
this.uriInfoStore = uriInfoStore;

View File

@@ -33,8 +33,6 @@
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.repository.Feature;
import sonia.scm.repository.api.Command;
import sonia.scm.repository.api.CommandNotSupportedException;
@@ -45,8 +43,6 @@ import java.io.IOException;
import java.util.Collections;
import java.util.Set;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra

View File

@@ -33,15 +33,12 @@
package sonia.scm.web.filter;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Splitter;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.ArgumentIsInvalidException;
import sonia.scm.SCMContext;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.repository.Repository;
@@ -57,8 +54,6 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Iterator;
//~--- JDK imports ------------------------------------------------------------
/**
* Abstract http filter to check repository permissions.
*
@@ -137,22 +132,6 @@ public abstract class PermissionFilter
sendAccessDenied(request, response, subject);
}
}
catch (ArgumentIsInvalidException ex)
{
if (logger.isTraceEnabled())
{
logger.trace(
"wrong request at ".concat(request.getRequestURI()).concat(
" send redirect"), ex);
}
else if (logger.isWarnEnabled())
{
logger.warn("wrong request at {} send redirect",
request.getRequestURI());
}
response.sendRedirect(getRepositoryRootHelpUrl(request));
}
catch (ScmSecurityException | AuthorizationException ex)
{
logger.warn("user " + subject.getPrincipal() + " has not enough permissions", ex);
@@ -256,25 +235,6 @@ public abstract class PermissionFilter
: "read";
}
/**
* Returns the repository root help url.
*
*
* @param request current http request
*
* @return repository root help url
*/
private String getRepositoryRootHelpUrl(HttpServletRequest request)
{
String type = extractType(request);
String helpUrl = HttpUtil.getCompleteUrl(request,
"/api/rest/help/repository-root/");
helpUrl = helpUrl.concat(type).concat(".html");
return helpUrl;
}
/**
* Returns the username from the given subject or anonymous.
*

View File

@@ -1,71 +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.filter;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.config.ScmConfiguration;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra
* @since 1.9
*/
public abstract class ProviderPermissionFilter extends PermissionFilter
{
/**
* the logger for ProviderPermissionFilter
*/
private static final Logger logger =
LoggerFactory.getLogger(ProviderPermissionFilter.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param configuration
* @since 1.21
*/
public ProviderPermissionFilter(ScmConfiguration configuration)
{
super(configuration);
}
}

View File

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

View File

@@ -45,47 +45,27 @@ import sonia.scm.web.GitScmProtocolProviderWrapper;
* @author Sebastian Sdorra
*/
@Extension
public class GitRepositoryServiceResolver implements RepositoryServiceResolver
{
public class GitRepositoryServiceResolver implements RepositoryServiceResolver {
/** Field description */
public static final String TYPE = "git";
//~--- constructors ---------------------------------------------------------
@Inject
public GitRepositoryServiceResolver(GitRepositoryHandler handler, GitScmProtocolProviderWrapper providerWrapper)
{
public GitRepositoryServiceResolver(GitRepositoryHandler handler, GitScmProtocolProviderWrapper providerWrapper) {
this.handler = handler;
this.providerWrapper = providerWrapper;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param repository
*
* @return
*/
@Override
public GitRepositoryServiceProvider resolve(Repository repository)
{
public GitRepositoryServiceProvider resolve(Repository repository) {
GitRepositoryServiceProvider provider = null;
if (TYPE.equalsIgnoreCase(repository.getType()))
{
if (TYPE.equalsIgnoreCase(repository.getType())) {
provider = new GitRepositoryServiceProvider(handler, repository, providerWrapper.get(repository));
}
return provider;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private final GitRepositoryHandler handler;
private final GitScmProtocolProviderWrapper providerWrapper;
}

View File

@@ -33,32 +33,24 @@
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import org.eclipse.jgit.http.server.GitSmartHttpTools;
import sonia.scm.ClientMessages;
import sonia.scm.Priority;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.filter.Filters;
import sonia.scm.repository.GitUtil;
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;
//~--- JDK imports ------------------------------------------------------------
/**
* GitPermissionFilter decides if a git request requires write or read privileges.
*
* @author Sebastian Sdorra
*/
@Priority(Filters.PRIORITY_AUTHORIZATION)
//@WebElement(value = GitServletModule.PATTERN_GIT)
public class GitPermissionFilter extends ProviderPermissionFilter
public class GitPermissionFilter extends PermissionFilter
{
private static final String PARAMETER_SERVICE = "service";

View File

@@ -51,18 +51,6 @@ import sonia.scm.web.lfs.LfsBlobStoreFactory;
public class GitServletModule extends ServletModule
{
public static final String GIT_PATH = "/repo";
/** Field description */
public static final String PATTERN_GIT = GIT_PATH + "/*";
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*/
@Override
protected void configureServlets()
{

View File

@@ -33,8 +33,6 @@
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -57,8 +55,6 @@ import java.util.regex.Pattern;
import static org.eclipse.jgit.lfs.lib.Constants.CONTENT_TYPE_GIT_LFS_JSON;
import static org.slf4j.LoggerFactory.getLogger;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra
@@ -67,7 +63,8 @@ import static org.slf4j.LoggerFactory.getLogger;
public class ScmGitServlet extends GitServlet implements ScmProviderHttpServlet
{
/** Field description */
public static final String REPO_PATH = "/repo";
public static final Pattern REGEX_GITHTTPBACKEND = Pattern.compile(
"(?x)^/repo/(.*/(HEAD|info/refs|objects/(info/[^/]+|[0-9a-f]{2}/[0-9a-f]{38}|pack/pack-[0-9a-f]{40}\\.(pack|idx))|git-(upload|receive)-pack))$"
);
@@ -172,7 +169,7 @@ public class ScmGitServlet extends GitServlet implements ScmProviderHttpServlet
* @throws IOException
* @throws ServletException
*/
private void handleBrowserRequest(HttpServletRequest request, HttpServletResponse response, Repository repository) throws ServletException, IOException {
private void handleBrowserRequest(HttpServletRequest request, HttpServletResponse response, Repository repository) throws ServletException {
try {
repositoryViewer.handleRequest(request, response, repository);
} catch (IOException ex) {
@@ -191,7 +188,7 @@ public class ScmGitServlet extends GitServlet implements ScmProviderHttpServlet
*/
private static boolean isLfsFileTransferRequest(HttpServletRequest request, String repository) {
String regex = String.format("^%s%s/%s(\\.git)?/info/lfs/objects/[a-z0-9]{64}$", request.getContextPath(), GitServletModule.GIT_PATH, repository);
String regex = String.format("^%s%s/%s(\\.git)?/info/lfs/objects/[a-z0-9]{64}$", request.getContextPath(), REPO_PATH, repository);
boolean pathMatches = request.getRequestURI().matches(regex);
boolean methodMatches = request.getMethod().equals("PUT") || request.getMethod().equals("GET");
@@ -210,7 +207,7 @@ public class ScmGitServlet extends GitServlet implements ScmProviderHttpServlet
*/
private static boolean isLfsBatchApiRequest(HttpServletRequest request, String repository) {
String regex = String.format("^%s%s/%s(\\.git)?/info/lfs/objects/batch$", request.getContextPath(), GitServletModule.GIT_PATH, repository);
String regex = String.format("^%s%s/%s(\\.git)?/info/lfs/objects/batch$", request.getContextPath(), REPO_PATH, repository);
boolean pathMatches = request.getRequestURI().matches(regex);
boolean methodMatches = "POST".equals(request.getMethod());

View File

@@ -33,8 +33,6 @@
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.Closeables;
import sonia.scm.repository.Feature;
import sonia.scm.repository.HgHookManager;
@@ -49,8 +47,6 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra

View File

@@ -33,8 +33,6 @@
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import sonia.scm.plugin.Extension;
import sonia.scm.repository.HgHookManager;

View File

@@ -1,102 +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.Priority;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.filter.Filters;
import sonia.scm.filter.WebElement;
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;
/**
*
* @author Sebastian Sdorra
*/
@Priority(Filters.PRIORITY_AUTHENTICATION)
@WebElement(value = HgServletModule.MAPPING_HG)
public class HgBasicAuthenticationFilter extends AuthenticationFilter
{
/**
* Constructs ...
*
*
* @param configuration
* @param webTokenGenerators
*/
@Inject
public HgBasicAuthenticationFilter(ScmConfiguration configuration,
Set<WebTokenGenerator> webTokenGenerators)
{
super(configuration, webTokenGenerators);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param request
* @param response
*
* @throws IOException
*/
@Override
protected void sendFailedAuthenticationError(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
if (HgUtil.isHgClient(request)
&& (configuration.isLoginAttemptLimitEnabled()))
{
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
else
{
super.sendFailedAuthenticationError(request, response);
}
}
}

View File

@@ -33,8 +33,6 @@
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Stopwatch;
import com.google.common.base.Strings;
import com.google.inject.Inject;
@@ -68,8 +66,6 @@ import java.io.IOException;
import java.util.Base64;
import java.util.Enumeration;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra

View File

@@ -33,43 +33,30 @@
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.web.filter.ProviderPermissionFilter;
import sonia.scm.web.filter.PermissionFilter;
import javax.servlet.http.HttpServletRequest;
import java.util.Set;
//~--- JDK imports ------------------------------------------------------------
/**
* Permission filter for mercurial repositories.
*
* @author Sebastian Sdorra
*/
//@Priority(Filters.PRIORITY_AUTHORIZATION)
//@WebElement(value = HgServletModule.MAPPING_HG)
public class HgPermissionFilter extends ProviderPermissionFilter
public class HgPermissionFilter extends PermissionFilter
{
private static final Set<String> READ_METHODS = ImmutableSet.of("GET", "HEAD", "OPTIONS", "TRACE");
/**
* Constructs a new instance.
*
* @param configuration scm configuration
*/
@Inject
public HgPermissionFilter(ScmConfiguration configuration)
{
super(configuration);
}
//~--- get methods ----------------------------------------------------------
@Override
public boolean isWriteRequest(HttpServletRequest request)
{

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());
}

View File

@@ -33,8 +33,6 @@
package sonia.scm;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.inject.Injector;
@@ -63,8 +61,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra

View File

@@ -33,8 +33,6 @@
package sonia.scm;
//~--- non-JDK imports --------------------------------------------------------
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.Provider;
import com.google.inject.multibindings.Multibinder;
@@ -121,8 +119,6 @@ import sonia.scm.web.security.DefaultAdministrationContext;
import javax.net.ssl.SSLContext;
import javax.servlet.ServletContext;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra
@@ -188,14 +184,6 @@ public class ScmServletModule extends ServletModule
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param servletContext
* @param pluginLoader
* @param overrides
*/
ScmServletModule(ServletContext servletContext, DefaultPluginLoader pluginLoader, ClassOverrides overrides)
{
this.servletContext = servletContext;

View File

@@ -33,8 +33,6 @@
package sonia.scm.api.rest.resources;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.Maps;
@@ -59,8 +57,6 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra

View File

@@ -31,8 +31,6 @@
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.github.sdorra.ssp.PermissionActionCheck;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -67,8 +65,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
//~--- JDK imports ------------------------------------------------------------
/**
* Default implementation of {@link RepositoryManager}.
*

View File

@@ -33,30 +33,26 @@
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.servlet.RequestScoped;
import sonia.scm.security.ScmSecurityException;
import javax.servlet.http.HttpServletRequest;
//~--- JDK imports ------------------------------------------------------------
@RequestScoped
public class DefaultRepositoryProvider implements RepositoryProvider {
public static final String ATTRIBUTE_NAME = "scm.request.repository";
private final Provider<HttpServletRequest> requestProvider;
@Inject
public DefaultRepositoryProvider(Provider<HttpServletRequest> requestProvider) {
this.requestProvider = requestProvider;
}
@Override
public Repository get() throws ScmSecurityException {
public Repository get() {
HttpServletRequest request = requestProvider.get();
if (request != null) {