From 5d775ad99ba8207bb4aac73a4f630ce87fbe641c Mon Sep 17 00:00:00 2001 From: Dmitry Litvintsev Date: Thu, 20 Jun 2024 19:26:34 -0500 Subject: [PATCH] wlcg tape api: fix handling of door root path --- .../restful/resources/tape/StageResources.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/dcache-frontend/src/main/java/org/dcache/restful/resources/tape/StageResources.java b/modules/dcache-frontend/src/main/java/org/dcache/restful/resources/tape/StageResources.java index 3bb947d3715..9876209b3e5 100644 --- a/modules/dcache-frontend/src/main/java/org/dcache/restful/resources/tape/StageResources.java +++ b/modules/dcache-frontend/src/main/java/org/dcache/restful/resources/tape/StageResources.java @@ -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; @@ -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; @@ -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; @@ -130,6 +135,9 @@ public final class StageResources { @Inject private BulkServiceCommunicator service; + @Inject + private PathMapper pathMapper; + @Inject @Named("pnfs-stub") private CellStub pnfsmanager; @@ -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. @@ -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."); } @@ -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);