mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-24 13:00:18 +01:00
merge
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package sonia.scm.api.v2.resources;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -14,7 +13,7 @@ import java.util.Arrays;
|
||||
* builder for each method.
|
||||
*
|
||||
* <pre>
|
||||
* LinkBuilder builder = new LinkBuilder(uriInfo, MainResource.class, SubResource.class);
|
||||
* LinkBuilder builder = new LinkBuilder(pathInfo, MainResource.class, SubResource.class);
|
||||
* Link link = builder
|
||||
* .method("sub")
|
||||
* .parameters("param")
|
||||
@@ -25,16 +24,16 @@ import java.util.Arrays;
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess") // Non-public will result in IllegalAccessError for plugins
|
||||
public class LinkBuilder {
|
||||
private final UriInfo uriInfo;
|
||||
private final ScmPathInfo pathInfo;
|
||||
private final Class[] classes;
|
||||
private final ImmutableList<Call> calls;
|
||||
|
||||
public LinkBuilder(UriInfo uriInfo, Class... classes) {
|
||||
this(uriInfo, classes, ImmutableList.of());
|
||||
public LinkBuilder(ScmPathInfo pathInfo, Class... classes) {
|
||||
this(pathInfo, classes, ImmutableList.of());
|
||||
}
|
||||
|
||||
private LinkBuilder(UriInfo uriInfo, Class[] classes, ImmutableList<Call> calls) {
|
||||
this.uriInfo = uriInfo;
|
||||
private LinkBuilder(ScmPathInfo pathInfo, Class[] classes, ImmutableList<Call> calls) {
|
||||
this.pathInfo = pathInfo;
|
||||
this.classes = classes;
|
||||
this.calls = calls;
|
||||
}
|
||||
@@ -51,7 +50,7 @@ public class LinkBuilder {
|
||||
throw new IllegalStateException("not enough methods for all classes");
|
||||
}
|
||||
|
||||
URI baseUri = uriInfo.getBaseUri();
|
||||
URI baseUri = pathInfo.getApiRestUri();
|
||||
URI relativeUri = createRelativeUri();
|
||||
return baseUri.resolve(relativeUri);
|
||||
}
|
||||
@@ -61,7 +60,7 @@ public class LinkBuilder {
|
||||
}
|
||||
|
||||
private LinkBuilder add(String method, String[] parameters) {
|
||||
return new LinkBuilder(uriInfo, classes, appendNewCall(method, parameters));
|
||||
return new LinkBuilder(pathInfo, classes, appendNewCall(method, parameters));
|
||||
}
|
||||
|
||||
private ImmutableList<Call> appendNewCall(String method, String[] parameters) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public interface ScmPathInfo {
|
||||
|
||||
String REST_API_PATH = "/api/rest";
|
||||
|
||||
URI getApiRestUri();
|
||||
|
||||
default URI getRootUri() {
|
||||
return getApiRestUri().resolve("../..");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
public class ScmPathInfoStore {
|
||||
|
||||
private ScmPathInfo pathInfo;
|
||||
|
||||
public ScmPathInfo get() {
|
||||
return pathInfo;
|
||||
}
|
||||
|
||||
public void set(ScmPathInfo info) {
|
||||
if (this.pathInfo != null) {
|
||||
throw new IllegalStateException("UriInfo already set");
|
||||
}
|
||||
this.pathInfo = info;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
public class UriInfoStore {
|
||||
|
||||
private UriInfo uriInfo;
|
||||
|
||||
public UriInfo get() {
|
||||
return uriInfo;
|
||||
}
|
||||
|
||||
public void set(UriInfo uriInfo) {
|
||||
if (this.uriInfo != null) {
|
||||
throw new IllegalStateException("UriInfo already set");
|
||||
}
|
||||
this.uriInfo = uriInfo;
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
package sonia.scm.filter;
|
||||
|
||||
import static sonia.scm.api.v2.resources.ScmPathInfo.REST_API_PATH;
|
||||
|
||||
/**
|
||||
* Useful constants for filter implementations.
|
||||
*
|
||||
@@ -44,26 +46,26 @@ public final class Filters
|
||||
public static final String PATTERN_ALL = "/*";
|
||||
|
||||
/** Field description */
|
||||
public static final String PATTERN_CONFIG = "/api/rest/config*";
|
||||
public static final String PATTERN_CONFIG = REST_API_PATH + "/config*";
|
||||
|
||||
/** Field description */
|
||||
public static final String PATTERN_DEBUG = "/debug.html";
|
||||
|
||||
/** Field description */
|
||||
public static final String PATTERN_GROUPS = "/api/rest/groups*";
|
||||
public static final String PATTERN_GROUPS = REST_API_PATH + "/groups*";
|
||||
|
||||
/** Field description */
|
||||
public static final String PATTERN_PLUGINS = "/api/rest/plugins*";
|
||||
public static final String PATTERN_PLUGINS = REST_API_PATH + "/plugins*";
|
||||
|
||||
/** Field description */
|
||||
public static final String PATTERN_RESOURCE_REGEX =
|
||||
"^/(?:resources|api|plugins|index)[\\./].*(?:html|\\.css|\\.js|\\.xml|\\.json|\\.txt)";
|
||||
|
||||
/** Field description */
|
||||
public static final String PATTERN_RESTAPI = "/api/rest/*";
|
||||
public static final String PATTERN_RESTAPI = REST_API_PATH + "/*";
|
||||
|
||||
/** Field description */
|
||||
public static final String PATTERN_USERS = "/api/rest/users*";
|
||||
public static final String PATTERN_USERS = REST_API_PATH + "/users*";
|
||||
|
||||
/** authentication priority */
|
||||
public static final int PRIORITY_AUTHENTICATION = 5000;
|
||||
|
||||
@@ -1,207 +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.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.15
|
||||
*/
|
||||
public final class EscapeUtil
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
private EscapeUtil() {}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
public static void escape(BrowserResult result)
|
||||
{
|
||||
result.setBranch(escape(result.getBranch()));
|
||||
result.setTag(escape(result.getTag()));
|
||||
|
||||
for (FileObject fo : result)
|
||||
{
|
||||
escape(fo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param result
|
||||
* @since 1.17
|
||||
*/
|
||||
public static void escape(BlameResult result)
|
||||
{
|
||||
for (BlameLine line : result.getBlameLines())
|
||||
{
|
||||
escape(line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param line
|
||||
* @since 1.17
|
||||
*/
|
||||
public static void escape(BlameLine line)
|
||||
{
|
||||
line.setDescription(escape(line.getDescription()));
|
||||
escape(line.getAuthor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param fo
|
||||
*/
|
||||
public static void escape(FileObject fo)
|
||||
{
|
||||
fo.setDescription(escape(fo.getDescription()));
|
||||
fo.setName(fo.getName());
|
||||
fo.setPath(fo.getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param changeset
|
||||
*/
|
||||
public static void escape(Changeset changeset)
|
||||
{
|
||||
changeset.setDescription(escape(changeset.getDescription()));
|
||||
escape(changeset.getAuthor());
|
||||
changeset.setBranches(escapeList(changeset.getBranches()));
|
||||
changeset.setTags(escapeList(changeset.getTags()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param person
|
||||
* @since 1.17
|
||||
*/
|
||||
public static void escape(Person person)
|
||||
{
|
||||
if (person != null)
|
||||
{
|
||||
person.setName(escape(person.getName()));
|
||||
person.setMail(escape(person.getMail()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
public static void escape(ChangesetPagingResult result)
|
||||
{
|
||||
for (Changeset c : result)
|
||||
{
|
||||
escape(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param value
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String escape(String value)
|
||||
{
|
||||
return StringEscapeUtils.escapeHtml(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param values
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List<String> escapeList(List<String> values)
|
||||
{
|
||||
if (Util.isNotEmpty(values))
|
||||
{
|
||||
List<String> newList = Lists.newArrayList();
|
||||
|
||||
for (String v : values)
|
||||
{
|
||||
newList.add(StringEscapeUtils.escapeHtml(v));
|
||||
}
|
||||
|
||||
values = newList;
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public static void escape(Modifications modifications) {
|
||||
modifications.setAdded(escapeList(modifications.getAdded()));
|
||||
modifications.setModified(escapeList(modifications.getModified()));
|
||||
modifications.setRemoved(escapeList(modifications.getRemoved()));
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,6 @@ public class PreProcessorUtil
|
||||
blameLine.getLineNumber(), repository.getName());
|
||||
}
|
||||
|
||||
EscapeUtil.escape(blameLine);
|
||||
handlePreProcess(repository,blameLine,blameLinePreProcessorFactorySet, blameLinePreProcessorSet);
|
||||
}
|
||||
|
||||
@@ -123,22 +122,6 @@ public class PreProcessorUtil
|
||||
* @param blameResult
|
||||
*/
|
||||
public void prepareForReturn(Repository repository, BlameResult blameResult)
|
||||
{
|
||||
prepareForReturn(repository, blameResult, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param blameResult
|
||||
* @param escape
|
||||
*
|
||||
* @since 1.35
|
||||
*/
|
||||
public void prepareForReturn(Repository repository, BlameResult blameResult,
|
||||
boolean escape)
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
@@ -146,10 +129,6 @@ public class PreProcessorUtil
|
||||
repository.getName());
|
||||
}
|
||||
|
||||
if (escape)
|
||||
{
|
||||
EscapeUtil.escape(blameResult);
|
||||
}
|
||||
handlePreProcessForIterable(repository, blameResult.getBlameLines(),blameLinePreProcessorFactorySet, blameLinePreProcessorSet);
|
||||
}
|
||||
|
||||
@@ -162,32 +141,12 @@ public class PreProcessorUtil
|
||||
*/
|
||||
public void prepareForReturn(Repository repository, Changeset changeset)
|
||||
{
|
||||
prepareForReturn(repository, changeset, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param changeset
|
||||
* @param escape
|
||||
*
|
||||
* @since 1.35
|
||||
*/
|
||||
public void prepareForReturn(Repository repository, Changeset changeset, boolean escape){
|
||||
logger.trace("prepare changeset {} of repository {} for return", changeset.getId(), repository.getName());
|
||||
if (escape) {
|
||||
EscapeUtil.escape(changeset);
|
||||
}
|
||||
handlePreProcess(repository, changeset, changesetPreProcessorFactorySet, changesetPreProcessorSet);
|
||||
}
|
||||
|
||||
public void prepareForReturn(Repository repository, Modifications modifications, boolean escape) {
|
||||
public void prepareForReturn(Repository repository, Modifications modifications) {
|
||||
logger.trace("prepare modifications {} of repository {} for return", modifications, repository.getName());
|
||||
if (escape) {
|
||||
EscapeUtil.escape(modifications);
|
||||
}
|
||||
handlePreProcess(repository, modifications, modificationsPreProcessorFactorySet, modificationsPreProcessorSet);
|
||||
}
|
||||
|
||||
@@ -199,22 +158,6 @@ public class PreProcessorUtil
|
||||
* @param result
|
||||
*/
|
||||
public void prepareForReturn(Repository repository, BrowserResult result)
|
||||
{
|
||||
prepareForReturn(repository, result, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param result
|
||||
* @param escape
|
||||
*
|
||||
* @since 1.35
|
||||
*/
|
||||
public void prepareForReturn(Repository repository, BrowserResult result,
|
||||
boolean escape)
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
@@ -222,10 +165,6 @@ public class PreProcessorUtil
|
||||
repository.getName());
|
||||
}
|
||||
|
||||
if (escape)
|
||||
{
|
||||
EscapeUtil.escape(result);
|
||||
}
|
||||
handlePreProcessForIterable(repository, result,fileObjectPreProcessorFactorySet, fileObjectPreProcessorSet);
|
||||
}
|
||||
|
||||
@@ -235,12 +174,8 @@ public class PreProcessorUtil
|
||||
*
|
||||
* @param repository
|
||||
* @param result
|
||||
* @param escape
|
||||
*
|
||||
* @since 1.35
|
||||
*/
|
||||
public void prepareForReturn(Repository repository,
|
||||
ChangesetPagingResult result, boolean escape)
|
||||
public void prepareForReturn(Repository repository, ChangesetPagingResult result)
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
@@ -248,27 +183,9 @@ public class PreProcessorUtil
|
||||
repository.getName());
|
||||
}
|
||||
|
||||
if (escape)
|
||||
{
|
||||
EscapeUtil.escape(result);
|
||||
}
|
||||
handlePreProcessForIterable(repository,result,changesetPreProcessorFactorySet, changesetPreProcessorSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param result
|
||||
*/
|
||||
public void prepareForReturn(Repository repository,
|
||||
ChangesetPagingResult result)
|
||||
{
|
||||
prepareForReturn(repository, result, true);
|
||||
}
|
||||
|
||||
|
||||
private <T, F extends PreProcessorFactory<T>, P extends PreProcessor<T>> void handlePreProcess(Repository repository, T processedObject,
|
||||
Collection<F> factories,
|
||||
Collection<P> preProcessors) {
|
||||
|
||||
@@ -40,7 +40,6 @@ import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Lists;
|
||||
import sonia.scm.BasicPropertiesAware;
|
||||
import sonia.scm.ModelObject;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.util.ValidationUtil;
|
||||
|
||||
@@ -349,17 +348,6 @@ public class Repository extends BasicPropertiesAware implements ModelObject, Per
|
||||
// do not copy health check results
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the url of the repository.
|
||||
*
|
||||
* @param baseUrl base url of the server including the context path
|
||||
* @return url of the repository
|
||||
* @since 1.17
|
||||
*/
|
||||
public String createUrl(String baseUrl) {
|
||||
return HttpUtil.concatenate(baseUrl, type, namespace, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the {@link Repository} is the same as the obj argument.
|
||||
*
|
||||
|
||||
@@ -38,7 +38,6 @@ package sonia.scm.repository;
|
||||
import sonia.scm.AlreadyExistsException;
|
||||
import sonia.scm.TypeManager;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -99,29 +98,6 @@ public interface RepositoryManager
|
||||
*/
|
||||
public Collection<RepositoryType> getConfiguredTypes();
|
||||
|
||||
/**
|
||||
* Returns the {@link Repository} associated to the request uri.
|
||||
*
|
||||
*
|
||||
* @param request the current http request
|
||||
*
|
||||
* @return associated to the request uri
|
||||
* @since 1.9
|
||||
*/
|
||||
public Repository getFromRequest(HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* Returns the {@link Repository} associated to the request uri.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param uri request uri without context path
|
||||
*
|
||||
* @return associated to the request uri
|
||||
* @since 1.9
|
||||
*/
|
||||
public Repository getFromUri(String uri);
|
||||
|
||||
/**
|
||||
* Returns a {@link RepositoryHandler} by the given type (hg, git, svn ...).
|
||||
*
|
||||
|
||||
@@ -39,7 +39,6 @@ import sonia.scm.AlreadyExistsException;
|
||||
import sonia.scm.ManagerDecorator;
|
||||
import sonia.scm.Type;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -120,34 +119,6 @@ public class RepositoryManagerDecorator
|
||||
return decorated;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Repository getFromRequest(HttpServletRequest request)
|
||||
{
|
||||
return decorated.getFromRequest(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param uri
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Repository getFromUri(String uri)
|
||||
{
|
||||
return decorated.getFromUri(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
||||
@@ -44,8 +44,8 @@ import sonia.scm.NotFoundException;
|
||||
public class RepositoryNotFoundException extends NotFoundException
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final long serialVersionUID = -6583078808900520166L;
|
||||
private static final String TYPE_REPOSITORY = "repository";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
@@ -55,10 +55,14 @@ public class RepositoryNotFoundException extends NotFoundException
|
||||
*
|
||||
*/
|
||||
public RepositoryNotFoundException(Repository repository) {
|
||||
super("repository", repository.getName() + "/" + repository.getNamespace());
|
||||
super(TYPE_REPOSITORY, repository.getName() + "/" + repository.getNamespace());
|
||||
}
|
||||
|
||||
public RepositoryNotFoundException(String repositoryId) {
|
||||
super("repository", repositoryId);
|
||||
super(TYPE_REPOSITORY, repositoryId);
|
||||
}
|
||||
|
||||
public RepositoryNotFoundException(NamespaceAndName namespaceAndName) {
|
||||
super(TYPE_REPOSITORY, namespaceAndName.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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
|
||||
@@ -26,35 +26,21 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.throwingproviders.CheckedProvider;
|
||||
|
||||
import sonia.scm.security.ScmSecurityException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.10
|
||||
*/
|
||||
public interface RepositoryProvider extends CheckedProvider<Repository>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws ScmSecurityException
|
||||
*/
|
||||
public interface RepositoryProvider extends CheckedProvider<Repository> {
|
||||
@Override
|
||||
public Repository get() throws ScmSecurityException;
|
||||
Repository get();
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ public final class BlameCommandBuilder
|
||||
|
||||
if (!disablePreProcessors && (result != null))
|
||||
{
|
||||
preProcessorUtil.prepareForReturn(repository, result, !disableEscaping);
|
||||
preProcessorUtil.prepareForReturn(repository, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -210,24 +210,6 @@ public final class BlameCommandBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable html escaping for the returned blame lines. By default all
|
||||
* blame lines are html escaped.
|
||||
*
|
||||
*
|
||||
* @param disableEscaping true to disable the html escaping
|
||||
*
|
||||
* @return {@code this}
|
||||
*
|
||||
* @since 1.35
|
||||
*/
|
||||
public BlameCommandBuilder setDisableEscaping(boolean disableEscaping)
|
||||
{
|
||||
this.disableEscaping = disableEscaping;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the execution of pre processors.
|
||||
*
|
||||
@@ -362,9 +344,6 @@ public final class BlameCommandBuilder
|
||||
/** the cache */
|
||||
private final Cache<CacheKey, BlameResult> cache;
|
||||
|
||||
/** disable escaping */
|
||||
private boolean disableEscaping = false;
|
||||
|
||||
/** disable change */
|
||||
private boolean disableCache = false;
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ public final class BrowseCommandBuilder
|
||||
|
||||
if (!disablePreProcessors && (result != null))
|
||||
{
|
||||
preProcessorUtil.prepareForReturn(repository, result, !disableEscaping);
|
||||
preProcessorUtil.prepareForReturn(repository, result);
|
||||
|
||||
List<FileObject> fileObjects = result.getFiles();
|
||||
|
||||
@@ -212,24 +212,6 @@ public final class BrowseCommandBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable html escaping for the returned file objects. By default all
|
||||
* file objects are html escaped.
|
||||
*
|
||||
*
|
||||
* @param disableEscaping true to disable the html escaping
|
||||
*
|
||||
* @return {@code this}
|
||||
*
|
||||
* @since 1.35
|
||||
*/
|
||||
public BrowseCommandBuilder setDisableEscaping(boolean disableEscaping)
|
||||
{
|
||||
this.disableEscaping = disableEscaping;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disabling the last commit means that every call to
|
||||
* {@link FileObject#getDescription()} and
|
||||
@@ -433,9 +415,6 @@ public final class BrowseCommandBuilder
|
||||
/** cache */
|
||||
private final Cache<CacheKey, BrowserResult> cache;
|
||||
|
||||
/** disable escaping */
|
||||
private boolean disableEscaping = false;
|
||||
|
||||
/** disables the cache */
|
||||
private boolean disableCache = false;
|
||||
|
||||
|
||||
@@ -132,8 +132,7 @@ public final class HookChangesetBuilder
|
||||
try
|
||||
{
|
||||
copy = DeepCopy.copy(c);
|
||||
preProcessorUtil.prepareForReturn(repository, copy,
|
||||
!disableEscaping);
|
||||
preProcessorUtil.prepareForReturn(repository, copy);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
@@ -156,24 +155,6 @@ public final class HookChangesetBuilder
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Disable html escaping for the returned changesets. By default all
|
||||
* changesets are html escaped.
|
||||
*
|
||||
*
|
||||
* @param disableEscaping true to disable the html escaping
|
||||
*
|
||||
* @return {@code this}
|
||||
*
|
||||
* @since 1.35
|
||||
*/
|
||||
public HookChangesetBuilder setDisableEscaping(boolean disableEscaping)
|
||||
{
|
||||
this.disableEscaping = disableEscaping;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the execution of pre processors.
|
||||
*
|
||||
@@ -192,9 +173,6 @@ public final class HookChangesetBuilder
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** disable escaping */
|
||||
private boolean disableEscaping = false;
|
||||
|
||||
/** disable pre processors marker */
|
||||
private boolean disablePreProcessors = false;
|
||||
|
||||
|
||||
@@ -264,7 +264,7 @@ public final class LogCommandBuilder
|
||||
|
||||
if (!disablePreProcessors && (cpr != null))
|
||||
{
|
||||
preProcessorUtil.prepareForReturn(repository, cpr, !disableEscaping);
|
||||
preProcessorUtil.prepareForReturn(repository, cpr);
|
||||
}
|
||||
|
||||
return cpr;
|
||||
@@ -306,24 +306,6 @@ public final class LogCommandBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable html escaping for the returned changesets. By default all
|
||||
* changesets are html escaped.
|
||||
*
|
||||
*
|
||||
* @param disableEscaping true to disable the html escaping
|
||||
*
|
||||
* @return {@code this}
|
||||
*
|
||||
* @since 1.35
|
||||
*/
|
||||
public LogCommandBuilder setDisableEscaping(boolean disableEscaping)
|
||||
{
|
||||
this.disableEscaping = disableEscaping;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the execution of pre processors.
|
||||
*
|
||||
@@ -545,9 +527,6 @@ public final class LogCommandBuilder
|
||||
/** repository to query */
|
||||
private final Repository repository;
|
||||
|
||||
/** disable escaping */
|
||||
private boolean disableEscaping = false;
|
||||
|
||||
/** disable cache */
|
||||
private boolean disableCache = false;
|
||||
|
||||
|
||||
@@ -43,9 +43,6 @@ public final class ModificationsCommandBuilder {
|
||||
|
||||
private final PreProcessorUtil preProcessorUtil;
|
||||
|
||||
@Setter
|
||||
private boolean disableEscaping = false;
|
||||
|
||||
@Setter
|
||||
private boolean disableCache = false;
|
||||
|
||||
@@ -90,7 +87,7 @@ public final class ModificationsCommandBuilder {
|
||||
}
|
||||
}
|
||||
if (!disablePreProcessors && (modifications != null)) {
|
||||
preProcessorUtil.prepareForReturn(repository, modifications, !disableEscaping);
|
||||
preProcessorUtil.prepareForReturn(repository, modifications);
|
||||
}
|
||||
return modifications;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
package sonia.scm.repository.api;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.cache.CacheManager;
|
||||
@@ -42,6 +43,8 @@ import sonia.scm.repository.spi.RepositoryServiceProvider;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* From the {@link RepositoryService} it is possible to access all commands for
|
||||
@@ -78,30 +81,32 @@ import java.io.IOException;
|
||||
* @apiviz.uses sonia.scm.repository.api.UnbundleCommandBuilder
|
||||
* @since 1.17
|
||||
*/
|
||||
@Slf4j
|
||||
public final class RepositoryService implements Closeable {
|
||||
private CacheManager cacheManager;
|
||||
private PreProcessorUtil preProcessorUtil;
|
||||
private RepositoryServiceProvider provider;
|
||||
private Repository repository;
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(RepositoryService.class);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RepositoryService.class);
|
||||
|
||||
private final CacheManager cacheManager;
|
||||
private final PreProcessorUtil preProcessorUtil;
|
||||
private final RepositoryServiceProvider provider;
|
||||
private final Repository repository;
|
||||
private final Set<ScmProtocolProvider> protocolProviders;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link RepositoryService}. This constructor should only
|
||||
* be called from the {@link RepositoryServiceFactory}.
|
||||
*
|
||||
* @param cacheManager cache manager
|
||||
* @param cacheManager cache manager
|
||||
* @param provider implementation for {@link RepositoryServiceProvider}
|
||||
* @param repository the repository
|
||||
* @param preProcessorUtil
|
||||
*/
|
||||
RepositoryService(CacheManager cacheManager,
|
||||
RepositoryServiceProvider provider, Repository repository,
|
||||
PreProcessorUtil preProcessorUtil) {
|
||||
RepositoryServiceProvider provider, Repository repository,
|
||||
PreProcessorUtil preProcessorUtil, Set<ScmProtocolProvider> protocolProviders) {
|
||||
this.cacheManager = cacheManager;
|
||||
this.provider = provider;
|
||||
this.repository = repository;
|
||||
this.preProcessorUtil = preProcessorUtil;
|
||||
this.protocolProviders = protocolProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +130,7 @@ public final class RepositoryService implements Closeable {
|
||||
try {
|
||||
provider.close();
|
||||
} catch (IOException ex) {
|
||||
logger.error("Could not close repository service provider", ex);
|
||||
log.error("Could not close repository service provider", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +143,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public BlameCommandBuilder getBlameCommand() {
|
||||
logger.debug("create blame command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new BlameCommandBuilder(cacheManager, provider.getBlameCommand(),
|
||||
repository, preProcessorUtil);
|
||||
@@ -153,7 +158,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public BranchesCommandBuilder getBranchesCommand() {
|
||||
logger.debug("create branches command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new BranchesCommandBuilder(cacheManager,
|
||||
provider.getBranchesCommand(), repository);
|
||||
@@ -168,7 +173,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public BrowseCommandBuilder getBrowseCommand() {
|
||||
logger.debug("create browse command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new BrowseCommandBuilder(cacheManager, provider.getBrowseCommand(),
|
||||
repository, preProcessorUtil);
|
||||
@@ -184,7 +189,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public BundleCommandBuilder getBundleCommand() {
|
||||
logger.debug("create bundle command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new BundleCommandBuilder(provider.getBundleCommand(), repository);
|
||||
}
|
||||
@@ -198,7 +203,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public CatCommandBuilder getCatCommand() {
|
||||
logger.debug("create cat command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new CatCommandBuilder(provider.getCatCommand());
|
||||
}
|
||||
@@ -213,7 +218,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public DiffCommandBuilder getDiffCommand() {
|
||||
logger.debug("create diff command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new DiffCommandBuilder(provider.getDiffCommand());
|
||||
}
|
||||
@@ -229,7 +234,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public IncomingCommandBuilder getIncomingCommand() {
|
||||
logger.debug("create incoming command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new IncomingCommandBuilder(cacheManager,
|
||||
provider.getIncomingCommand(), repository, preProcessorUtil);
|
||||
@@ -244,7 +249,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public LogCommandBuilder getLogCommand() {
|
||||
logger.debug("create log command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new LogCommandBuilder(cacheManager, provider.getLogCommand(),
|
||||
repository, preProcessorUtil);
|
||||
@@ -258,7 +263,7 @@ public final class RepositoryService implements Closeable {
|
||||
* by the implementation of the repository service provider.
|
||||
*/
|
||||
public ModificationsCommandBuilder getModificationsCommand() {
|
||||
logger.debug("create modifications command for repository {}",repository.getNamespaceAndName());
|
||||
logger.debug("create modifications command for repository {}", repository.getNamespaceAndName());
|
||||
return new ModificationsCommandBuilder(provider.getModificationsCommand(),repository, cacheManager.getCache(ModificationsCommandBuilder.CACHE_NAME), preProcessorUtil);
|
||||
}
|
||||
|
||||
@@ -272,7 +277,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public OutgoingCommandBuilder getOutgoingCommand() {
|
||||
logger.debug("create outgoing command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new OutgoingCommandBuilder(cacheManager,
|
||||
provider.getOutgoingCommand(), repository, preProcessorUtil);
|
||||
@@ -288,7 +293,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public PullCommandBuilder getPullCommand() {
|
||||
logger.debug("create pull command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new PullCommandBuilder(provider.getPullCommand(), repository);
|
||||
}
|
||||
@@ -303,7 +308,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public PushCommandBuilder getPushCommand() {
|
||||
logger.debug("create push command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new PushCommandBuilder(provider.getPushCommand());
|
||||
}
|
||||
@@ -326,7 +331,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public TagsCommandBuilder getTagsCommand() {
|
||||
logger.debug("create tags command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new TagsCommandBuilder(cacheManager, provider.getTagsCommand(),
|
||||
repository);
|
||||
@@ -342,7 +347,7 @@ public final class RepositoryService implements Closeable {
|
||||
*/
|
||||
public UnbundleCommandBuilder getUnbundleCommand() {
|
||||
logger.debug("create unbundle command for repository {}",
|
||||
repository.getName());
|
||||
repository.getNamespaceAndName());
|
||||
|
||||
return new UnbundleCommandBuilder(provider.getUnbundleCommand(),
|
||||
repository);
|
||||
@@ -369,5 +374,20 @@ public final class RepositoryService implements Closeable {
|
||||
return provider.getSupportedFeatures().contains(feature);
|
||||
}
|
||||
|
||||
public <T extends ScmProtocol> Stream<T> getSupportedProtocols() {
|
||||
return protocolProviders.stream()
|
||||
.filter(protocolProvider -> protocolProvider.getType().equals(getRepository().getType()))
|
||||
.map(this::<T>createProviderInstanceForRepository);
|
||||
}
|
||||
|
||||
private <T extends ScmProtocol> T createProviderInstanceForRepository(ScmProtocolProvider<T> protocolProvider) {
|
||||
return protocolProvider.get(repository);
|
||||
}
|
||||
|
||||
public <T extends ScmProtocol> T getProtocol(Class<T> clazz) {
|
||||
return this.<T>getSupportedProtocols()
|
||||
.filter(scmProtocol -> clazz.isAssignableFrom(scmProtocol.getClass()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format("no implementation for %s and repository type %s", clazz.getName(),getRepository().getType())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,13 +137,15 @@ public final class RepositoryServiceFactory
|
||||
@Inject
|
||||
public RepositoryServiceFactory(ScmConfiguration configuration,
|
||||
CacheManager cacheManager, RepositoryManager repositoryManager,
|
||||
Set<RepositoryServiceResolver> resolvers, PreProcessorUtil preProcessorUtil)
|
||||
Set<RepositoryServiceResolver> resolvers, PreProcessorUtil preProcessorUtil,
|
||||
Set<ScmProtocolProvider> protocolProviders)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.cacheManager = cacheManager;
|
||||
this.repositoryManager = repositoryManager;
|
||||
this.resolvers = resolvers;
|
||||
this.preProcessorUtil = preProcessorUtil;
|
||||
this.protocolProviders = protocolProviders;
|
||||
|
||||
ScmEventBus.getInstance().register(new CacheClearHook(cacheManager));
|
||||
}
|
||||
@@ -208,9 +210,7 @@ public final class RepositoryServiceFactory
|
||||
|
||||
if (repository == null)
|
||||
{
|
||||
String msg = "could not find a repository with namespace/name " + namespaceAndName;
|
||||
|
||||
throw new RepositoryNotFoundException(msg);
|
||||
throw new RepositoryNotFoundException(namespaceAndName);
|
||||
}
|
||||
|
||||
return create(repository);
|
||||
@@ -254,7 +254,7 @@ public final class RepositoryServiceFactory
|
||||
}
|
||||
|
||||
service = new RepositoryService(cacheManager, provider, repository,
|
||||
preProcessorUtil);
|
||||
preProcessorUtil, protocolProviders);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -369,4 +369,6 @@ public final class RepositoryServiceFactory
|
||||
|
||||
/** service resolvers */
|
||||
private final Set<RepositoryServiceResolver> resolvers;
|
||||
|
||||
private Set<ScmProtocolProvider> protocolProviders;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package sonia.scm.repository.api;
|
||||
|
||||
/**
|
||||
* An ScmProtocol represents a concrete protocol provided by the SCM-Manager instance
|
||||
* to interact with a repository depending on its type. There may be multiple protocols
|
||||
* available for a repository type (eg. http and ssh).
|
||||
*/
|
||||
public interface ScmProtocol {
|
||||
|
||||
/**
|
||||
* The type of the concrete protocol, eg. "http" or "ssh".
|
||||
*/
|
||||
String getType();
|
||||
|
||||
/**
|
||||
* The URL to access the repository providing this protocol.
|
||||
*/
|
||||
String getUrl();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package sonia.scm.repository.api;
|
||||
|
||||
import sonia.scm.plugin.ExtensionPoint;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
@ExtensionPoint(multi = true)
|
||||
public interface ScmProtocolProvider<T extends ScmProtocol> {
|
||||
|
||||
String getType();
|
||||
|
||||
T get(Repository repository);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.ScmProtocol;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
public abstract class HttpScmProtocol implements ScmProtocol {
|
||||
|
||||
private final Repository repository;
|
||||
private final String basePath;
|
||||
|
||||
public HttpScmProtocol(Repository repository, String basePath) {
|
||||
this.repository = repository;
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "http";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return URI.create(basePath + "/").resolve(String.format("repo/%s/%s", repository.getNamespace(), repository.getName())).toASCIIString();
|
||||
}
|
||||
|
||||
public final void serve(HttpServletRequest request, HttpServletResponse response, ServletConfig config) throws ServletException, IOException {
|
||||
serve(request, response, repository, config);
|
||||
}
|
||||
|
||||
protected abstract void serve(HttpServletRequest request, HttpServletResponse response, Repository repository, ServletConfig config) throws ServletException, IOException;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import sonia.scm.api.v2.resources.ScmPathInfoStore;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.ScmProtocolProvider;
|
||||
|
||||
import javax.inject.Provider;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
import static java.util.Optional.empty;
|
||||
import static java.util.Optional.of;
|
||||
|
||||
@Slf4j
|
||||
public abstract class InitializingHttpScmProtocolWrapper implements ScmProtocolProvider<HttpScmProtocol> {
|
||||
|
||||
private final Provider<? extends ScmProviderHttpServlet> delegateProvider;
|
||||
private final Provider<ScmPathInfoStore> pathInfoStore;
|
||||
private final ScmConfiguration scmConfiguration;
|
||||
|
||||
private volatile boolean isInitialized = false;
|
||||
|
||||
|
||||
protected InitializingHttpScmProtocolWrapper(Provider<? extends ScmProviderHttpServlet> delegateProvider, Provider<ScmPathInfoStore> pathInfoStore, ScmConfiguration scmConfiguration) {
|
||||
this.delegateProvider = delegateProvider;
|
||||
this.pathInfoStore = pathInfoStore;
|
||||
this.scmConfiguration = scmConfiguration;
|
||||
}
|
||||
|
||||
protected void initializeServlet(ServletConfig config, ScmProviderHttpServlet httpServlet) throws ServletException {
|
||||
httpServlet.init(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpScmProtocol get(Repository repository) {
|
||||
if (!repository.getType().equals(getType())) {
|
||||
throw new IllegalArgumentException(String.format("cannot handle repository with type %s with protocol for type %s", repository.getType(), getType()));
|
||||
}
|
||||
return new ProtocolWrapper(repository, computeBasePath());
|
||||
}
|
||||
|
||||
private String computeBasePath() {
|
||||
return getPathFromScmPathInfoIfAvailable().orElse(getPathFromConfiguration());
|
||||
}
|
||||
|
||||
private Optional<String> getPathFromScmPathInfoIfAvailable() {
|
||||
try {
|
||||
ScmPathInfoStore scmPathInfoStore = pathInfoStore.get();
|
||||
if (scmPathInfoStore != null && scmPathInfoStore.get() != null) {
|
||||
return of(scmPathInfoStore.get().getRootUri().toASCIIString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.debug("could not get ScmPathInfoStore from context", e);
|
||||
}
|
||||
return empty();
|
||||
}
|
||||
|
||||
private String getPathFromConfiguration() {
|
||||
log.debug("using base path from configuration: {}", scmConfiguration.getBaseUrl());
|
||||
return scmConfiguration.getBaseUrl();
|
||||
}
|
||||
|
||||
private class ProtocolWrapper extends HttpScmProtocol {
|
||||
|
||||
public ProtocolWrapper(Repository repository, String basePath) {
|
||||
super(repository, basePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void serve(HttpServletRequest request, HttpServletResponse response, Repository repository, ServletConfig config) throws ServletException, IOException {
|
||||
if (!isInitialized) {
|
||||
synchronized (InitializingHttpScmProtocolWrapper.this) {
|
||||
if (!isInitialized) {
|
||||
ScmProviderHttpServlet httpServlet = delegateProvider.get();
|
||||
initializeServlet(config, httpServlet);
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delegateProvider.get().service(request, response, repository);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface ScmProviderHttpServlet {
|
||||
|
||||
void service(HttpServletRequest request, HttpServletResponse response, Repository repository) throws ServletException, IOException;
|
||||
|
||||
void init(ServletConfig config) throws ServletException;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ScmProviderHttpServletDecorator implements ScmProviderHttpServlet {
|
||||
|
||||
private final ScmProviderHttpServlet object;
|
||||
|
||||
public ScmProviderHttpServletDecorator(ScmProviderHttpServlet object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void service(HttpServletRequest request, HttpServletResponse response, Repository repository) throws ServletException, IOException {
|
||||
object.service(request, response, repository);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
object.init(config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import sonia.scm.DecoratorFactory;
|
||||
import sonia.scm.plugin.ExtensionPoint;
|
||||
|
||||
@ExtensionPoint
|
||||
public interface ScmProviderHttpServletDecoratorFactory extends DecoratorFactory<ScmProviderHttpServlet> {
|
||||
/**
|
||||
* Has to return <code>true</code> if this factory provides a decorator for the given scm type (eg. "git", "hg" or
|
||||
* "svn").
|
||||
* @param type The current scm type this factory can provide a decorator for.
|
||||
* @return <code>true</code> when the provided decorator should be used for the given scm type.
|
||||
*/
|
||||
boolean handlesScmType(String type);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import sonia.scm.util.Decorators;
|
||||
|
||||
import javax.inject.Provider;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
public abstract class ScmProviderHttpServletProvider implements Provider<ScmProviderHttpServlet> {
|
||||
|
||||
@Inject(optional = true)
|
||||
private Set<ScmProviderHttpServletDecoratorFactory> decoratorFactories;
|
||||
|
||||
private final String type;
|
||||
|
||||
protected ScmProviderHttpServletProvider(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScmProviderHttpServlet get() {
|
||||
return Decorators.decorate(getRootServlet(), getDecoratorsForType());
|
||||
}
|
||||
|
||||
private List<ScmProviderHttpServletDecoratorFactory> getDecoratorsForType() {
|
||||
return decoratorFactories.stream().filter(d -> d.handlesScmType(type)).collect(toList());
|
||||
}
|
||||
|
||||
protected abstract ScmProviderHttpServlet getRootServlet();
|
||||
}
|
||||
@@ -37,7 +37,6 @@ package sonia.scm.util;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.DecoratorFactory;
|
||||
|
||||
/**
|
||||
@@ -33,39 +33,32 @@
|
||||
|
||||
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;
|
||||
import sonia.scm.repository.RepositoryPermissions;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServletDecorator;
|
||||
import sonia.scm.security.Role;
|
||||
import sonia.scm.security.ScmSecurityException;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Abstract http filter to check repository permissions.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class PermissionFilter extends HttpFilter
|
||||
public abstract class PermissionFilter extends ScmProviderHttpServletDecorator
|
||||
{
|
||||
|
||||
/** the logger for PermissionFilter */
|
||||
@@ -81,23 +74,14 @@ public abstract class PermissionFilter extends HttpFilter
|
||||
*
|
||||
* @since 1.21
|
||||
*/
|
||||
public PermissionFilter(ScmConfiguration configuration)
|
||||
protected PermissionFilter(ScmConfiguration configuration, ScmProviderHttpServlet delegate)
|
||||
{
|
||||
super(delegate);
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the requested repository.
|
||||
*
|
||||
*
|
||||
* @param request current http request
|
||||
*
|
||||
* @return requested repository
|
||||
*/
|
||||
protected abstract Repository getRepository(HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* Returns true if the current request is a write request.
|
||||
*
|
||||
@@ -117,66 +101,38 @@ public abstract class PermissionFilter extends HttpFilter
|
||||
*
|
||||
* @param request http request
|
||||
* @param response http response
|
||||
* @param chain filter chain
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ServletException
|
||||
*/
|
||||
@Override
|
||||
protected void doFilter(HttpServletRequest request,
|
||||
HttpServletResponse response, FilterChain chain)
|
||||
public void service(HttpServletRequest request,
|
||||
HttpServletResponse response, Repository repository)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
|
||||
try
|
||||
{
|
||||
Repository repository = getRepository(request);
|
||||
boolean writeRequest = isWriteRequest(request);
|
||||
|
||||
if (repository != null)
|
||||
if (hasPermission(repository, writeRequest))
|
||||
{
|
||||
boolean writeRequest = isWriteRequest(request);
|
||||
logger.trace("{} access to repository {} for user {} granted",
|
||||
getActionAsString(writeRequest), repository.getName(),
|
||||
getUserName(subject));
|
||||
|
||||
if (hasPermission(repository, writeRequest))
|
||||
{
|
||||
logger.trace("{} access to repository {} for user {} granted",
|
||||
getActionAsString(writeRequest), repository.getName(),
|
||||
getUserName(subject));
|
||||
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.info("{} access to repository {} for user {} denied",
|
||||
getActionAsString(writeRequest), repository.getName(),
|
||||
getUserName(subject));
|
||||
|
||||
sendAccessDenied(request, response, subject);
|
||||
}
|
||||
super.service(request, response, repository);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug("repository not found");
|
||||
logger.info("{} access to repository {} for user {} denied",
|
||||
getActionAsString(writeRequest), repository.getName(),
|
||||
getUserName(subject));
|
||||
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
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);
|
||||
@@ -217,29 +173,6 @@ public abstract class PermissionFilter extends HttpFilter
|
||||
HttpUtil.sendUnauthorized(response, configuration.getRealmDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the type of the repositroy from url.
|
||||
*
|
||||
*
|
||||
* @param request http request
|
||||
*
|
||||
* @return type of repository
|
||||
*/
|
||||
private String extractType(HttpServletRequest request)
|
||||
{
|
||||
Iterator<String> it = Splitter.on(
|
||||
HttpUtil.SEPARATOR_PATH).omitEmptyStrings().split(
|
||||
request.getRequestURI()).iterator();
|
||||
String type = it.next();
|
||||
|
||||
if (Util.isNotEmpty(request.getContextPath()))
|
||||
{
|
||||
type = it.next();
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send access denied to the servlet response.
|
||||
*
|
||||
@@ -280,25 +213,6 @@ public abstract class PermissionFilter extends HttpFilter
|
||||
: "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.
|
||||
*
|
||||
|
||||
@@ -1,118 +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 com.google.common.base.Throwables;
|
||||
import com.google.inject.ProvisionException;
|
||||
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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
|
||||
* @param repositoryProvider
|
||||
* @since 1.21
|
||||
*/
|
||||
public ProviderPermissionFilter(ScmConfiguration configuration,
|
||||
RepositoryProvider repositoryProvider)
|
||||
{
|
||||
super(configuration);
|
||||
this.repositoryProvider = repositoryProvider;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected Repository getRepository(HttpServletRequest request)
|
||||
{
|
||||
Repository repository = null;
|
||||
|
||||
try
|
||||
{
|
||||
repository = repositoryProvider.get();
|
||||
}
|
||||
catch (ProvisionException ex)
|
||||
{
|
||||
Throwables.propagateIfPossible(ex.getCause(),
|
||||
IllegalStateException.class, AuthorizationException.class);
|
||||
logger.error("could not get repository from request", ex);
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final RepositoryProvider repositoryProvider;
|
||||
}
|
||||
@@ -1,60 +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.repository;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class RepositoryTest
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCreateUrl()
|
||||
{
|
||||
Repository repository = new Repository("123", "hg", "test", "repo");
|
||||
|
||||
assertEquals("http://localhost:8080/scm/hg/test/repo",
|
||||
repository.createUrl("http://localhost:8080/scm"));
|
||||
assertEquals("http://localhost:8080/scm/hg/test/repo",
|
||||
repository.createUrl("http://localhost:8080/scm/"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package sonia.scm.repository.api;
|
||||
|
||||
import org.junit.Test;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.spi.HttpScmProtocol;
|
||||
import sonia.scm.repository.spi.RepositoryServiceProvider;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.util.IterableUtil.sizeOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class RepositoryServiceTest {
|
||||
|
||||
private final RepositoryServiceProvider provider = mock(RepositoryServiceProvider.class);
|
||||
private final Repository repository = new Repository("", "git", "space", "repo");
|
||||
|
||||
@Test
|
||||
public void shouldReturnMatchingProtocolsFromProvider() {
|
||||
RepositoryService repositoryService = new RepositoryService(null, provider, repository, null, Collections.singleton(new DummyScmProtocolProvider()));
|
||||
Stream<ScmProtocol> supportedProtocols = repositoryService.getSupportedProtocols();
|
||||
|
||||
assertThat(sizeOf(supportedProtocols.collect(Collectors.toList()))).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindKnownProtocol() {
|
||||
RepositoryService repositoryService = new RepositoryService(null, provider, repository, null, Collections.singleton(new DummyScmProtocolProvider()));
|
||||
|
||||
HttpScmProtocol protocol = repositoryService.getProtocol(HttpScmProtocol.class);
|
||||
|
||||
assertThat(protocol).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailForUnknownProtocol() {
|
||||
RepositoryService repositoryService = new RepositoryService(null, provider, repository, null, Collections.singleton(new DummyScmProtocolProvider()));
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
repositoryService.getProtocol(UnknownScmProtocol.class);
|
||||
});
|
||||
}
|
||||
|
||||
private static class DummyHttpProtocol extends HttpScmProtocol {
|
||||
public DummyHttpProtocol(Repository repository) {
|
||||
super(repository, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serve(HttpServletRequest request, HttpServletResponse response, Repository repository, ServletConfig config) {
|
||||
}
|
||||
}
|
||||
|
||||
private static class DummyScmProtocolProvider implements ScmProtocolProvider {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "git";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScmProtocol get(Repository repository) {
|
||||
return new DummyHttpProtocol(repository);
|
||||
}
|
||||
}
|
||||
|
||||
private interface UnknownScmProtocol extends ScmProtocol {}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.junit.jupiter.api.DynamicTest;
|
||||
import org.junit.jupiter.api.TestFactory;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class HttpScmProtocolTest {
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> shouldCreateCorrectUrlsWithContextPath() {
|
||||
return Stream.of("http://localhost/scm", "http://localhost/scm/")
|
||||
.map(url -> assertResultingUrl(url, "http://localhost/scm/repo/space/name"));
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
Stream<DynamicTest> shouldCreateCorrectUrlsWithPort() {
|
||||
return Stream.of("http://localhost:8080", "http://localhost:8080/")
|
||||
.map(url -> assertResultingUrl(url, "http://localhost:8080/repo/space/name"));
|
||||
}
|
||||
|
||||
DynamicTest assertResultingUrl(String baseUrl, String expectedUrl) {
|
||||
String actualUrl = createInstanceOfHttpScmProtocol(baseUrl).getUrl();
|
||||
return DynamicTest.dynamicTest(baseUrl + " -> " + expectedUrl, () -> assertThat(actualUrl).isEqualTo(expectedUrl));
|
||||
}
|
||||
|
||||
private HttpScmProtocol createInstanceOfHttpScmProtocol(String baseUrl) {
|
||||
return new HttpScmProtocol(new Repository("", "", "space", "name"), baseUrl) {
|
||||
@Override
|
||||
protected void serve(HttpServletRequest request, HttpServletResponse response, Repository repository, ServletConfig config) {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.util.Providers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.stubbing.OngoingStubbing;
|
||||
import sonia.scm.api.v2.resources.ScmPathInfo;
|
||||
import sonia.scm.api.v2.resources.ScmPathInfoStore;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
import javax.inject.Provider;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
public class InitializingHttpScmProtocolWrapperTest {
|
||||
|
||||
private static final Repository REPOSITORY = new Repository("", "git", "space", "name");
|
||||
|
||||
@Mock
|
||||
private ScmProviderHttpServlet delegateServlet;
|
||||
@Mock
|
||||
private ScmPathInfoStore pathInfoStore;
|
||||
@Mock
|
||||
private ScmConfiguration scmConfiguration;
|
||||
private Provider<ScmPathInfoStore> pathInfoStoreProvider;
|
||||
|
||||
@Mock
|
||||
private HttpServletRequest request;
|
||||
@Mock
|
||||
private HttpServletResponse response;
|
||||
@Mock
|
||||
private ServletConfig servletConfig;
|
||||
|
||||
private InitializingHttpScmProtocolWrapper wrapper;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
initMocks(this);
|
||||
pathInfoStoreProvider = mock(Provider.class);
|
||||
when(pathInfoStoreProvider.get()).thenReturn(pathInfoStore);
|
||||
|
||||
wrapper = new InitializingHttpScmProtocolWrapper(Providers.of(this.delegateServlet), pathInfoStoreProvider, scmConfiguration) {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "git";
|
||||
}
|
||||
};
|
||||
when(scmConfiguration.getBaseUrl()).thenReturn("http://example.com/scm");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUsePathFromPathInfo() {
|
||||
mockSetPathInfo();
|
||||
|
||||
HttpScmProtocol httpScmProtocol = wrapper.get(REPOSITORY);
|
||||
|
||||
assertEquals("http://example.com/scm/repo/space/name", httpScmProtocol.getUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUseConfigurationWhenPathInfoNotSet() {
|
||||
HttpScmProtocol httpScmProtocol = wrapper.get(REPOSITORY);
|
||||
|
||||
assertEquals("http://example.com/scm/repo/space/name", httpScmProtocol.getUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUseConfigurationWhenNotInRequestScope() {
|
||||
when(pathInfoStoreProvider.get()).thenThrow(new ProvisionException("test"));
|
||||
|
||||
HttpScmProtocol httpScmProtocol = wrapper.get(REPOSITORY);
|
||||
|
||||
assertEquals("http://example.com/scm/repo/space/name", httpScmProtocol.getUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldInitializeAndDelegateRequestThroughFilter() throws ServletException, IOException {
|
||||
HttpScmProtocol httpScmProtocol = wrapper.get(REPOSITORY);
|
||||
|
||||
httpScmProtocol.serve(request, response, servletConfig);
|
||||
|
||||
verify(delegateServlet).init(servletConfig);
|
||||
verify(delegateServlet).service(request, response, REPOSITORY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldInitializeOnlyOnce() throws ServletException, IOException {
|
||||
HttpScmProtocol httpScmProtocol = wrapper.get(REPOSITORY);
|
||||
|
||||
httpScmProtocol.serve(request, response, servletConfig);
|
||||
httpScmProtocol.serve(request, response, servletConfig);
|
||||
|
||||
verify(delegateServlet, times(1)).init(servletConfig);
|
||||
verify(delegateServlet, times(2)).service(request, response, REPOSITORY);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldFailForIllegalScmType() {
|
||||
HttpScmProtocol httpScmProtocol = wrapper.get(new Repository("", "other", "space", "name"));
|
||||
}
|
||||
|
||||
private OngoingStubbing<ScmPathInfo> mockSetPathInfo() {
|
||||
return when(pathInfoStore.get()).thenReturn(() -> URI.create("http://example.com/scm/api/rest/"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package sonia.scm.web.filter;
|
||||
|
||||
import com.github.sdorra.shiro.ShiroRule;
|
||||
import com.github.sdorra.shiro.SubjectAware;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@SubjectAware(configuration = "classpath:sonia/scm/shiro.ini")
|
||||
public class PermissionFilterTest {
|
||||
|
||||
public static final Repository REPOSITORY = new Repository("1", "git", "space", "name");
|
||||
|
||||
@Rule
|
||||
public final ShiroRule shiroRule = new ShiroRule();
|
||||
|
||||
private final ScmProviderHttpServlet delegateServlet = mock(ScmProviderHttpServlet.class);
|
||||
|
||||
private final PermissionFilter permissionFilter = new PermissionFilter(new ScmConfiguration(), delegateServlet) {
|
||||
@Override
|
||||
protected boolean isWriteRequest(HttpServletRequest request) {
|
||||
return writeRequest;
|
||||
}
|
||||
};
|
||||
|
||||
private final HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
private final HttpServletResponse response = mock(HttpServletResponse.class);
|
||||
|
||||
private boolean writeRequest = false;
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "reader", password = "secret")
|
||||
public void shouldPassForReaderOnReadRequest() throws IOException, ServletException {
|
||||
writeRequest = false;
|
||||
|
||||
permissionFilter.service(request, response, REPOSITORY);
|
||||
|
||||
verify(delegateServlet).service(request, response, REPOSITORY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "reader", password = "secret")
|
||||
public void shouldBlockForReaderOnWriteRequest() throws IOException, ServletException {
|
||||
writeRequest = true;
|
||||
|
||||
permissionFilter.service(request, response, REPOSITORY);
|
||||
|
||||
verify(response).sendError(eq(401), anyString());
|
||||
verify(delegateServlet, never()).service(request, response, REPOSITORY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "writer", password = "secret")
|
||||
public void shouldPassForWriterOnWriteRequest() throws IOException, ServletException {
|
||||
writeRequest = true;
|
||||
|
||||
permissionFilter.service(request, response, REPOSITORY);
|
||||
|
||||
verify(delegateServlet).service(request, response, REPOSITORY);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,12 @@
|
||||
[users]
|
||||
trillian = secret, user
|
||||
admin = secret, admin
|
||||
writer = secret, repo_write
|
||||
reader = secret, repo_read
|
||||
unpriv = secret
|
||||
|
||||
[roles]
|
||||
admin = *
|
||||
user = something:*
|
||||
user = something:*
|
||||
repo_read = "repository:read:1"
|
||||
repo_write = "repository:push:1"
|
||||
|
||||
@@ -31,7 +31,7 @@ public class RepositoryUtil {
|
||||
static RepositoryClient createRepositoryClient(String repositoryType, File folder, String username, String password) throws IOException {
|
||||
String httpProtocolUrl = TestData.callRepository(username, password, repositoryType, HttpStatus.SC_OK)
|
||||
.extract()
|
||||
.path("_links.httpProtocol.href");
|
||||
.path("_links.protocol.find{it.name=='http'}.href");
|
||||
|
||||
return REPOSITORY_CLIENT_FACTORY.create(repositoryType, httpProtocolUrl, username, password, folder);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import static de.otto.edison.hal.Links.linkingTo;
|
||||
public abstract class GitConfigToGitConfigDtoMapper extends BaseMapper<GitConfig, GitConfigDto> {
|
||||
|
||||
@Inject
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@AfterMapping
|
||||
void appendLinks(GitConfig config, @MappingTarget GitConfigDto target) {
|
||||
@@ -30,12 +30,12 @@ public abstract class GitConfigToGitConfigDtoMapper extends BaseMapper<GitConfig
|
||||
}
|
||||
|
||||
private String self() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), GitConfigResource.class);
|
||||
LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get(), GitConfigResource.class);
|
||||
return linkBuilder.method("get").parameters().href();
|
||||
}
|
||||
|
||||
private String update() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), GitConfigResource.class);
|
||||
LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get(), GitConfigResource.class);
|
||||
return linkBuilder.method("update").parameters().href();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -71,19 +69,10 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
* @param repository
|
||||
*/
|
||||
public GitRepositoryServiceProvider(GitRepositoryHandler handler,
|
||||
Repository repository)
|
||||
{
|
||||
public GitRepositoryServiceProvider(GitRepositoryHandler handler, Repository repository) {
|
||||
this.handler = handler;
|
||||
this.repository = repository;
|
||||
context = new GitContext(handler.getDirectory(repository));
|
||||
this.context = new GitContext(handler.getDirectory(repository));
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -35,7 +35,6 @@ package sonia.scm.repository.spi;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
@@ -45,51 +44,23 @@ import sonia.scm.repository.Repository;
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Extension
|
||||
public class GitRepositoryServiceResolver implements RepositoryServiceResolver
|
||||
{
|
||||
public class GitRepositoryServiceResolver implements RepositoryServiceResolver {
|
||||
|
||||
/** Field description */
|
||||
public static final String TYPE = "git";
|
||||
private final GitRepositoryHandler handler;
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
@Inject
|
||||
public GitRepositoryServiceResolver(GitRepositoryHandler handler)
|
||||
{
|
||||
public GitRepositoryServiceResolver(GitRepositoryHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
//~--- 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 (GitRepositoryHandler.TYPE_NAME.equalsIgnoreCase(repository.getType())) {
|
||||
provider = new GitRepositoryServiceProvider(handler, repository);
|
||||
}
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private GitRepositoryHandler handler;
|
||||
}
|
||||
|
||||
@@ -1,69 +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;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* Handles git specific basic authentication.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Priority(Filters.PRIORITY_AUTHENTICATION)
|
||||
@WebElement(value = GitServletModule.PATTERN_GIT)
|
||||
public class GitBasicAuthenticationFilter extends AuthenticationFilter
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param configuration scm-manager main configuration
|
||||
* @param webTokenGenerators web token generators
|
||||
*/
|
||||
@Inject
|
||||
public GitBasicAuthenticationFilter(ScmConfiguration configuration,
|
||||
Set<WebTokenGenerator> webTokenGenerators)
|
||||
{
|
||||
super(configuration, webTokenGenerators);
|
||||
}
|
||||
}
|
||||
@@ -33,38 +33,24 @@
|
||||
|
||||
package sonia.scm.web;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.http.server.GitSmartHttpTools;
|
||||
|
||||
import sonia.scm.ClientMessages;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
import sonia.scm.web.filter.ProviderPermissionFilter;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.web.filter.PermissionFilter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import sonia.scm.Priority;
|
||||
import sonia.scm.filter.Filters;
|
||||
import sonia.scm.filter.WebElement;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 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";
|
||||
@@ -83,11 +69,9 @@ public class GitPermissionFilter extends ProviderPermissionFilter
|
||||
* Constructs a new instance of the GitPermissionFilter.
|
||||
*
|
||||
* @param configuration scm main configuration
|
||||
* @param repositoryProvider repository provider
|
||||
*/
|
||||
@Inject
|
||||
public GitPermissionFilter(ScmConfiguration configuration, RepositoryProvider repositoryProvider) {
|
||||
super(configuration, repositoryProvider);
|
||||
public GitPermissionFilter(ScmConfiguration configuration, ScmProviderHttpServlet delegate) {
|
||||
super(configuration, delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,7 +87,7 @@ public class GitPermissionFilter extends ProviderPermissionFilter
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isWriteRequest(HttpServletRequest request) {
|
||||
public boolean isWriteRequest(HttpServletRequest request) {
|
||||
return isReceivePackRequest(request) ||
|
||||
isReceiveServiceRequest(request) ||
|
||||
isLfsFileUpload(request);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServletDecoratorFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@Extension
|
||||
public class GitPermissionFilterFactory implements ScmProviderHttpServletDecoratorFactory {
|
||||
|
||||
private final ScmConfiguration configuration;
|
||||
|
||||
@Inject
|
||||
public GitPermissionFilterFactory(ScmConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlesScmType(String type) {
|
||||
return GitRepositoryHandler.TYPE_NAME.equals(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScmProviderHttpServlet createDecorator(ScmProviderHttpServlet delegate) {
|
||||
return new GitPermissionFilter(configuration, delegate);
|
||||
}
|
||||
}
|
||||
@@ -125,8 +125,9 @@ public class GitRepositoryResolver implements RepositoryResolver<HttpServletRequ
|
||||
throw new ServiceNotEnabledException();
|
||||
}
|
||||
}
|
||||
catch (RuntimeException | IOException e)
|
||||
catch (IOException e)
|
||||
{
|
||||
// REVIEW
|
||||
throw new RepositoryNotFoundException(repositoryName, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +278,6 @@ public class GitRepositoryViewer
|
||||
{
|
||||
//J-
|
||||
ChangesetPagingResult cpr = service.getLogCommand()
|
||||
.setDisableEscaping(true)
|
||||
.setBranch(name)
|
||||
.setPagingLimit(CHANGESET_PER_BRANCH)
|
||||
.getChangesets();
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import sonia.scm.api.v2.resources.ScmPathInfoStore;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.spi.InitializingHttpScmProtocolWrapper;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
@Extension
|
||||
public class GitScmProtocolProviderWrapper extends InitializingHttpScmProtocolWrapper {
|
||||
@Inject
|
||||
public GitScmProtocolProviderWrapper(ScmGitServletProvider servletProvider, Provider<ScmPathInfoStore> uriInfoStore, ScmConfiguration scmConfiguration) {
|
||||
super(servletProvider, uriInfoStore, scmConfiguration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return GitRepositoryHandler.TYPE_NAME;
|
||||
}
|
||||
}
|
||||
@@ -51,18 +51,6 @@ import sonia.scm.web.lfs.LfsBlobStoreFactory;
|
||||
public class GitServletModule extends ServletModule
|
||||
{
|
||||
|
||||
public static final String GIT_PATH = "/git";
|
||||
|
||||
/** Field description */
|
||||
public static final String PATTERN_GIT = GIT_PATH + "/*";
|
||||
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
protected void configureServlets()
|
||||
{
|
||||
@@ -75,8 +63,5 @@ public class GitServletModule extends ServletModule
|
||||
|
||||
bind(GitConfigDtoToGitConfigMapper.class).to(Mappers.getMapper(GitConfigDtoToGitConfigMapper.class).getClass());
|
||||
bind(GitConfigToGitConfigDtoMapper.class).to(Mappers.getMapper(GitConfigToGitConfigDtoMapper.class).getClass());
|
||||
|
||||
// serlvelts and filters
|
||||
serve(PATTERN_GIT).with(ScmGitServlet.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -42,8 +40,8 @@ import org.eclipse.jgit.http.server.GitServlet;
|
||||
import org.eclipse.jgit.lfs.lib.Constants;
|
||||
import org.slf4j.Logger;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
import sonia.scm.repository.RepositoryRequestListenerUtil;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.web.lfs.servlet.LfsServletFactory;
|
||||
|
||||
@@ -57,19 +55,18 @@ 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
|
||||
*/
|
||||
@Singleton
|
||||
public class ScmGitServlet extends GitServlet
|
||||
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)^/git/(.*/(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))$"
|
||||
"(?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))$"
|
||||
);
|
||||
|
||||
/** Field description */
|
||||
@@ -88,7 +85,6 @@ public class ScmGitServlet extends GitServlet
|
||||
* @param repositoryResolver
|
||||
* @param receivePackFactory
|
||||
* @param repositoryViewer
|
||||
* @param repositoryProvider
|
||||
* @param repositoryRequestListenerUtil
|
||||
* @param lfsServletFactory
|
||||
*/
|
||||
@@ -96,11 +92,9 @@ public class ScmGitServlet extends GitServlet
|
||||
public ScmGitServlet(GitRepositoryResolver repositoryResolver,
|
||||
GitReceivePackFactory receivePackFactory,
|
||||
GitRepositoryViewer repositoryViewer,
|
||||
RepositoryProvider repositoryProvider,
|
||||
RepositoryRequestListenerUtil repositoryRequestListenerUtil,
|
||||
LfsServletFactory lfsServletFactory)
|
||||
{
|
||||
this.repositoryProvider = repositoryProvider;
|
||||
this.repositoryViewer = repositoryViewer;
|
||||
this.repositoryRequestListenerUtil = repositoryRequestListenerUtil;
|
||||
this.lfsServletFactory = lfsServletFactory;
|
||||
@@ -122,44 +116,9 @@ public class ScmGitServlet extends GitServlet
|
||||
* @throws ServletException
|
||||
*/
|
||||
@Override
|
||||
protected void service(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
public void service(HttpServletRequest request, HttpServletResponse response, Repository repository)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
Repository repository = repositoryProvider.get();
|
||||
if (repository != null) {
|
||||
handleRequest(request, response, repository);
|
||||
} else {
|
||||
// logger
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides the type request being currently made and delegates it accordingly.
|
||||
* <ul>
|
||||
* <li>Batch API:</li>
|
||||
* <ul>
|
||||
* <li>used to provide the client with information on how handle the large files of a repository.</li>
|
||||
* <li>response contains the information where to perform the actual upload and download of the large objects.</li>
|
||||
* </ul>
|
||||
* <li>Transfer API:</li>
|
||||
* <ul>
|
||||
* <li>receives and provides the actual large objects (resolves the pointer placed in the file of the working copy).</li>
|
||||
* <li>invoked only after the Batch API has been questioned about what to do with the large files</li>
|
||||
* </ul>
|
||||
* <li>Regular Git Http API:</li>
|
||||
* <ul>
|
||||
* <li>regular git http wire protocol, use by normal git clients.</li>
|
||||
* </ul>
|
||||
* <li>Browser Overview:<li>
|
||||
* <ul>
|
||||
* <li>short repository overview for browser clients.</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
*/
|
||||
private void handleRequest(HttpServletRequest request, HttpServletResponse response, Repository repository) throws ServletException, IOException {
|
||||
String repoPath = repository.getNamespace() + "/" + repository.getName();
|
||||
logger.trace("handle git repository at {}", repoPath);
|
||||
if (isLfsBatchApiRequest(request, repoPath)) {
|
||||
@@ -210,7 +169,7 @@ public class ScmGitServlet extends GitServlet
|
||||
* @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) {
|
||||
@@ -229,7 +188,7 @@ public class ScmGitServlet extends GitServlet
|
||||
*/
|
||||
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");
|
||||
@@ -248,7 +207,7 @@ public class ScmGitServlet extends GitServlet
|
||||
*/
|
||||
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());
|
||||
@@ -284,12 +243,8 @@ public class ScmGitServlet extends GitServlet
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final RepositoryProvider repositoryProvider;
|
||||
|
||||
/** Field description */
|
||||
private final RepositoryRequestListenerUtil repositoryRequestListenerUtil;
|
||||
|
||||
@@ -299,5 +254,4 @@ public class ScmGitServlet extends GitServlet
|
||||
private final GitRepositoryViewer repositoryViewer;
|
||||
|
||||
private final LfsServletFactory lfsServletFactory;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServletProvider;
|
||||
|
||||
import javax.inject.Provider;
|
||||
|
||||
public class ScmGitServletProvider extends ScmProviderHttpServletProvider {
|
||||
|
||||
@Inject
|
||||
private Provider<ScmGitServlet> servletProvider;
|
||||
|
||||
public ScmGitServletProvider() {
|
||||
super(GitRepositoryHandler.TYPE_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ScmProviderHttpServlet getRootServlet() {
|
||||
return servletProvider.get();
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class LfsServletFactory {
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static String buildBaseUri(Repository repository, HttpServletRequest request) {
|
||||
return String.format("%s/git/%s/%s.git/info/lfs/objects/", HttpUtil.getCompleteUrl(request), repository.getNamespace(), repository.getName());
|
||||
return String.format("%s/repo/%s/%s.git/info/lfs/objects/", HttpUtil.getCompleteUrl(request), repository.getNamespace(), repository.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class GitConfigResourceTest {
|
||||
private GitConfigDtoToGitConfigMapperImpl dtoToConfigMapper;
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@InjectMocks
|
||||
private GitConfigToGitConfigDtoMapperImpl configToDtoMapper;
|
||||
@@ -67,7 +67,7 @@ public class GitConfigResourceTest {
|
||||
when(repositoryHandler.getConfig()).thenReturn(gitConfig);
|
||||
GitConfigResource gitConfigResource = new GitConfigResource(dtoToConfigMapper, configToDtoMapper, repositoryHandler);
|
||||
dispatcher.getRegistry().addSingletonResource(gitConfigResource);
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,7 +28,7 @@ public class GitConfigToGitConfigDtoMapperTest {
|
||||
private URI baseUri = URI.create("http://example.com/base/");
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@InjectMocks
|
||||
private GitConfigToGitConfigDtoMapperImpl mapper;
|
||||
@@ -40,7 +40,7 @@ public class GitConfigToGitConfigDtoMapperTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
|
||||
expectedBaseUri = baseUri.resolve(GitConfigResource.GIT_CONFIG_PATH_V2);
|
||||
subjectThreadState.bind();
|
||||
ThreadContext.bind(subject);
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
@@ -29,12 +29,7 @@ import static org.mockito.Mockito.when;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class GitPermissionFilterTest {
|
||||
|
||||
@Mock
|
||||
private RepositoryProvider repositoryProvider;
|
||||
|
||||
private final GitPermissionFilter permissionFilter = new GitPermissionFilter(
|
||||
new ScmConfiguration(), repositoryProvider
|
||||
);
|
||||
private final GitPermissionFilter permissionFilter = new GitPermissionFilter(new ScmConfiguration(), mock(ScmProviderHttpServlet.class));
|
||||
|
||||
@Mock
|
||||
private HttpServletResponse response;
|
||||
|
||||
@@ -23,12 +23,12 @@ public class LfsServletFactoryTest {
|
||||
String repositoryName = "git-lfs-demo";
|
||||
|
||||
String result = LfsServletFactory.buildBaseUri(new Repository("", "GIT", repositoryNamespace, repositoryName), RequestWithUri(repositoryName, true));
|
||||
assertThat(result, is(equalTo("http://localhost:8081/scm/git/space/git-lfs-demo.git/info/lfs/objects/")));
|
||||
assertThat(result, is(equalTo("http://localhost:8081/scm/repo/space/git-lfs-demo.git/info/lfs/objects/")));
|
||||
|
||||
|
||||
//result will be with dot-git suffix, ide
|
||||
result = LfsServletFactory.buildBaseUri(new Repository("", "GIT", repositoryNamespace, repositoryName), RequestWithUri(repositoryName, false));
|
||||
assertThat(result, is(equalTo("http://localhost:8081/scm/git/space/git-lfs-demo.git/info/lfs/objects/")));
|
||||
assertThat(result, is(equalTo("http://localhost:8081/scm/repo/space/git-lfs-demo.git/info/lfs/objects/")));
|
||||
}
|
||||
|
||||
private HttpServletRequest RequestWithUri(String repositoryName, boolean withDotGitSuffix) {
|
||||
@@ -44,12 +44,10 @@ public class LfsServletFactoryTest {
|
||||
|
||||
//build from valid live request data
|
||||
when(mockedRequest.getRequestURL()).thenReturn(
|
||||
new StringBuffer(String.format("http://localhost:8081/scm/git/%s%s/info/lfs/objects/batch", repositoryName, suffix)));
|
||||
when(mockedRequest.getRequestURI()).thenReturn(String.format("/scm/git/%s%s/info/lfs/objects/batch", repositoryName, suffix));
|
||||
new StringBuffer(String.format("http://localhost:8081/scm/repo/%s%s/info/lfs/objects/batch", repositoryName, suffix)));
|
||||
when(mockedRequest.getRequestURI()).thenReturn(String.format("/scm/repo/%s%s/info/lfs/objects/batch", repositoryName, suffix));
|
||||
when(mockedRequest.getContextPath()).thenReturn("/scm");
|
||||
|
||||
return mockedRequest;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ import static de.otto.edison.hal.Links.linkingTo;
|
||||
|
||||
public class HgConfigInstallationsToDtoMapper {
|
||||
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@Inject
|
||||
public HgConfigInstallationsToDtoMapper(UriInfoStore uriInfoStore) {
|
||||
this.uriInfoStore = uriInfoStore;
|
||||
public HgConfigInstallationsToDtoMapper(ScmPathInfoStore scmPathInfoStore) {
|
||||
this.scmPathInfoStore = scmPathInfoStore;
|
||||
}
|
||||
|
||||
public HgConfigInstallationsDto map(List<String> installations, String path) {
|
||||
@@ -20,7 +20,7 @@ public class HgConfigInstallationsToDtoMapper {
|
||||
}
|
||||
|
||||
private String createSelfLink(String path) {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), HgConfigResource.class);
|
||||
LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get(), HgConfigResource.class);
|
||||
return linkBuilder.method("getInstallationsResource").parameters().href() + '/' + path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import static de.otto.edison.hal.Links.linkingTo;
|
||||
public abstract class HgConfigPackagesToDtoMapper {
|
||||
|
||||
@Inject
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
public HgConfigPackagesDto map(HgPackages hgpackages) {
|
||||
return map(new HgPackagesNonIterable(hgpackages));
|
||||
@@ -40,7 +40,7 @@ public abstract class HgConfigPackagesToDtoMapper {
|
||||
}
|
||||
|
||||
private String createSelfLink() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), HgConfigResource.class);
|
||||
LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get(), HgConfigResource.class);
|
||||
return linkBuilder.method("getPackagesResource").parameters().href();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import static de.otto.edison.hal.Links.linkingTo;
|
||||
public abstract class HgConfigToHgConfigDtoMapper extends BaseMapper<HgConfig, HgConfigDto> {
|
||||
|
||||
@Inject
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@AfterMapping
|
||||
void appendLinks(HgConfig config, @MappingTarget HgConfigDto target) {
|
||||
@@ -30,12 +30,12 @@ public abstract class HgConfigToHgConfigDtoMapper extends BaseMapper<HgConfig, H
|
||||
}
|
||||
|
||||
private String self() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), HgConfigResource.class);
|
||||
LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get(), HgConfigResource.class);
|
||||
return linkBuilder.method("get").parameters().href();
|
||||
}
|
||||
|
||||
private String update() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), HgConfigResource.class);
|
||||
LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get(), HgConfigResource.class);
|
||||
return linkBuilder.method("update").parameters().href();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,7 @@
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
import sonia.scm.repository.Feature;
|
||||
import sonia.scm.repository.HgHookManager;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
@@ -44,11 +41,8 @@ import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.Command;
|
||||
import sonia.scm.repository.api.CommandNotSupportedException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -82,16 +76,6 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param hookManager
|
||||
* @param handler
|
||||
* @param repository
|
||||
*/
|
||||
HgRepositoryServiceProvider(HgRepositoryHandler handler,
|
||||
HgHookManager hookManager, Repository repository)
|
||||
{
|
||||
|
||||
@@ -33,10 +33,7 @@
|
||||
|
||||
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;
|
||||
@@ -50,19 +47,9 @@ import sonia.scm.repository.Repository;
|
||||
public class HgRepositoryServiceResolver implements RepositoryServiceResolver
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String TYPE = "hg";
|
||||
private HgRepositoryHandler handler;
|
||||
private HgHookManager hookManager;
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param hookManager
|
||||
* @param handler
|
||||
*/
|
||||
@Inject
|
||||
public HgRepositoryServiceResolver(HgRepositoryHandler handler,
|
||||
HgHookManager hookManager)
|
||||
@@ -71,35 +58,14 @@ public class HgRepositoryServiceResolver implements RepositoryServiceResolver
|
||||
this.hookManager = hookManager;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public HgRepositoryServiceProvider resolve(Repository repository)
|
||||
{
|
||||
public HgRepositoryServiceProvider resolve(Repository repository) {
|
||||
HgRepositoryServiceProvider provider = null;
|
||||
|
||||
if (TYPE.equalsIgnoreCase(repository.getType()))
|
||||
{
|
||||
provider = new HgRepositoryServiceProvider(handler, hookManager,
|
||||
repository);
|
||||
if (HgRepositoryHandler.TYPE_NAME.equalsIgnoreCase(repository.getType())) {
|
||||
provider = new HgRepositoryServiceProvider(handler, hookManager, repository);
|
||||
}
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private HgRepositoryHandler handler;
|
||||
|
||||
/** Field description */
|
||||
private HgHookManager hookManager;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -49,8 +47,8 @@ import sonia.scm.repository.HgHookManager;
|
||||
import sonia.scm.repository.HgPythonScript;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
import sonia.scm.repository.RepositoryRequestListenerUtil;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.security.CipherUtil;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
@@ -68,14 +66,12 @@ import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.Enumeration;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
public class HgCGIServlet extends HttpServlet
|
||||
public class HgCGIServlet extends HttpServlet implements ScmProviderHttpServlet
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
@@ -108,20 +104,18 @@ public class HgCGIServlet extends HttpServlet
|
||||
*
|
||||
* @param cgiExecutorFactory
|
||||
* @param configuration
|
||||
* @param repositoryProvider
|
||||
* @param handler
|
||||
* @param hookManager
|
||||
* @param requestListenerUtil
|
||||
*/
|
||||
@Inject
|
||||
public HgCGIServlet(CGIExecutorFactory cgiExecutorFactory,
|
||||
ScmConfiguration configuration, RepositoryProvider repositoryProvider,
|
||||
ScmConfiguration configuration,
|
||||
HgRepositoryHandler handler, HgHookManager hookManager,
|
||||
RepositoryRequestListenerUtil requestListenerUtil)
|
||||
{
|
||||
this.cgiExecutorFactory = cgiExecutorFactory;
|
||||
this.configuration = configuration;
|
||||
this.repositoryProvider = repositoryProvider;
|
||||
this.handler = handler;
|
||||
this.hookManager = hookManager;
|
||||
this.requestListenerUtil = requestListenerUtil;
|
||||
@@ -131,46 +125,11 @@ public class HgCGIServlet extends HttpServlet
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws ServletException
|
||||
*/
|
||||
@Override
|
||||
public void init() throws ServletException
|
||||
public void service(HttpServletRequest request,
|
||||
HttpServletResponse response, Repository repository)
|
||||
{
|
||||
|
||||
super.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ServletException
|
||||
*/
|
||||
@Override
|
||||
protected void service(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
Repository repository = repositoryProvider.get();
|
||||
|
||||
if (repository == null)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("no hg repository found at {}", request.getRequestURI());
|
||||
}
|
||||
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
else if (!handler.isConfigured())
|
||||
if (!handler.isConfigured())
|
||||
{
|
||||
exceptionHandler.sendFormattedError(request, response,
|
||||
HgCGIExceptionHandler.ERROR_NOT_CONFIGURED);
|
||||
@@ -379,9 +338,6 @@ public class HgCGIServlet extends HttpServlet
|
||||
/** Field description */
|
||||
private final HgHookManager hookManager;
|
||||
|
||||
/** Field description */
|
||||
private final RepositoryProvider repositoryProvider;
|
||||
|
||||
/** Field description */
|
||||
private final RepositoryRequestListenerUtil requestListenerUtil;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServletProvider;
|
||||
|
||||
import javax.inject.Provider;
|
||||
|
||||
public class HgCGIServletProvider extends ScmProviderHttpServletProvider {
|
||||
|
||||
@Inject
|
||||
private Provider<HgCGIServlet> servletProvider;
|
||||
|
||||
public HgCGIServletProvider() {
|
||||
super(HgRepositoryHandler.TYPE_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ScmProviderHttpServlet getRootServlet() {
|
||||
return servletProvider.get();
|
||||
}
|
||||
}
|
||||
@@ -33,53 +33,31 @@
|
||||
|
||||
package sonia.scm.web;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
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 java.util.Set;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.web.filter.PermissionFilter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param repositoryProvider repository provider
|
||||
*/
|
||||
@Inject
|
||||
public HgPermissionFilter(ScmConfiguration configuration,
|
||||
RepositoryProvider repositoryProvider)
|
||||
public HgPermissionFilter(ScmConfiguration configuration, ScmProviderHttpServlet delegate)
|
||||
{
|
||||
super(configuration, repositoryProvider);
|
||||
super(configuration, delegate);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
@Override
|
||||
protected boolean isWriteRequest(HttpServletRequest request)
|
||||
public boolean isWriteRequest(HttpServletRequest request)
|
||||
{
|
||||
return !READ_METHODS.contains(request.getMethod());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServletDecoratorFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@Extension
|
||||
public class HgPermissionFilterFactory implements ScmProviderHttpServletDecoratorFactory {
|
||||
|
||||
private final ScmConfiguration configuration;
|
||||
|
||||
@Inject
|
||||
public HgPermissionFilterFactory(ScmConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlesScmType(String type) {
|
||||
return HgRepositoryHandler.TYPE_NAME.equals(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScmProviderHttpServlet createDecorator(ScmProviderHttpServlet delegate) {
|
||||
return new HgPermissionFilter(configuration, delegate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import sonia.scm.api.v2.resources.ScmPathInfoStore;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.repository.spi.InitializingHttpScmProtocolWrapper;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
@Extension
|
||||
public class HgScmProtocolProviderWrapper extends InitializingHttpScmProtocolWrapper {
|
||||
@Inject
|
||||
public HgScmProtocolProviderWrapper(HgCGIServletProvider servletProvider, Provider<ScmPathInfoStore> uriInfoStore, ScmConfiguration scmConfiguration) {
|
||||
super(servletProvider, uriInfoStore, scmConfiguration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return HgRepositoryHandler.TYPE_NAME;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class HgConfigInstallationsResourceTest {
|
||||
private final URI baseUri = URI.create("/");
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@InjectMocks
|
||||
private HgConfigInstallationsToDtoMapper mapper;
|
||||
@@ -61,7 +61,7 @@ public class HgConfigInstallationsResourceTest {
|
||||
new HgConfigResource(null, null, null, null,
|
||||
null, resourceProvider));
|
||||
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,7 +23,7 @@ public class HgConfigInstallationsToDtoMapperTest {
|
||||
private URI baseUri = URI.create("http://example.com/base/");
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@InjectMocks
|
||||
private HgConfigInstallationsToDtoMapper mapper;
|
||||
@@ -34,7 +34,7 @@ public class HgConfigInstallationsToDtoMapperTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
|
||||
expectedBaseUri = baseUri.resolve(HgConfigResource.HG_CONFIG_PATH_V2 + "/installations/" + expectedPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class HgConfigPackageResourceTest {
|
||||
private final URI baseUri = java.net.URI.create("/");
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@InjectMocks
|
||||
private HgConfigPackagesToDtoMapperImpl mapper;
|
||||
@@ -81,7 +81,7 @@ public class HgConfigPackageResourceTest {
|
||||
public void prepareEnvironment() {
|
||||
setupResources();
|
||||
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
|
||||
|
||||
when(hgPackageReader.getPackages().getPackages()).thenReturn(createPackages());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -13,12 +12,10 @@ import sonia.scm.installer.HgPackages;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static sonia.scm.api.v2.resources.HgConfigTests.assertEqualsPackage;
|
||||
import static sonia.scm.api.v2.resources.HgConfigTests.createPackage;
|
||||
@@ -29,7 +26,7 @@ public class HgConfigPackagesToDtoMapperTest {
|
||||
private URI baseUri = URI.create("http://example.com/base/");
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@InjectMocks
|
||||
private HgConfigPackagesToDtoMapperImpl mapper;
|
||||
@@ -38,7 +35,7 @@ public class HgConfigPackagesToDtoMapperTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
|
||||
expectedBaseUri = baseUri.resolve(HgConfigResource.HG_CONFIG_PATH_V2 + "/packages");
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class HgConfigResourceTest {
|
||||
private HgConfigDtoToHgConfigMapperImpl dtoToConfigMapper;
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@InjectMocks
|
||||
private HgConfigToHgConfigDtoMapperImpl configToDtoMapper;
|
||||
@@ -79,7 +79,7 @@ public class HgConfigResourceTest {
|
||||
new HgConfigResource(dtoToConfigMapper, configToDtoMapper, repositoryHandler, packagesResource,
|
||||
autoconfigResource, installationsResource);
|
||||
dispatcher.getRegistry().addSingletonResource(gitConfigResource);
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -29,7 +29,7 @@ public class HgConfigToHgConfigDtoMapperTest {
|
||||
private URI baseUri = URI.create("http://example.com/base/");
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@InjectMocks
|
||||
private HgConfigToHgConfigDtoMapperImpl mapper;
|
||||
@@ -41,7 +41,7 @@ public class HgConfigToHgConfigDtoMapperTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
|
||||
expectedBaseUri = baseUri.resolve(HgConfigResource.HG_CONFIG_PATH_V2);
|
||||
subjectThreadState.bind();
|
||||
ThreadContext.bind(subject);
|
||||
|
||||
@@ -18,7 +18,7 @@ import static de.otto.edison.hal.Links.linkingTo;
|
||||
public abstract class SvnConfigToSvnConfigDtoMapper extends BaseMapper<SvnConfig, SvnConfigDto> {
|
||||
|
||||
@Inject
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@AfterMapping
|
||||
void appendLinks(SvnConfig config, @MappingTarget SvnConfigDto target) {
|
||||
@@ -30,12 +30,12 @@ public abstract class SvnConfigToSvnConfigDtoMapper extends BaseMapper<SvnConfig
|
||||
}
|
||||
|
||||
private String self() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), SvnConfigResource.class);
|
||||
LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get(), SvnConfigResource.class);
|
||||
return linkBuilder.method("get").parameters().href();
|
||||
}
|
||||
|
||||
private String update() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), SvnConfigResource.class);
|
||||
LinkBuilder linkBuilder = new LinkBuilder(scmPathInfoStore.get(), SvnConfigResource.class);
|
||||
return linkBuilder.method("update").parameters().href();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,19 +33,13 @@
|
||||
|
||||
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;
|
||||
import sonia.scm.repository.SvnRepositoryHandler;
|
||||
import sonia.scm.repository.api.Command;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -65,13 +59,6 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
* @param repository
|
||||
*/
|
||||
SvnRepositoryServiceProvider(SvnRepositoryHandler handler,
|
||||
Repository repository)
|
||||
{
|
||||
|
||||
@@ -32,64 +32,29 @@
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Extension
|
||||
public class SvnRepositoryServiceResolver implements RepositoryServiceResolver
|
||||
{
|
||||
public class SvnRepositoryServiceResolver implements RepositoryServiceResolver {
|
||||
|
||||
/** Field description */
|
||||
public static final String TYPE = "svn";
|
||||
private SvnRepositoryHandler handler;
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
@Inject
|
||||
public SvnRepositoryServiceResolver(SvnRepositoryHandler handler)
|
||||
{
|
||||
public SvnRepositoryServiceResolver(SvnRepositoryHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
//~--- 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 (SvnRepositoryHandler.TYPE_NAME.equalsIgnoreCase(repository.getType())) {
|
||||
provider = new SvnRepositoryServiceProvider(handler, repository);
|
||||
}
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private SvnRepositoryHandler handler;
|
||||
}
|
||||
|
||||
@@ -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.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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -45,6 +43,7 @@ import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
import sonia.scm.repository.RepositoryRequestListenerUtil;
|
||||
import sonia.scm.repository.SvnRepositoryHandler;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
|
||||
@@ -54,14 +53,12 @@ import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
public class SvnDAVServlet extends DAVServlet
|
||||
public class SvnDAVServlet extends DAVServlet implements ScmProviderHttpServlet
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
@@ -110,28 +107,18 @@ public class SvnDAVServlet extends DAVServlet
|
||||
* @throws ServletException
|
||||
*/
|
||||
@Override
|
||||
public void service(HttpServletRequest request, HttpServletResponse response)
|
||||
public void service(HttpServletRequest request, HttpServletResponse response, Repository repository)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
Repository repository = repositoryProvider.get();
|
||||
|
||||
if (repository != null)
|
||||
{
|
||||
if (repositoryRequestListenerUtil.callListeners(request, response,
|
||||
repository))
|
||||
{
|
||||
super.service(new SvnHttpServletRequestWrapper(request,
|
||||
repositoryProvider), response);
|
||||
}
|
||||
else if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("request aborted by repository request listener");
|
||||
}
|
||||
}
|
||||
else
|
||||
if (repositoryRequestListenerUtil.callListeners(request, response,
|
||||
repository))
|
||||
{
|
||||
super.service(new SvnHttpServletRequestWrapper(request,
|
||||
repositoryProvider), response);
|
||||
repository), response);
|
||||
}
|
||||
else if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("request aborted by repository request listener");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,18 +150,11 @@ public class SvnDAVServlet extends DAVServlet
|
||||
extends HttpServletRequestWrapper
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param repositoryProvider
|
||||
*/
|
||||
public SvnHttpServletRequestWrapper(HttpServletRequest request,
|
||||
RepositoryProvider repositoryProvider)
|
||||
Repository repository)
|
||||
{
|
||||
super(request);
|
||||
this.repositoryProvider = repositoryProvider;
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
//~--- get methods --------------------------------------------------------
|
||||
@@ -211,8 +191,6 @@ public class SvnDAVServlet extends DAVServlet
|
||||
|
||||
AssertUtil.assertIsNotEmpty(pathInfo);
|
||||
|
||||
Repository repository = repositoryProvider.get();
|
||||
|
||||
if (repository != null)
|
||||
{
|
||||
if (pathInfo.startsWith(HttpUtil.SEPARATOR_PATH))
|
||||
@@ -236,7 +214,6 @@ public class SvnDAVServlet extends DAVServlet
|
||||
public String getServletPath()
|
||||
{
|
||||
String servletPath = super.getServletPath();
|
||||
Repository repository = repositoryProvider.get();
|
||||
|
||||
if (repository != null)
|
||||
{
|
||||
@@ -280,10 +257,9 @@ public class SvnDAVServlet extends DAVServlet
|
||||
//~--- fields -------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final RepositoryProvider repositoryProvider;
|
||||
private final Repository repository;
|
||||
}
|
||||
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import sonia.scm.repository.SvnRepositoryHandler;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServletProvider;
|
||||
|
||||
import javax.inject.Provider;
|
||||
|
||||
public class SvnDAVServletProvider extends ScmProviderHttpServletProvider {
|
||||
|
||||
@Inject
|
||||
private Provider<SvnDAVServlet> servletProvider;
|
||||
|
||||
public SvnDAVServletProvider() {
|
||||
super(SvnRepositoryHandler.TYPE_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ScmProviderHttpServlet getRootServlet() {
|
||||
return servletProvider.get();
|
||||
}
|
||||
}
|
||||
@@ -34,38 +34,34 @@ package sonia.scm.web;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.filter.GZipFilter;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.SvnRepositoryHandler;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
public class SvnGZipFilter extends GZipFilter
|
||||
public class SvnGZipFilter extends GZipFilter implements ScmProviderHttpServlet
|
||||
{
|
||||
|
||||
/**
|
||||
* the logger for SvnGZipFilter
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(SvnGZipFilter.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(SvnGZipFilter.class);
|
||||
|
||||
private final SvnRepositoryHandler handler;
|
||||
private final ScmProviderHttpServlet delegate;
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
@@ -75,10 +71,10 @@ public class SvnGZipFilter extends GZipFilter
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
@Inject
|
||||
public SvnGZipFilter(SvnRepositoryHandler handler)
|
||||
public SvnGZipFilter(SvnRepositoryHandler handler, ScmProviderHttpServlet delegate)
|
||||
{
|
||||
this.handler = handler;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -134,8 +130,30 @@ public class SvnGZipFilter extends GZipFilter
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
@Override
|
||||
public void service(HttpServletRequest request, HttpServletResponse response, Repository repository) throws ServletException, IOException {
|
||||
if (handler.getConfig().isEnabledGZip())
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("encode svn request with gzip");
|
||||
}
|
||||
|
||||
/** Field description */
|
||||
private SvnRepositoryHandler handler;
|
||||
super.doFilter(request, response, (servletRequest, servletResponse) -> delegate.service((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, repository));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("skip gzip encoding");
|
||||
}
|
||||
|
||||
delegate.service(request, response, repository);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
delegate.init(config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.SvnRepositoryHandler;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServletDecoratorFactory;
|
||||
|
||||
@Extension
|
||||
public class SvnGZipFilterFactory implements ScmProviderHttpServletDecoratorFactory {
|
||||
|
||||
private final SvnRepositoryHandler handler;
|
||||
|
||||
@Inject
|
||||
public SvnGZipFilterFactory(SvnRepositoryHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlesScmType(String type) {
|
||||
return SvnRepositoryHandler.TYPE_NAME.equals(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScmProviderHttpServlet createDecorator(ScmProviderHttpServlet delegate) {
|
||||
return new SvnGZipFilter(handler, delegate);
|
||||
}
|
||||
}
|
||||
@@ -33,37 +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.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 sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.web.filter.PermissionFilter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Priority(Filters.PRIORITY_AUTHORIZATION)
|
||||
@WebElement(value = SvnServletModule.PATTERN_SVN)
|
||||
public class SvnPermissionFilter extends ProviderPermissionFilter
|
||||
public class SvnPermissionFilter extends PermissionFilter
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
@@ -77,13 +64,10 @@ public class SvnPermissionFilter extends ProviderPermissionFilter
|
||||
* Constructs ...
|
||||
*
|
||||
* @param configuration
|
||||
* @param repository
|
||||
*/
|
||||
@Inject
|
||||
public SvnPermissionFilter(ScmConfiguration configuration,
|
||||
RepositoryProvider repository)
|
||||
public SvnPermissionFilter(ScmConfiguration configuration, ScmProviderHttpServlet delegate)
|
||||
{
|
||||
super(configuration, repository);
|
||||
super(configuration, delegate);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -132,7 +116,7 @@ public class SvnPermissionFilter extends ProviderPermissionFilter
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected boolean isWriteRequest(HttpServletRequest request)
|
||||
public boolean isWriteRequest(HttpServletRequest request)
|
||||
{
|
||||
return WRITEMETHOD_SET.contains(request.getMethod().toUpperCase());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.SvnRepositoryHandler;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServletDecoratorFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@Extension
|
||||
public class SvnPermissionFilterFactory implements ScmProviderHttpServletDecoratorFactory {
|
||||
|
||||
private final ScmConfiguration configuration;
|
||||
|
||||
@Inject
|
||||
public SvnPermissionFilterFactory(ScmConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlesScmType(String type) {
|
||||
return SvnRepositoryHandler.TYPE_NAME.equals(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScmProviderHttpServlet createDecorator(ScmProviderHttpServlet delegate) {
|
||||
return new SvnPermissionFilter(configuration, delegate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import sonia.scm.api.v2.resources.ScmPathInfoStore;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.SvnRepositoryHandler;
|
||||
import sonia.scm.repository.spi.InitializingHttpScmProtocolWrapper;
|
||||
import sonia.scm.repository.spi.ScmProviderHttpServlet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
@Singleton
|
||||
@Extension
|
||||
public class SvnScmProtocolProviderWrapper extends InitializingHttpScmProtocolWrapper {
|
||||
|
||||
public static final String PARAMETER_SVN_PARENTPATH = "SVNParentPath";
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return SvnRepositoryHandler.TYPE_NAME;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public SvnScmProtocolProviderWrapper(SvnDAVServletProvider servletProvider, Provider<ScmPathInfoStore> uriInfoStore, ScmConfiguration scmConfiguration) {
|
||||
super(servletProvider, uriInfoStore, scmConfiguration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeServlet(ServletConfig config, ScmProviderHttpServlet httpServlet) throws ServletException {
|
||||
|
||||
super.initializeServlet(new SvnConfigEnhancer(config), httpServlet);
|
||||
}
|
||||
|
||||
private static class SvnConfigEnhancer implements ServletConfig {
|
||||
|
||||
private final ServletConfig originalConfig;
|
||||
|
||||
private SvnConfigEnhancer(ServletConfig originalConfig) {
|
||||
this.originalConfig = originalConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServletName() {
|
||||
return originalConfig.getServletName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletContext getServletContext() {
|
||||
return originalConfig.getServletContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Overridden to return the systems temp directory for the key {@link PARAMETER_SVN_PARENTPATH}.
|
||||
*/
|
||||
public String getInitParameter(String key) {
|
||||
if (PARAMETER_SVN_PARENTPATH.equals(key)) {
|
||||
return System.getProperty("java.io.tmpdir");
|
||||
}
|
||||
return originalConfig.getInitParameter(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration getInitParameterNames() {
|
||||
return originalConfig.getInitParameterNames();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,53 +33,22 @@
|
||||
|
||||
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;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
//~--- 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());
|
||||
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
|
||||
parameters.put(PARAMETER_SVN_PARENTPATH,
|
||||
System.getProperty("java.io.tmpdir"));
|
||||
serve(PATTERN_SVN).with(SvnDAVServlet.class, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class SvnConfigResourceTest {
|
||||
private SvnConfigDtoToSvnConfigMapperImpl dtoToConfigMapper;
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@InjectMocks
|
||||
private SvnConfigToSvnConfigDtoMapperImpl configToDtoMapper;
|
||||
@@ -67,7 +67,7 @@ public class SvnConfigResourceTest {
|
||||
when(repositoryHandler.getConfig()).thenReturn(gitConfig);
|
||||
SvnConfigResource gitConfigResource = new SvnConfigResource(dtoToConfigMapper, configToDtoMapper, repositoryHandler);
|
||||
dispatcher.getRegistry().addSingletonResource(gitConfigResource);
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SvnConfigToSvnConfigDtoMapperTest {
|
||||
private URI baseUri = URI.create("http://example.com/base/");
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
private ScmPathInfoStore scmPathInfoStore;
|
||||
|
||||
@InjectMocks
|
||||
private SvnConfigToSvnConfigDtoMapperImpl mapper;
|
||||
@@ -42,7 +42,7 @@ public class SvnConfigToSvnConfigDtoMapperTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);
|
||||
expectedBaseUri = baseUri.resolve(SvnConfigResource.SVN_CONFIG_PATH_V2);
|
||||
subjectThreadState.bind();
|
||||
ThreadContext.bind(subject);
|
||||
|
||||
8
scm-ui-components/packages/ui-types/src/Branch.js
Normal file
8
scm-ui-components/packages/ui-types/src/Branch.js
Normal file
@@ -0,0 +1,8 @@
|
||||
//@flow
|
||||
import type {Links} from "./hal";
|
||||
|
||||
export type Branch = {
|
||||
name: string,
|
||||
revision: string,
|
||||
_links: Links
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
//@flow
|
||||
import type { Links } from "./hal";
|
||||
import type { Tag } from "./Tags";
|
||||
import type {Links} from "./hal";
|
||||
import type {Tag} from "./Tags";
|
||||
import type {Branch} from "./Branch";
|
||||
|
||||
export type Changeset = {
|
||||
id: string,
|
||||
date: Date,
|
||||
@@ -8,11 +10,16 @@ export type Changeset = {
|
||||
name: string,
|
||||
mail: string
|
||||
},
|
||||
description: string
|
||||
description: string,
|
||||
_links: Links,
|
||||
_embedded: {
|
||||
tags: Tag[]
|
||||
branches: any, //todo: Add correct type
|
||||
parents: any //todo: Add correct type
|
||||
tags: Tag[],
|
||||
branches: Branch[],
|
||||
parents: ParentChangeset[]
|
||||
};
|
||||
}
|
||||
|
||||
export type ParentChangeset = {
|
||||
id: string,
|
||||
_links: Links
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
"id": "ID",
|
||||
"description": "Description",
|
||||
"contact": "Contact",
|
||||
"date": "Date"
|
||||
"date": "Date",
|
||||
"summary": "Changeset {{id}} committed {{time}}"
|
||||
},
|
||||
"author": {
|
||||
"name": "Author",
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// @flow
|
||||
import ChangesetRow from "./ChangesetRow";
|
||||
import React from "react";
|
||||
|
||||
type Props = {
|
||||
changesets: Changeset[]
|
||||
}
|
||||
|
||||
class ChangesetTable extends React.Component<Props> {
|
||||
|
||||
render() {
|
||||
const {changesets} = this.props;
|
||||
return <table className="table is-hoverable is-fullwidth is-striped is-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Changesets</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{changesets.map((changeset, index) => {
|
||||
return <ChangesetRow key={index} changeset={changeset}/>;
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
}
|
||||
|
||||
export default ChangesetTable;
|
||||
@@ -7,7 +7,7 @@ import { routerReducer, routerMiddleware } from "react-router-redux";
|
||||
import users from "./users/modules/users";
|
||||
import repos from "./repos/modules/repos";
|
||||
import repositoryTypes from "./repos/modules/repositoryTypes";
|
||||
import changesets from "./changesets/modules/changesets";
|
||||
import changesets from "./repos/modules/changesets";
|
||||
import groups from "./groups/modules/groups";
|
||||
import auth from "./modules/auth";
|
||||
import pending from "./modules/pending";
|
||||
|
||||
27
scm-ui/src/repos/components/ChangesetAuthor.js
Normal file
27
scm-ui/src/repos/components/ChangesetAuthor.js
Normal file
@@ -0,0 +1,27 @@
|
||||
//@flow
|
||||
|
||||
import React from "react";
|
||||
import type { Changeset } from "@scm-manager/ui-types";
|
||||
|
||||
type Props = {
|
||||
changeset: Changeset
|
||||
};
|
||||
|
||||
export default class ChangesetAuthor extends React.Component<Props> {
|
||||
render() {
|
||||
const { changeset } = this.props;
|
||||
return (
|
||||
<>
|
||||
{changeset.author.name}{" "}
|
||||
<a
|
||||
className="is-hidden-mobile"
|
||||
href={"mailto:" + changeset.author.mail}
|
||||
>
|
||||
<
|
||||
{changeset.author.mail}
|
||||
>
|
||||
</a>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
28
scm-ui/src/repos/components/ChangesetAvatar.js
Normal file
28
scm-ui/src/repos/components/ChangesetAvatar.js
Normal file
@@ -0,0 +1,28 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import {ExtensionPoint} from "@scm-manager/ui-extensions";
|
||||
import type {Changeset} from "@scm-manager/ui-types";
|
||||
import {Image} from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
changeset: Changeset
|
||||
};
|
||||
|
||||
class ChangesetAvatar extends React.Component<Props> {
|
||||
render() {
|
||||
const { changeset } = this.props;
|
||||
return (
|
||||
<p className="image is-64x64">
|
||||
<ExtensionPoint
|
||||
name="repos.changeset-table.information"
|
||||
renderAll={true}
|
||||
props={{ changeset }}
|
||||
>
|
||||
<Image src="/images/blib.jpg" alt="Logo" />
|
||||
</ExtensionPoint>
|
||||
</p>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ChangesetAvatar;
|
||||
25
scm-ui/src/repos/components/ChangesetId.js
Normal file
25
scm-ui/src/repos/components/ChangesetId.js
Normal file
@@ -0,0 +1,25 @@
|
||||
//@flow
|
||||
|
||||
import { Link } from "react-router-dom";
|
||||
import React from "react";
|
||||
import type { Repository, Changeset } from "@scm-manager/ui-types";
|
||||
|
||||
type Props = {
|
||||
repository: Repository,
|
||||
changeset: Changeset
|
||||
};
|
||||
|
||||
export default class ChangesetId extends React.Component<Props> {
|
||||
render() {
|
||||
const { repository, changeset } = this.props;
|
||||
return (
|
||||
<Link
|
||||
to={`/repo/${repository.namespace}/${repository.name}/changeset/${
|
||||
changeset.id
|
||||
}`}
|
||||
>
|
||||
{changeset.id.substr(0, 7)}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
}
|
||||
22
scm-ui/src/repos/components/ChangesetList.js
Normal file
22
scm-ui/src/repos/components/ChangesetList.js
Normal file
@@ -0,0 +1,22 @@
|
||||
// @flow
|
||||
import ChangesetRow from "./ChangesetRow";
|
||||
import React from "react";
|
||||
import type { Changeset, Repository } from "@scm-manager/ui-types";
|
||||
import classNames from "classnames";
|
||||
|
||||
type Props = {
|
||||
repository: Repository,
|
||||
changesets: Changeset[]
|
||||
};
|
||||
|
||||
class ChangesetList extends React.Component<Props> {
|
||||
render() {
|
||||
const { repository, changesets } = this.props;
|
||||
const content = changesets.map((changeset, index) => {
|
||||
return <ChangesetRow key={index} repository={repository} changeset={changeset} />;
|
||||
});
|
||||
return <div className={classNames("box")}>{content}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
export default ChangesetList;
|
||||
66
scm-ui/src/repos/components/ChangesetRow.js
Normal file
66
scm-ui/src/repos/components/ChangesetRow.js
Normal file
@@ -0,0 +1,66 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import type { Changeset, Repository } from "@scm-manager/ui-types";
|
||||
import classNames from "classnames";
|
||||
import { translate, Interpolate } from "react-i18next";
|
||||
import ChangesetAvatar from "./ChangesetAvatar";
|
||||
import ChangesetId from "./ChangesetId";
|
||||
import injectSheet from "react-jss";
|
||||
import { DateFromNow } from "@scm-manager/ui-components";
|
||||
import ChangesetAuthor from "./ChangesetAuthor";
|
||||
|
||||
const styles = {
|
||||
pointer: {
|
||||
cursor: "pointer"
|
||||
},
|
||||
changesetGroup: {
|
||||
marginBottom: "1em"
|
||||
},
|
||||
withOverflow: {
|
||||
overflow: "auto"
|
||||
}
|
||||
};
|
||||
|
||||
type Props = {
|
||||
repository: Repository,
|
||||
changeset: Changeset,
|
||||
t: any,
|
||||
classes: any
|
||||
};
|
||||
|
||||
class ChangesetRow extends React.Component<Props> {
|
||||
createLink = (changeset: Changeset) => {
|
||||
const { repository } = this.props;
|
||||
return <ChangesetId changeset={changeset} repository={repository} />;
|
||||
};
|
||||
|
||||
render() {
|
||||
const { changeset, classes } = this.props;
|
||||
const changesetLink = this.createLink(changeset);
|
||||
const dateFromNow = <DateFromNow date={changeset.date} />;
|
||||
const authorLine = <ChangesetAuthor changeset={changeset}/>;
|
||||
return (
|
||||
<article className={classNames("media", classes.inner)}>
|
||||
<figure className="media-left">
|
||||
<ChangesetAvatar changeset={changeset} />
|
||||
</figure>
|
||||
<div className={classNames("media-content", classes.withOverflow)}>
|
||||
<div className="content">
|
||||
<p className="is-ellipsis-overflow">
|
||||
{changeset.description}
|
||||
<br />
|
||||
<Interpolate
|
||||
i18nKey="changeset.summary"
|
||||
id={changesetLink}
|
||||
time={dateFromNow}
|
||||
/>
|
||||
</p>{" "}
|
||||
<p className="is-size-7">{authorLine}</p>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default injectSheet(styles)(translate("changesets")(ChangesetRow));
|
||||
@@ -11,13 +11,15 @@ type Props = {
|
||||
class DropDown extends React.Component<Props> {
|
||||
render() {
|
||||
const {options, preselectedOption} = this.props;
|
||||
return <select value={preselectedOption} onChange={this.change}>
|
||||
<option key=""> </option>
|
||||
return <div className="select">
|
||||
<select value={preselectedOption} onChange={this.change}>
|
||||
<option key=""></option>
|
||||
{options.map(option => {
|
||||
return <option key={option}
|
||||
value={option}>{option}</option>
|
||||
})}
|
||||
</select>
|
||||
</div>
|
||||
}
|
||||
|
||||
change = (event) => {
|
||||
@@ -1,9 +1,9 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import {Link} from "react-router-dom";
|
||||
import injectSheet from "react-jss";
|
||||
import type { Repository } from "@scm-manager/ui-types";
|
||||
import { DateFromNow } from "@scm-manager/ui-components";
|
||||
import type {Repository} from "@scm-manager/ui-types";
|
||||
import {DateFromNow} from "@scm-manager/ui-components";
|
||||
import RepositoryEntryLink from "./RepositoryEntryLink";
|
||||
import classNames from "classnames";
|
||||
import RepositoryAvatar from "./RepositoryAvatar";
|
||||
@@ -45,7 +45,7 @@ class RepositoryEntry extends React.Component<Props> {
|
||||
return (
|
||||
<RepositoryEntryLink
|
||||
iconClass="fa-code-branch"
|
||||
to={repositoryLink + "/changesets"}
|
||||
to={repositoryLink + "/history"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -67,10 +67,7 @@ class RepositoryEntry extends React.Component<Props> {
|
||||
renderModifyLink = (repository: Repository, repositoryLink: string) => {
|
||||
if (repository._links["update"]) {
|
||||
return (
|
||||
<RepositoryEntryLink
|
||||
iconClass="fa-cog"
|
||||
to={repositoryLink + "/modify"}
|
||||
/>
|
||||
<RepositoryEntryLink iconClass="fa-cog" to={repositoryLink + "/edit"} />
|
||||
);
|
||||
}
|
||||
return null;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user