From a194c9e19539ed1595a6a76089d4ec1bf4a21712 Mon Sep 17 00:00:00 2001 From: Dmitry Litvintsev Date: Mon, 24 Jun 2024 16:17:50 -0500 Subject: [PATCH] frontend: handle frontend.root variable properly Motivation: =========== Issue https://github.com/dCache/dcache/issues/7506 is about failures to invoke WLCG tape API to stage files on files relative to {webdav,frontend}.root Modification: ============ Take frontend.root path into account when calculating effective prefix Result: ======= Able to call stage API successully on paths ralative to frontend.root Patch: https://rb.dcache.org/r/14267/ Target: trunk Request: 10.x Request: 9.x --- .../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);