Skip to content

Commit

Permalink
craft the right one sage URL and set the redirect cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-hodgson committed Oct 3, 2024
1 parent 2c5a895 commit f31c83c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/main/java/org/sagebionetworks/web/client/GWTWrapperImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.google.gwt.user.datepicker.client.CalendarUtil;
import com.google.gwt.xhr.client.XMLHttpRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.sagebionetworks.web.client.utils.Callback;

public class GWTWrapperImpl implements GWTWrapper {
Expand Down Expand Up @@ -241,14 +243,34 @@ public String getFriendlySize(double size, boolean abbreviatedUnits) {
return DisplayUtils.getFriendlySize(size, abbreviatedUnits);
}

private static Map<String, String> hostName2OneSageSite = new HashMap<>();

static {
hostName2OneSageSite.put(
"staging.synapse.org",
"https://staging.accounts.synapse.org/?appId=staging.synapse.org"
);
hostName2OneSageSite.put(
"portal-dev.dev.sagebase.org",
"https://accounts-dev.dev.sagebase.org/?appId=dev.synapse.org"
);
hostName2OneSageSite.put(
"localhost",
"http://localhost:3000/?appId=localhost"
);
hostName2OneSageSite.put(
"127.0.0.1",
"http://127.0.0.1:3000/?appId=localhost"
);
}

@Override
public String getOneSageURL() {
boolean isStaging = Window.Location
.getHostName()
.equalsIgnoreCase("staging.synapse.org");
return isStaging
? "https://staging.accounts.synapse.org/?appId=staging.synapse.org"
: "https://accounts.synapse.org/?appId=synapse.org";
String hostName = Window.Location.getHostName().toLowerCase();
return hostName2OneSageSite.getOrDefault(
hostName,
"https://accounts.synapse.org/?appId=synapse.org"
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sagebionetworks.web.client;

import static org.sagebionetworks.web.client.ServiceEntryPointUtils.fixServiceEntryPoint;
import static org.sagebionetworks.web.client.cookie.CookieKeys.ONESAGE_REDIRECT_COOKIE_KEY;
import static org.sagebionetworks.web.client.cookie.CookieKeys.SHOW_DATETIME_IN_UTC;
import static org.sagebionetworks.web.shared.WebConstants.REPO_SERVICE_URL_KEY;

Expand Down Expand Up @@ -614,6 +615,9 @@ public void onPreviewNativeEvent(NativePreviewEvent event) {

@Override
public void gotoLoginPage() {
//tell One Sage to return to the current url
cookieProvider.setCookie(ONESAGE_REDIRECT_COOKIE_KEY, gwt.getCurrentURL());
//go to One Sage to log in
gwt.assignThisWindowWith(gwt.getOneSageURL());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ public class CookieKeys {

public static String PORTAL_CONFIG =
"org.sagebionetworks.security.cookies.portal.config";

public static String ONESAGE_REDIRECT_COOKIE_KEY =
"org.sagebionetworks.cookies.redirect-after-login";
}

0 comments on commit f31c83c

Please sign in to comment.