Skip to content

Commit

Permalink
wlcg tape api: fix handling of door root path
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryLitvintsev committed Jun 21, 2024
1 parent 5652f98 commit 5d775ad
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
*/
package org.dcache.restful.resources.tape;

import static org.dcache.http.AuthenticationHandler.getLoginAttributes;
import static org.dcache.restful.resources.bulk.BulkResources.getRestriction;
import static org.dcache.restful.resources.bulk.BulkResources.getSubject;
import static org.dcache.restful.util.HttpServletRequests.getUserRootAwareTargetPrefix;
import static org.dcache.restful.util.JSONUtils.newBadRequestException;

import com.google.common.base.Strings;
import diskCacheV111.util.FsPath;
import diskCacheV111.util.PnfsHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
Expand All @@ -84,6 +86,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import javax.ws.rs.BadRequestException;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.ForbiddenException;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand All @@ -93,8 +96,10 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.dcache.auth.attributes.LoginAttributes;
import org.dcache.auth.attributes.Restriction;
import org.dcache.cells.CellStub;
import org.dcache.http.PathMapper;
import org.dcache.restful.providers.tape.StageRequestInfo;
import org.dcache.restful.util.HandlerBuilders;
import org.dcache.restful.util.bulk.BulkServiceCommunicator;
Expand Down Expand Up @@ -130,6 +135,9 @@ public final class StageResources {
@Inject
private BulkServiceCommunicator service;

@Inject
private PathMapper pathMapper;

@Inject
@Named("pnfs-stub")
private CellStub pnfsmanager;
Expand Down Expand Up @@ -281,7 +289,10 @@ public Response submit(
Subject subject = getSubject();
Restriction restriction = getRestriction();

BulkRequest request = toBulkRequest(requestPayload);
FsPath userRoot = LoginAttributes.getUserRoot(getLoginAttributes(request));
FsPath rootPath = pathMapper.effectiveRoot(userRoot, ForbiddenException::new);

BulkRequest request = toBulkRequest(requestPayload, rootPath);

/*
* Frontend sets the URL. The backend service provides the UUID.
Expand Down Expand Up @@ -340,7 +351,7 @@ public Response clearRequest(@ApiParam("The unique id of the request.")
return Response.ok().build();
}

private BulkRequest toBulkRequest(String requestPayload) {
private BulkRequest toBulkRequest(String requestPayload, FsPath rootPath) {
if (Strings.emptyToNull(requestPayload) == null) {
throw new BadRequestException("empty request payload.");
}
Expand All @@ -353,7 +364,7 @@ private BulkRequest toBulkRequest(String requestPayload) {
request.setActivity("STAGE");

PnfsHandler handler = HandlerBuilders.unrestrictedPnfsHandler(pnfsmanager);
request.setTargetPrefix(getUserRootAwareTargetPrefix(this.request, null, handler));
request.setTargetPrefix(getUserRootAwareTargetPrefix(this.request, rootPath.toString(), handler));

try {
JSONObject reqPayload = new JSONObject(requestPayload);
Expand Down

0 comments on commit 5d775ad

Please sign in to comment.