add crlf exception and exception mapper

This commit is contained in:
Mohamed Karray
2018-09-06 13:54:52 +02:00
parent 85999904b3
commit 6acfb38132
5 changed files with 48 additions and 4 deletions

View File

@@ -0,0 +1,13 @@
package sonia.scm.api.v2.resources;
import sonia.scm.api.rest.StatusExceptionMapper;
import sonia.scm.util.CRLFInjectionException;
import javax.ws.rs.core.Response;
public class CRLFInjectionExceptionMapper extends StatusExceptionMapper<CRLFInjectionException> {
public CRLFInjectionExceptionMapper() {
super(CRLFInjectionException.class, Response.Status.BAD_REQUEST);
}
}

View File

@@ -31,6 +31,16 @@ public class DiffRootResource {
this.serviceFactory = serviceFactory;
}
/**
* Get the repository diff of a revision
*
* @param namespace repository namespace
* @param name repository name
* @param revision the revision
* @return the dif of the revision
* @throws NotFoundException if the repository is not found
*/
@GET
@Path("{revision}")
@Produces(VndMediaType.DIFF)
@@ -45,8 +55,6 @@ public class DiffRootResource {
public Response get(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("revision") String revision) throws NotFoundException {
HttpUtil.checkForCRLFInjection(revision);
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
Repository repository = repositoryService.getRepository();
RepositoryPermissions.read(repository).check();
StreamingOutput responseEntry = output -> {
try {
repositoryService.getDiffCommand()