From bd66c326258ebc60a9ba2a0bf1324b5a8378328e Mon Sep 17 00:00:00 2001 From: connoratrug <47183404+connoratrug@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:42:37 +0100 Subject: [PATCH] fix: 4479 use redirect url if set (#4494) fix: 4479 use redirect url if set Load redirect location from https session and use if set Closes #4479 --- .../emx2/web/controllers/OIDCController.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/molgenis-emx2-webapi/src/main/java/org/molgenis/emx2/web/controllers/OIDCController.java b/backend/molgenis-emx2-webapi/src/main/java/org/molgenis/emx2/web/controllers/OIDCController.java index 0f6146af05..665e4d2e9b 100644 --- a/backend/molgenis-emx2-webapi/src/main/java/org/molgenis/emx2/web/controllers/OIDCController.java +++ b/backend/molgenis-emx2-webapi/src/main/java/org/molgenis/emx2/web/controllers/OIDCController.java @@ -4,6 +4,7 @@ import static org.molgenis.emx2.web.SecurityConfigFactory.OIDC_CLIENT_NAME; import io.javalin.http.Context; +import java.util.ArrayList; import java.util.Optional; import org.molgenis.emx2.Database; import org.molgenis.emx2.MolgenisException; @@ -68,7 +69,7 @@ public void handleLoginRequest(Context ctx) { public void handleLoginCallback(Context ctx) { final JavalinWebContext context = new JavalinWebContext(ctx); - + Optional requestedUrlList = sessionStore.get(context, Pac4jConstants.REQUESTED_URL); HttpActionAdapter adapter = JavalinCustomHttpActionAdapter.INSTANCE; final CallbackLogic callbackLogic = FindBest.callbackLogic(null, securityConfig, DefaultCallbackLogic.INSTANCE); @@ -103,6 +104,17 @@ public void handleLoginCallback(Context ctx) { logger.info("OIDC sign in for user: {}", user); ctx.status(302); - ctx.redirect("/"); + + if (requestedUrlList.isPresent()) { + @SuppressWarnings("unchecked") + ArrayList requestedUrl = (ArrayList) requestedUrlList.get(); + if (requestedUrl.size() == 1) { + ctx.redirect(requestedUrl.get(0)); + } else { + ctx.redirect("/"); + } + } else { + ctx.redirect("/"); + } } }