Skip to content

Commit

Permalink
Introduce hidden preference for default oAuth provisioning url
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Sep 4, 2024
1 parent c597d32 commit 7aca9ea
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
16 changes: 11 additions & 5 deletions src/main/java/org/broad/igv/oauth/OAuthUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.gson.JsonParser;
import org.broad.igv.logging.*;
import org.broad.igv.DirectoryManager;
import org.broad.igv.prefs.Constants;
import org.broad.igv.prefs.PreferencesManager;
import org.broad.igv.ui.IGVMenuBar;
import org.broad.igv.ui.util.MessageUtils;
Expand Down Expand Up @@ -124,7 +125,7 @@ public OAuthProvider getGoogleProvider() {
try {
log.info("Loading Google oAuth properties");
googleProvider = loadDefaultOauthProperties();
if (IGVMenuBar.getInstance() != null) {
if (googleProvider != null && IGVMenuBar.getInstance() != null) {
IGVMenuBar.getInstance().enableGoogleMenu(true);
}
} catch (IOException e) {
Expand All @@ -142,10 +143,15 @@ public OAuthProvider getGoogleProvider() {
* @throws IOException
*/
private OAuthProvider loadDefaultOauthProperties() throws IOException {
String json = loadAsString(PROPERTIES_URL);
JsonParser parser = new JsonParser();
JsonObject obj = parser.parse(json).getAsJsonObject();
return parseProviderObject(obj);
String propertiesURL = PreferencesManager.getPreferences().get(Constants.PROVISIONING_URL_DEFAULT);
if(propertiesURL != null && propertiesURL.length() > 0) {
String json = loadAsString(propertiesURL);
JsonParser parser = new JsonParser();
JsonObject obj = parser.parse(json).getAsJsonObject();
return parseProviderObject(obj);
} else {
return null;
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/broad/igv/prefs/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ private Constants() {

// OAuth provisioning
public static final String PROVISIONING_URL = "PROVISIONING.URL";
public static final String PROVISIONING_URL_DEFAULT = "PROVISIONING_URL_DEFAULT";

// JBrowse circular view integration
public static final String CIRC_VIEW_ENABLED = "CIRC_VIEW_ENABLED";
Expand Down
31 changes: 21 additions & 10 deletions src/main/java/org/broad/igv/ui/IGVMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@ private List<AbstractButton> createMenus() {
// by loading a protected Google resource
try {
googleMenu = createGoogleMenu();
boolean enabled = PreferencesManager.getPreferences().getAsBoolean(ENABLE_GOOGLE_MENU);
enableGoogleMenu(enabled);
menus.add(googleMenu);
if(googleMenu != null) {
boolean enabled = PreferencesManager.getPreferences().getAsBoolean(ENABLE_GOOGLE_MENU);
enableGoogleMenu(enabled);
menus.add(googleMenu);
}
} catch (IOException e) {
log.error("Error creating google menu: " + e.getMessage());
}
Expand Down Expand Up @@ -1049,12 +1051,20 @@ public void menuCanceled(MenuEvent e) {

private JMenu createGoogleMenu() {

final OAuthProvider googleProvider = OAuthUtils.getInstance().getGoogleProvider();
if(googleProvider == null) {
log.error("Error creating google oauth provider");
return null;
}


googleMenu = new JMenu("Google");

final JMenuItem login = new JMenuItem("Login ... ");

login.addActionListener(e -> {
try {
OAuthUtils.getInstance().getGoogleProvider().openAuthorizationPage();
googleProvider.openAuthorizationPage();
} catch (Exception ex) {
MessageUtils.showErrorMessage("Error fetching oAuth tokens. See log for details", ex);
log.error("Error fetching oAuth tokens", ex);
Expand All @@ -1065,7 +1075,7 @@ private JMenu createGoogleMenu() {

final JMenuItem logout = new JMenuItem("Logout ");
logout.addActionListener(e -> {
OAuthUtils.getInstance().getGoogleProvider().logout();
googleProvider.logout();
GoogleUtils.setProjectID(null);
});
googleMenu.add(logout);
Expand All @@ -1077,10 +1087,9 @@ private JMenu createGoogleMenu() {
googleMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(MenuEvent e) {
OAuthProvider oauth = OAuthUtils.getInstance().getGoogleProvider();
boolean loggedIn = oauth.isLoggedIn();
if (loggedIn && oauth.getCurrentUserName() != null) {
login.setText(oauth.getCurrentUserName());
boolean loggedIn = googleProvider.isLoggedIn();
if (loggedIn && googleProvider.getCurrentUserName() != null) {
login.setText(googleProvider.getCurrentUserName());
} else {
login.setText("Login ...");
}
Expand Down Expand Up @@ -1112,7 +1121,9 @@ public void menuCanceled(MenuEvent e) {
* @throws IOException
*/
public void enableGoogleMenu(boolean enable) throws IOException {
googleMenu.setVisible(enable);
if(googleMenu != null) {
googleMenu.setVisible(enable);
}
}

// public void enableRemoveGenomes() {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/org/broad/igv/prefs/preferences.tab
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ CIRC_VIEW_PORT CircView port integer 60152

#Hidden

PROVISIONING_URL_DEFAULT https://igv.org/services/desktop_google
SAM.SHOW_JUNCTION_FLANKINGREGIONS FALSE
SAM.JUNCTION_MIN_FLANKING_WIDTH 0
SAM.JUNCTION_MIN_COVERAGE 1
Expand Down

0 comments on commit 7aca9ea

Please sign in to comment.