Skip to content

Commit

Permalink
Merge pull request #1293 from virtualcell/1287-improved-auth
Browse files Browse the repository at this point in the history
1287 improved auth
  • Loading branch information
AvocadoMoon authored Jul 2, 2024
2 parents ecbcf5c + c255e1f commit 4ce5122
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,8 @@ public void connectToServer(TopLevelWindowManager requester, ClientServerInfo cl
public void logOut(final TopLevelWindowManager requester){
JDialog dialog = new JDialog();
dialog.setAlwaysOnTop(true);
int confirm = JOptionPane.showOptionDialog(dialog, "You are about to logout of VCell, and in doing so close the app." +
"To complete this process you'll need to logout on the website as well. Do you want to continue?",
int confirm = JOptionPane.showOptionDialog(dialog, "You are about to logout of VCell, and in doing so close the app. " +
"To complete this process you'll be redirected to a logout page. Do you want to continue?",
"Logout", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null,
new String[] { "Continue", "Cancel" }, "Continue");
if (confirm == JOptionPane.OK_OPTION) {
Expand All @@ -670,7 +670,9 @@ public void logOut(final TopLevelWindowManager requester){
Hashtable<String, Object> hash = new Hashtable<String, Object>();

Auth0ConnectionUtils auth0ConnectionUtils = getClientServerManager().getAuth0ConnectionUtils();
auth0ConnectionUtils.logOut();
if (!getClientServerInfo().getUsername().equals(User.VCELL_GUEST_NAME)){
auth0ConnectionUtils.logOut();
}
Auth0ConnectionUtils.setShowLoginPopUp(true);

AsynchClientTask waitTask = new AsynchClientTask("wait for window closing",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class VCellClientMain implements Callable<Integer> {
private String quarkusAPIHost = null;

private boolean isHTTP = PropertyLoader.getBooleanProperty(PropertyLoader.isHTTP, false);
public static Injector injector;

private VCellClientMain() {
}
Expand Down Expand Up @@ -117,7 +118,7 @@ public Integer call() throws Exception {
int quarkusPort = quarkusAPIHost != null ? Integer.parseInt(quarkusAPIHost.split(":")[1]) : port;

PropertyLoader.loadProperties(REQUIRED_CLIENT_PROPERTIES);
Injector injector = Guice.createInjector(new VCellClientModule(host, port, pathPrefixV0,
injector = Guice.createInjector(new VCellClientModule(host, port, pathPrefixV0,
quarkusHost, quarkusPort));
this.vcellClient = injector.getInstance(VCellClient.class);

Expand Down
223 changes: 61 additions & 162 deletions vcell-client/src/main/java/cbit/vcell/client/desktop/DocumentWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@
import cbit.vcell.client.*;
import cbit.vcell.client.constants.GuiConstants;
import cbit.vcell.client.data.ExportedDataViewer;
import cbit.vcell.client.server.ConnectionStatus;
import cbit.vcell.client.server.DynamicClientProperties;
import cbit.vcell.client.server.ReconnectListener;
import cbit.vcell.client.server.Reconnector;
import cbit.vcell.client.server.*;
import cbit.vcell.client.task.AsynchClientTask;
import cbit.vcell.client.task.ClientTaskDispatcher;
import cbit.vcell.client.task.LaunchVirtualFRAP;
import cbit.vcell.desktop.ClientLogin;
import cbit.vcell.model.ReactionStep;
import cbit.vcell.model.TransformMassActions;
import cbit.vcell.model.TransformMassActions.TransformedReaction;
import cbit.vcell.model.gui.TransformMassActionPanel;
import cbit.vcell.resource.OperatingSystemInfo;
import cbit.vcell.resource.PropertyLoader;
import cbit.vcell.resource.ResourceUtil;
import cbit.vcell.server.VCellConnectionFactory;
import com.google.inject.ConfigurationException;
import com.google.inject.Key;
import com.google.inject.name.Names;
import org.vcell.DependencyConstants;
import org.vcell.client.logicalwindow.LWTopFrame;
import org.vcell.documentation.VcellHelpViewer;
import org.vcell.util.UtilCancelException;
Expand All @@ -40,6 +43,7 @@
import org.vcell.util.gui.*;
import org.vcell.util.gui.exporter.FileFilters;
import org.vcell.util.importer.PathwayImportPanel.PathwayImportOption;
import scala.collection.mutable.HashTable;

import javax.swing.*;
import javax.swing.event.MenuEvent;
Expand Down Expand Up @@ -72,6 +76,7 @@ public class DocumentWindow extends LWTopFrame implements TopLevelWindow, Reconn

private JMenuItem ivjAbout_BoxMenuItem = null;
private JMenuItem ivjManageUser = null;
private JMenuItem loginMenuItem = null;
private JMenuItem ivjLogoutUser = null;
private JMenuItem ivjCloseMenuItem = null;
private JMenuBar ivjDocumentWindowJMenuBar = null;
Expand Down Expand Up @@ -222,9 +227,12 @@ else if (e.getSource() == DocumentWindow.this.menuItemImportPathwayExample)
getWindowManager().showFieldDataWindow();
if (e.getSource() == DocumentWindow.this.getManageUserMenuItem()){
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)){
Desktop.getDesktop().browse(new URI("https://vcell-stage.cam.uchc.edu/login_success"));
Desktop.getDesktop().browse(new URI("https://vcell-stage.cam.uchc.edu/profile"));
}
}
if (e.getSource() == DocumentWindow.this.getLoginItem()){
login();
}
if (e.getSource() == DocumentWindow.this.getPermissionsMenuItem()) {
getWindowManager().getRequestManager().accessPermissions(DocumentWindow.this, getWindowManager().getVCDocument());
}
Expand Down Expand Up @@ -445,6 +453,16 @@ private javax.swing.JMenuItem getViewJobsMenuItem() {
return viewJobsMenuItem;
}

private JMenuItem getLoginItem(){
if (loginMenuItem == null){
loginMenuItem = new javax.swing.JMenuItem();
loginMenuItem.setName("LoginMenuItem");
loginMenuItem.setText("Login");
loginMenuItem.setEnabled(false);
}
return loginMenuItem;
}

private JMenuItem getManageUserMenuItem(){
if (ivjManageUser == null){
ivjManageUser = new javax.swing.JMenuItem();
Expand Down Expand Up @@ -986,142 +1004,6 @@ private javax.swing.JMenu getOpenMenuItem() {
}


//private static String createImageJServiceMenuText() {
// if(ImageJHelper.serviceExists()) {
// return "Stop FIJI (ImageJ) Service ("+ImageJHelper.getServiceURI().getPort()+")";
// }
// return "Start FIJI (ImageJ) Service";
//}
//
//private static final String IMAGEJ_PLUGIN_PATH = "IMAGEJ_PLUGIN_PATH";
//
//private void startStopImageJService() {
// if(ImageJHelper.serviceExists()) {
// try {
// ImageJHelper.stopService();
// } catch (Exception e) {
// e.printStackTrace();
// DialogUtils.showErrorDialog(this, "Error stopping ImageJ Service: "+e.getMessage());
// }
// }else {
// final String VC_PLUG_CONTINUE = "Continue";
// final String CANCEL = "Cancel";
// final String NEW_IJ_PLUGIN = "Install new plugin...";
// final String CHANGE_IJ_PLUGIN = "Update plugin or Change path...";
// Preferences prefs = Preferences.userNodeForPackage(DocumentWindow.class);
// String imageJVCellPluginVersion = "vcell-imagej-helper-"+TokenMangler.fixTokenStrict(VCellSoftwareVersion.fromSystemProperty().getSoftwareVersionString())+".jar";
// String imageJPluginPath = prefs.get(IMAGEJ_PLUGIN_PATH, null);
// URL imageJVCellPluginURL = null;
// try {
// imageJVCellPluginURL = new URL(PropertyLoader.getRequiredProperty(PropertyLoader.imageJVcellPluginURL)+"/"+imageJVCellPluginVersion);
// } catch (Exception e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// DialogUtils.showErrorDialog(this, "Error download URL: "+e1.getMessage());
// return;
// }
// String downLoadOption = NEW_IJ_PLUGIN;
//// File ijPluginFile = null;
// File[] existingVCPlugins = new File[] {};
// Boolean bSame = null;
// if(imageJPluginPath != null){
// existingVCPlugins = (new File(imageJPluginPath)).listFiles(new FilenameFilter() {
// @Override
// public boolean accept(File dir, String name) {
// // TODO Auto-generated method stub
// return name.startsWith("vcell-imagej-helper-") && name.endsWith(".jar");
// }
// });
// if(existingVCPlugins.length > 1) {
// StringBuffer sb = new StringBuffer();
// for (int i = 0; i < existingVCPlugins.length; i++) {
// sb.append((i!=0?"\n":"")+existingVCPlugins[i].getName());
// }
// DialogUtils.showWarningDialog(this, "Found "+existingVCPlugins.length+" installed VCell Imagej plugins:\n"+
// sb.toString()+"\nRemove the "+existingVCPlugins.length+" plugins from ImageJ directory and start service again.\nPlugin path="+imageJPluginPath);
// return;
// }
// if(existingVCPlugins.length == 1) {
// downLoadOption = CHANGE_IJ_PLUGIN;
// if(imageJVCellPluginVersion.equals(existingVCPlugins[0].getName())) {
// bSame = true;
// }else {
// bSame = false;
// }
// }
// }
// String[] options = (existingVCPlugins.length==0?new String[] {downLoadOption,CANCEL}:new String[] {VC_PLUG_CONTINUE,downLoadOption,CANCEL});
// String result = DialogUtils.showWarningDialog(this,
// "Start VCell's FIJI Service",
// "VCell's FIJI (ImageJ) service allows scripts running in FIJI to communicate with VCell "+
// "allowing query, control, and transfer of model/simulation data between VCell and FIJI.\n"+
// "(see Help->'VCell Help' then search 'start imagej service')\n"+
// (existingVCPlugins.length == 0?"Install FIJI (https://imagej.net/Fiji) before starting this service.":
// "Current plugin path:\n"+existingVCPlugins[0].getAbsolutePath()+"\n"+"Available version="+imageJVCellPluginVersion)
// ,options, CANCEL);
// if(NEW_IJ_PLUGIN.equals(result) || CHANGE_IJ_PLUGIN.equals(result)) {
// File selectedDir = null;
// if(OperatingSystemInfo.getInstance().isMac()) {
// Frame f = (Frame)GeneralGuiUtils.findTypeParentOfComponent(this, Frame.class);
// System.setProperty("apple.awt.fileDialogForDirectories", "true");
// FileDialog fdiag = new FileDialog(f);
// fdiag.setMultipleMode(false);
// if(existingVCPlugins.length == 1) {
// fdiag.setDirectory(existingVCPlugins[0].getParentFile().getParentFile().getAbsolutePath());
// fdiag.setDirectory(existingVCPlugins[0].getParentFile().getAbsolutePath());
// }
// fdiag.setVisible(true);
// File[] files = fdiag.getFiles();
// if(files == null || files.length == 0) {
// return;
// }
// selectedDir = files[0];
// }else {
// VCFileChooser vcf = new VCFileChooser((existingVCPlugins.length == 0?ResourceUtil.getUserHomeDir():existingVCPlugins[0].getParentFile().getParentFile()));
// vcf.setMultiSelectionEnabled(false);
// if(existingVCPlugins.length == 1) {
// vcf.setSelectedFile(existingVCPlugins[0].getParentFile());
// }
// vcf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
// int returnVal = vcf.showOpenDialog(this);
// if(returnVal != JFileChooser.APPROVE_OPTION) {
// return;
// }
// selectedDir = vcf.getSelectedFile();
// }
// try {
// if(!selectedDir.getName().equals("plugins")) {
// String pluginWarn = DialogUtils.showOKCancelWarningDialog(this, "Unexpected plugins directory warning", "path "+selectedDir.getAbsolutePath()+"\nexpected to end with 'plugins'");
// if(pluginWarn == null || !pluginWarn.equals(SimpleUserMessage.OPTION_OK)) {
// return;
// }
// }
// final File pluginDestination = new File(selectedDir,imageJVCellPluginVersion);
// FileUtils.copyURLToFile(imageJVCellPluginURL, pluginDestination);
// prefs.put(IMAGEJ_PLUGIN_PATH, selectedDir.getAbsolutePath());
// if(existingVCPlugins.length != 0 && bSame!=null && !bSame) {
// if(!existingVCPlugins[0].delete()) {
// throw new Exception("Couldn't delete old plugin "+existingVCPlugins[0].getAbsolutePath()+". Please stop Imagej and manually remove the old plugin file.");
// }
// }
// DialogUtils.showInfoDialog(this, "VCell ImageJ plugin installed at:\n"+pluginDestination.getAbsolutePath());
// } catch (Exception e) {
// e.printStackTrace();
// DialogUtils.showErrorDialog(this, e.getMessage());
// return;
// }
// }else if(!VC_PLUG_CONTINUE.equals(result)){
// return;
// }
// try {
// ImageJHelper.startService(null);
// } catch (Exception e) {
// e.printStackTrace();
// DialogUtils.showErrorDialog(this, "error starting ImageJ Service: "+e.getMessage());
// }
// }
//
//}

private JMenuItem getRunVFrapItem() {
if (ivjRunVFrapMenuItem == null) {
Expand Down Expand Up @@ -1226,33 +1108,16 @@ private javax.swing.JMenu getServerMenu() {
if (ivjServerMenu == null) {
try {
ivjServerMenu = new javax.swing.JMenu();
// //getImageJServiceMenuItem().setText(createImageJServiceMenuText());
// ivjServerMenu.addMenuListener(new MenuListener() {
// @Override
// public void menuSelected(MenuEvent e) {
// getImageJServiceMenuItem().setText(createImageJServiceMenuText());
// }
// @Override
// public void menuDeselected(MenuEvent e) {
// }
// @Override
// public void menuCanceled(MenuEvent e) {
// }
// });
ivjServerMenu.setName("ServerMenu");
ivjServerMenu.setText("Account");
ivjServerMenu.add(getLoginItem());
ivjServerMenu.add(getLogOutMenuItem());
ivjServerMenu.add(getManageUserMenuItem());
ivjServerMenu.add(getChange_ProxyMenuItem());
ivjServerMenu.add(getLogOutMenuItem());
ivjServerMenu.add(getReconnectUserMenuItem());
// ivjServerMenu.add(getImageJServiceMenuItem()); // moved to Tools
ivjServerMenu.add(new JSeparator());
ivjServerMenu.add(getViewJobsMenuItem());
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
Expand Down Expand Up @@ -1517,6 +1382,7 @@ private void initConnections() throws java.lang.Exception {
getChange_ProxyMenuItem().addActionListener(ivjEventHandler);
getLogOutMenuItem().addActionListener(ivjEventHandler);
getReconnectUserMenuItem().addActionListener(ivjEventHandler);
getLoginItem().addActionListener(ivjEventHandler);
// getImageJServiceMenuItem().addActionListener(ivjEventHandler);
getJMenuItemRevert().addActionListener(ivjEventHandler);
getJMenuItemCompare().addActionListener(ivjEventHandler);
Expand Down Expand Up @@ -1629,6 +1495,35 @@ private void openDocument(java.awt.event.ActionEvent actionEvent) {
}
}

private void login(){
Hashtable<String, Object> hash = new Hashtable();
VCellConnectionFactory vcellConnectionFactory = VCellClientMain.injector.getInstance(VCellConnectionFactory.class);

String host = VCellClientMain.injector.getInstance(Key.get(String.class, Names.named(DependencyConstants.VCELL_API_HOST)));
String port;
String pathPrefix;
try{
port = VCellClientMain.injector.getInstance(Key.get(String.class, Names.named(DependencyConstants.VCELL_API_PORT)));
}
catch (ConfigurationException e){
port = "443";
}
try {
pathPrefix = VCellClientMain.injector.getInstance(Key.get(String.class, Names.named(DependencyConstants.VCELL_API_PATH_PREFIX_V0)));
}
catch (ConfigurationException e){
pathPrefix = "";
}

AsynchClientTask task1a = ClientLogin.popupLogin(false);
AsynchClientTask task1b = ClientLogin.loginWithAuth0(vcellConnectionFactory.getAuth0ConnectionUtils());
AsynchClientTask task2 = ClientLogin.connectToServer(vcellConnectionFactory.getAuth0ConnectionUtils(),
ClientServerInfo.createRemoteServerInfo(host, Integer.parseInt(port), pathPrefix, null));

AsynchClientTask[] taskArray = new AsynchClientTask[] { task1a, task1b, task2};
ClientTaskDispatcher.dispatch(null, hash, taskArray);
}


private void reconnect() {
getWindowManager().reconnect();
Expand Down Expand Up @@ -1749,7 +1644,8 @@ public void updateConnectionStatus(ConnectionStatus connStatus) {
status = "";
getJProgressBarConnection().setString("NOT CONNECTED");
getJProgressBarConnection().setValue(0);
getManageUserMenuItem().setEnabled(true);
getManageUserMenuItem().setEnabled(false);
getLoginItem().setEnabled(true);
getLogOutMenuItem().setEnabled(false);
getReconnectUserMenuItem().setEnabled(false);
getViewJobsMenuItem().setEnabled(false);
Expand All @@ -1776,6 +1672,7 @@ public void updateConnectionStatus(ConnectionStatus connStatus) {
getJProgressBarConnection().setString("CONNECTED (" + connStatus.getUserName() + ")");
getJProgressBarConnection().setValue(100);
getManageUserMenuItem().setEnabled(true);
getLoginItem().setEnabled(false);
getLogOutMenuItem().setEnabled(true);
getReconnectUserMenuItem().setEnabled(true);
getViewJobsMenuItem().setEnabled(true);
Expand Down Expand Up @@ -1817,6 +1714,7 @@ public void updateConnectionStatus(ConnectionStatus connStatus) {
getJProgressBarConnection().setString("INITIALIZING...");
getJProgressBarConnection().setValue(0);
getManageUserMenuItem().setEnabled(false);
getLoginItem().setEnabled(false);
getLogOutMenuItem().setEnabled(false);
getReconnectUserMenuItem().setEnabled(false);
enableOpenMenuItems(false);
Expand All @@ -1841,7 +1739,8 @@ public void updateConnectionStatus(ConnectionStatus connStatus) {
status = "Server: " + connStatus.getApihost()+":"+connStatus.getApiport() + " User: " + connStatus.getUserName();
getJProgressBarConnection().setString("DISCONNECTED");
getJProgressBarConnection().setValue(0);
getManageUserMenuItem().setEnabled(true);
getManageUserMenuItem().setEnabled(false);
getLoginItem().setEnabled(false);
getLogOutMenuItem().setEnabled(false);
getReconnectUserMenuItem().setEnabled(true);
enableOpenMenuItems(false);
Expand Down
Loading

0 comments on commit 4ce5122

Please sign in to comment.