Skip to content

Commit

Permalink
fix: 4479 use redirect url if set (#4494)
Browse files Browse the repository at this point in the history
fix: 4479 use redirect url if set

Load redirect location from https session and use if set

Closes #4479
  • Loading branch information
connoratrug authored Nov 14, 2024
1 parent 8d6f533 commit bd66c32
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void handleLoginRequest(Context ctx) {

public void handleLoginCallback(Context ctx) {
final JavalinWebContext context = new JavalinWebContext(ctx);

Optional<Object> requestedUrlList = sessionStore.get(context, Pac4jConstants.REQUESTED_URL);
HttpActionAdapter adapter = JavalinCustomHttpActionAdapter.INSTANCE;
final CallbackLogic callbackLogic =
FindBest.callbackLogic(null, securityConfig, DefaultCallbackLogic.INSTANCE);
Expand Down Expand Up @@ -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<String> requestedUrl = (ArrayList<String>) requestedUrlList.get();
if (requestedUrl.size() == 1) {
ctx.redirect(requestedUrl.get(0));
} else {
ctx.redirect("/");
}
} else {
ctx.redirect("/");
}
}
}

0 comments on commit bd66c32

Please sign in to comment.