From b7b2b8178774cb391d4f6eb3631fba0d321e2778 Mon Sep 17 00:00:00 2001 From: Dustin Jenkins Date: Wed, 10 Jul 2024 13:10:15 -0700 Subject: [PATCH] Preserve path information. --- VERSION | 2 +- .../scienceportal/session/PostAction.java | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index ddb0c9e..e1d098d 100644 --- a/VERSION +++ b/VERSION @@ -5,6 +5,6 @@ # tags with and without build number so operators use the versioned # tag but we always keep a timestamped tag in case a semantic tag gets # replaced accidentally -VER=0.2.4 +VER=0.2.5 TAGS="${VER} ${VER}-$(date -u +"%Y%m%dT%H%M%S")" unset VER diff --git a/src/main/java/org/opencadc/scienceportal/session/PostAction.java b/src/main/java/org/opencadc/scienceportal/session/PostAction.java index b4a928d..b70bc01 100644 --- a/src/main/java/org/opencadc/scienceportal/session/PostAction.java +++ b/src/main/java/org/opencadc/scienceportal/session/PostAction.java @@ -73,6 +73,7 @@ import ca.nrc.cadc.reg.Standards; import ca.nrc.cadc.reg.client.RegistryClient; import ca.nrc.cadc.rest.InlineContentHandler; +import ca.nrc.cadc.util.StringUtil; import org.opencadc.scienceportal.ApplicationConfiguration; import org.opencadc.scienceportal.SciencePortalAuthAction; @@ -92,12 +93,23 @@ public class PostAction extends SciencePortalAuthAction { @Override public void doAction() throws Exception { - final URL apiURL = new URL(getAPIURL().toExternalForm() + PostAction.SESSION_ENDPOINT); + final StringBuilder apiURLBuilder = new StringBuilder(getAPIURL().toExternalForm() + PostAction.SESSION_ENDPOINT); + + // Preserve path items. + final String path = this.syncInput.getPath(); + if (StringUtil.hasText(path)) { + if (!path.trim().startsWith("/")) { + apiURLBuilder.append("/"); + } + + apiURLBuilder.append(path); + } + + final URL apiURL = new URL(apiURLBuilder.toString()); final Subject authenticatedUser = getCurrentSubject(apiURL); final Map payload = new HashMap<>(); payload.putAll(syncInput.getParameterNames().stream().collect( Collectors.toMap(key -> key, key -> syncInput.getParameter(key)))); - Subject.doAs(authenticatedUser, (PrivilegedExceptionAction) () -> { final HttpPost httpPost = new HttpPost(apiURL, payload, false); httpPost.prepare();