From 6e3bda7667f31dc9ba152acf8eed4a7c2b640af3 Mon Sep 17 00:00:00 2001 From: Mitch Gaffigan Date: Wed, 3 Sep 2025 09:50:26 -0500 Subject: [PATCH 1/3] Moved handleSuccess to Mirth.java - boots app, not related to panel Signed-off-by: Mitch Gaffigan --- .../mirth/connect/client/ui/LoginPanel.java | 152 +----------------- .../com/mirth/connect/client/ui/Mirth.java | 149 +++++++++++++++++ 2 files changed, 151 insertions(+), 150 deletions(-) diff --git a/client/src/com/mirth/connect/client/ui/LoginPanel.java b/client/src/com/mirth/connect/client/ui/LoginPanel.java index 0414b7acc..284aff1d4 100644 --- a/client/src/com/mirth/connect/client/ui/LoginPanel.java +++ b/client/src/com/mirth/connect/client/ui/LoginPanel.java @@ -4,38 +4,27 @@ package com.mirth.connect.client.ui; -import static com.mirth.connect.client.core.BrandingConstants.CHECK_FOR_NOTIFICATIONS; - import java.awt.Color; import java.awt.Cursor; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; -import java.util.prefs.Preferences; import javax.swing.ImageIcon; import javax.swing.SwingWorker; -import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import com.mirth.connect.client.core.Client; import com.mirth.connect.client.core.ClientException; -import com.mirth.connect.client.core.ConnectServiceUtil; import com.mirth.connect.client.core.UnauthorizedException; import com.mirth.connect.client.core.api.servlets.UserServletInterface; import com.mirth.connect.client.ui.util.DisplayUtil; import com.mirth.connect.model.ExtendedLoginStatus; import com.mirth.connect.model.LoginStatus; -import com.mirth.connect.model.PublicServerSettings; -import com.mirth.connect.model.User; -import com.mirth.connect.model.converters.ObjectXMLSerializer; import com.mirth.connect.plugins.MultiFactorAuthenticationClientPlugin; -import com.mirth.connect.util.MirthSSLUtil; public class LoginPanel extends javax.swing.JFrame { @@ -97,8 +86,6 @@ public void initialize(String mirthServer, String version, String user, String p return; } - PlatformUI.CLIENT_VERSION = version; - setTitle(String.format("%s %s - Login", BrandingConstants.PRODUCT_NAME, version)); setIconImage(BrandingConstants.FAVICON.getImage()); @@ -447,7 +434,7 @@ public Void doInBackground() { // If SUCCESS or SUCCESS_GRACE_PERIOD if (loginStatus != null && loginStatus.isSuccess()) { - if (!handleSuccess(loginStatus)) { + if (!Mirth.handleLoginSuccess(client, loginStatus, username.getText())) { LoginPanel.getInstance().setVisible(false); LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); } @@ -466,7 +453,7 @@ public Void doInBackground() { if (loginStatus != null && loginStatus.isSuccess()) { errorOccurred = false; - if (!handleSuccess(loginStatus)) { + if (!Mirth.handleLoginSuccess(client, loginStatus, username.getText())) { LoginPanel.getInstance().setVisible(false); LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); } @@ -499,141 +486,6 @@ public Void doInBackground() { return null; } - private boolean handleSuccess(LoginStatus loginStatus) throws ClientException { - try { - PublicServerSettings publicServerSettings = client.getPublicServerSettings(); - - if (publicServerSettings.getLoginNotificationEnabled() == true) { - CustomBannerPanelDialog customBannerPanelDialog = new CustomBannerPanelDialog(LoginPanel.getInstance(), "Login Notification", publicServerSettings.getLoginNotificationMessage()); - boolean isAccepted = customBannerPanelDialog.isAccepted(); - - if (isAccepted == true) { - client.setUserNotificationAcknowledged(client.getCurrentUser().getId()); - } - else { - return false; - } - } - - String environmentName = publicServerSettings.getEnvironmentName(); - if (!StringUtils.isBlank(environmentName)) { - PlatformUI.ENVIRONMENT_NAME = environmentName; - } - - String serverName = publicServerSettings.getServerName(); - if (!StringUtils.isBlank(serverName)) { - PlatformUI.SERVER_NAME = serverName; - } else { - PlatformUI.SERVER_NAME = null; - } - - Color defaultBackgroundColor = publicServerSettings.getDefaultAdministratorBackgroundColor(); - if (defaultBackgroundColor != null) { - PlatformUI.DEFAULT_BACKGROUND_COLOR = defaultBackgroundColor; - } - } catch (ClientException e) { - PlatformUI.SERVER_NAME = null; - } - - try { - String database = (String) client.getAbout().get("database"); - if (!StringUtils.isBlank(database)) { - PlatformUI.SERVER_DATABASE = database; - } else { - PlatformUI.SERVER_DATABASE = null; - } - } catch (ClientException e) { - PlatformUI.SERVER_DATABASE = null; - } - - try { - Map map = client.getProtocolsAndCipherSuites(); - PlatformUI.SERVER_HTTPS_SUPPORTED_PROTOCOLS = map.get(MirthSSLUtil.KEY_SUPPORTED_PROTOCOLS); - PlatformUI.SERVER_HTTPS_ENABLED_CLIENT_PROTOCOLS = map.get(MirthSSLUtil.KEY_ENABLED_CLIENT_PROTOCOLS); - PlatformUI.SERVER_HTTPS_ENABLED_SERVER_PROTOCOLS = map.get(MirthSSLUtil.KEY_ENABLED_SERVER_PROTOCOLS); - PlatformUI.SERVER_HTTPS_SUPPORTED_CIPHER_SUITES = map.get(MirthSSLUtil.KEY_SUPPORTED_CIPHER_SUITES); - PlatformUI.SERVER_HTTPS_ENABLED_CIPHER_SUITES = map.get(MirthSSLUtil.KEY_ENABLED_CIPHER_SUITES); - } catch (ClientException e) { - } - - PlatformUI.USER_NAME = StringUtils.defaultString(loginStatus.getUpdatedUsername(), username.getText()); - setStatus("Authenticated..."); - new Mirth(client); - LoginPanel.getInstance().setVisible(false); - - User currentUser = PlatformUI.MIRTH_FRAME.getCurrentUser(PlatformUI.MIRTH_FRAME); - Properties userPreferences = new Properties(); - Set preferenceNames = new HashSet(); - preferenceNames.add("firstlogin"); - preferenceNames.add("checkForNotifications"); - preferenceNames.add("showNotificationPopup"); - preferenceNames.add("archivedNotifications"); - try { - userPreferences = client.getUserPreferences(currentUser.getId(), preferenceNames); - - // Display registration dialog if it's the user's first time logging in - String firstlogin = userPreferences.getProperty("firstlogin"); - if (firstlogin == null || BooleanUtils.toBoolean(firstlogin)) { - if (Integer.valueOf(currentUser.getId()) == 1) { - // if current user is user 1: - // 1. check system preferences for user information - // 2. if system preferences exist, populate screen using currentUser - Preferences preferences = Preferences.userNodeForPackage(Mirth.class); - String systemUserInfo = preferences.get("userLoginInfo", null); - if (systemUserInfo != null) { - String info[] = systemUserInfo.split(",", 0); - currentUser.setUsername(info[0]); - currentUser.setFirstName(info[1]); - currentUser.setLastName(info[2]); - currentUser.setEmail(info[3]); - currentUser.setCountry(info[4]); - currentUser.setStateTerritory(info[5]); - currentUser.setPhoneNumber(info[6]); - currentUser.setOrganization(info[7]); - currentUser.setRole(info[8]); - currentUser.setIndustry(info[9]); - currentUser.setDescription(info[10]); - } - } - FirstLoginDialog firstLoginDialog = new FirstLoginDialog(currentUser); - // if leaving the first login dialog without saving - if (!firstLoginDialog.getResult()) { - return false; - } - } else if (loginStatus.getStatus() == LoginStatus.Status.SUCCESS_GRACE_PERIOD) { - new ChangePasswordDialog(currentUser, loginStatus.getMessage()); - } - - // Check for new notifications from update server if enabled - String checkForNotifications = userPreferences.getProperty("checkForNotifications"); - if (CHECK_FOR_NOTIFICATIONS - && (checkForNotifications == null || BooleanUtils.toBoolean(checkForNotifications))) { - Set archivedNotifications = new HashSet(); - String archivedNotificationString = userPreferences.getProperty("archivedNotifications"); - if (archivedNotificationString != null) { - archivedNotifications = ObjectXMLSerializer.getInstance().deserialize(archivedNotificationString, Set.class); - } - // Update the Other Tasks pane with the unarchived notification count - int unarchivedNotifications = ConnectServiceUtil.getNotificationCount(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, LoadedExtensions.getInstance().getExtensionVersions(), archivedNotifications, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES); - PlatformUI.MIRTH_FRAME.updateNotificationTaskName(unarchivedNotifications); - - // Display notification dialog if enabled and if there are new notifications - String showNotificationPopup = userPreferences.getProperty("showNotificationPopup"); - if (showNotificationPopup == null || BooleanUtils.toBoolean(showNotificationPopup)) { - if (unarchivedNotifications > 0) { - new NotificationDialog(); - } - } - } - } catch (ClientException e) { - PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, e); - } - - PlatformUI.MIRTH_FRAME.sendUsageStatistics(); - - return true; - } - public void done() {} }; worker.execute(); diff --git a/client/src/com/mirth/connect/client/ui/Mirth.java b/client/src/com/mirth/connect/client/ui/Mirth.java index eacb68331..3292ccfd9 100644 --- a/client/src/com/mirth/connect/client/ui/Mirth.java +++ b/client/src/com/mirth/connect/client/ui/Mirth.java @@ -3,12 +3,18 @@ package com.mirth.connect.client.ui; +import static com.mirth.connect.client.core.BrandingConstants.CHECK_FOR_NOTIFICATIONS; + import java.awt.Color; import java.awt.Toolkit; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.io.IOException; import java.util.prefs.Preferences; +import java.util.Map; +import java.util.Set; +import java.util.Properties; +import java.util.HashSet; import javax.imageio.ImageIO; import javax.swing.ImageIcon; @@ -22,6 +28,7 @@ import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent.KeyBinding; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.SystemUtils; import org.apache.logging.log4j.Level; @@ -36,6 +43,12 @@ import com.jgoodies.looks.plastic.PlasticXPLookAndFeel; import com.mirth.connect.client.core.Client; import com.mirth.connect.client.core.ClientException; +import com.mirth.connect.client.core.ConnectServiceUtil; +import com.mirth.connect.model.LoginStatus; +import com.mirth.connect.model.PublicServerSettings; +import com.mirth.connect.model.User; +import com.mirth.connect.model.converters.ObjectXMLSerializer; +import com.mirth.connect.util.MirthSSLUtil; /** * The main mirth class. Sets up the login and then authenticates the login information and sets up @@ -282,4 +295,140 @@ public void run() { } }); } + + public static boolean handleLoginSuccess(Client client, LoginStatus loginStatus, String userName) throws ClientException { + AbstractLoginPanel loginPanel = LoginPanelFactory.getInstance(); + try { + PublicServerSettings publicServerSettings = client.getPublicServerSettings(); + + if (publicServerSettings.getLoginNotificationEnabled() == true) { + CustomBannerPanelDialog customBannerPanelDialog = new CustomBannerPanelDialog(loginPanel, "Login Notification", publicServerSettings.getLoginNotificationMessage()); + boolean isAccepted = customBannerPanelDialog.isAccepted(); + + if (isAccepted == true) { + client.setUserNotificationAcknowledged(client.getCurrentUser().getId()); + } + else { + return false; + } + } + + String environmentName = publicServerSettings.getEnvironmentName(); + if (!StringUtils.isBlank(environmentName)) { + PlatformUI.ENVIRONMENT_NAME = environmentName; + } + + String serverName = publicServerSettings.getServerName(); + if (!StringUtils.isBlank(serverName)) { + PlatformUI.SERVER_NAME = serverName; + } else { + PlatformUI.SERVER_NAME = null; + } + + Color defaultBackgroundColor = publicServerSettings.getDefaultAdministratorBackgroundColor(); + if (defaultBackgroundColor != null) { + PlatformUI.DEFAULT_BACKGROUND_COLOR = defaultBackgroundColor; + } + } catch (ClientException e) { + PlatformUI.SERVER_NAME = null; + } + + try { + String database = (String) client.getAbout().get("database"); + if (!StringUtils.isBlank(database)) { + PlatformUI.SERVER_DATABASE = database; + } else { + PlatformUI.SERVER_DATABASE = null; + } + } catch (ClientException e) { + PlatformUI.SERVER_DATABASE = null; + } + + try { + Map map = client.getProtocolsAndCipherSuites(); + PlatformUI.SERVER_HTTPS_SUPPORTED_PROTOCOLS = map.get(MirthSSLUtil.KEY_SUPPORTED_PROTOCOLS); + PlatformUI.SERVER_HTTPS_ENABLED_CLIENT_PROTOCOLS = map.get(MirthSSLUtil.KEY_ENABLED_CLIENT_PROTOCOLS); + PlatformUI.SERVER_HTTPS_ENABLED_SERVER_PROTOCOLS = map.get(MirthSSLUtil.KEY_ENABLED_SERVER_PROTOCOLS); + PlatformUI.SERVER_HTTPS_SUPPORTED_CIPHER_SUITES = map.get(MirthSSLUtil.KEY_SUPPORTED_CIPHER_SUITES); + PlatformUI.SERVER_HTTPS_ENABLED_CIPHER_SUITES = map.get(MirthSSLUtil.KEY_ENABLED_CIPHER_SUITES); + } catch (ClientException e) { + } + + PlatformUI.USER_NAME = StringUtils.defaultString(loginStatus.getUpdatedUsername(), userName); + loginPanel.setStatus("Authenticated..."); + new Mirth(client); + loginPanel.setVisible(false); + + User currentUser = PlatformUI.MIRTH_FRAME.getCurrentUser(PlatformUI.MIRTH_FRAME); + Properties userPreferences = new Properties(); + Set preferenceNames = new HashSet(); + preferenceNames.add("firstlogin"); + preferenceNames.add("checkForNotifications"); + preferenceNames.add("showNotificationPopup"); + preferenceNames.add("archivedNotifications"); + try { + userPreferences = client.getUserPreferences(currentUser.getId(), preferenceNames); + + // Display registration dialog if it's the user's first time logging in + String firstlogin = userPreferences.getProperty("firstlogin"); + if (firstlogin == null || BooleanUtils.toBoolean(firstlogin)) { + if (Integer.valueOf(currentUser.getId()) == 1) { + // if current user is user 1: + // 1. check system preferences for user information + // 2. if system preferences exist, populate screen using currentUser + Preferences preferences = Preferences.userNodeForPackage(Mirth.class); + String systemUserInfo = preferences.get("userLoginInfo", null); + if (systemUserInfo != null) { + String info[] = systemUserInfo.split(",", 0); + currentUser.setUsername(info[0]); + currentUser.setFirstName(info[1]); + currentUser.setLastName(info[2]); + currentUser.setEmail(info[3]); + currentUser.setCountry(info[4]); + currentUser.setStateTerritory(info[5]); + currentUser.setPhoneNumber(info[6]); + currentUser.setOrganization(info[7]); + currentUser.setRole(info[8]); + currentUser.setIndustry(info[9]); + currentUser.setDescription(info[10]); + } + } + FirstLoginDialog firstLoginDialog = new FirstLoginDialog(currentUser); + // if leaving the first login dialog without saving + if (!firstLoginDialog.getResult()) { + return false; + } + } else if (loginStatus.getStatus() == LoginStatus.Status.SUCCESS_GRACE_PERIOD) { + new ChangePasswordDialog(currentUser, loginStatus.getMessage()); + } + + // Check for new notifications from update server if enabled + String checkForNotifications = userPreferences.getProperty("checkForNotifications"); + if (CHECK_FOR_NOTIFICATIONS + && (checkForNotifications == null || BooleanUtils.toBoolean(checkForNotifications))) { + Set archivedNotifications = new HashSet(); + String archivedNotificationString = userPreferences.getProperty("archivedNotifications"); + if (archivedNotificationString != null) { + archivedNotifications = ObjectXMLSerializer.getInstance().deserialize(archivedNotificationString, Set.class); + } + // Update the Other Tasks pane with the unarchived notification count + int unarchivedNotifications = ConnectServiceUtil.getNotificationCount(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, LoadedExtensions.getInstance().getExtensionVersions(), archivedNotifications, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES); + PlatformUI.MIRTH_FRAME.updateNotificationTaskName(unarchivedNotifications); + + // Display notification dialog if enabled and if there are new notifications + String showNotificationPopup = userPreferences.getProperty("showNotificationPopup"); + if (showNotificationPopup == null || BooleanUtils.toBoolean(showNotificationPopup)) { + if (unarchivedNotifications > 0) { + new NotificationDialog(); + } + } + } + } catch (ClientException e) { + PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, e); + } + + PlatformUI.MIRTH_FRAME.sendUsageStatistics(); + + return true; + } } From 27146149c3095e7bdc092967615d55770481fd37 Mon Sep 17 00:00:00 2001 From: Mitch Gaffigan Date: Wed, 3 Sep 2025 09:53:28 -0500 Subject: [PATCH 2/3] Removed duplicated error handling logic to separate method, avoid relying on global state Signed-off-by: Mitch Gaffigan --- .../mirth/connect/client/ui/LoginPanel.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/client/src/com/mirth/connect/client/ui/LoginPanel.java b/client/src/com/mirth/connect/client/ui/LoginPanel.java index 284aff1d4..48cec8881 100644 --- a/client/src/com/mirth/connect/client/ui/LoginPanel.java +++ b/client/src/com/mirth/connect/client/ui/LoginPanel.java @@ -28,7 +28,6 @@ public class LoginPanel extends javax.swing.JFrame { - private Client client; private static final String ERROR_MESSAGE = "There was an error connecting to the server at the specified address. Please verify that the server is up and running."; private static LoginPanel instance = null; @@ -402,6 +401,7 @@ private void passwordActionPerformed(java.awt.event.ActionEvent evt)// GEN-FIRST private void loginButtonActionPerformed(java.awt.event.ActionEvent evt)// GEN-FIRST:event_loginButtonActionPerformed {// GEN-HEADEREND:event_loginButtonActionPerformed errorPane.setVisible(false); + LoginPanel loginPanel = this; SwingWorker worker = new SwingWorker() { @@ -410,7 +410,7 @@ public Void doInBackground() { try { String server = serverName.getText(); - client = new Client(server, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES); + Client client = new Client(server, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES); PlatformUI.SERVER_URL = server; // Attempt to login @@ -435,8 +435,8 @@ public Void doInBackground() { // If SUCCESS or SUCCESS_GRACE_PERIOD if (loginStatus != null && loginStatus.isSuccess()) { if (!Mirth.handleLoginSuccess(client, loginStatus, username.getText())) { - LoginPanel.getInstance().setVisible(false); - LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); + loginPanel.setVisible(false); + loginPanel.initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); } } else { // Assume failure unless overridden by a plugin @@ -454,8 +454,8 @@ public Void doInBackground() { if (loginStatus != null && loginStatus.isSuccess()) { errorOccurred = false; if (!Mirth.handleLoginSuccess(client, loginStatus, username.getText())) { - LoginPanel.getInstance().setVisible(false); - LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); + loginPanel.setVisible(false); + loginPanel.initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); } } } @@ -464,25 +464,16 @@ public Void doInBackground() { if (errorOccurred) { if (loginStatus != null) { - errorTextArea.setText(loginStatus.getMessage()); + setError(loginStatus.getMessage()); } else { - errorTextArea.setText(ERROR_MESSAGE); + setError(ERROR_MESSAGE); } } } catch (Throwable t) { - errorOccurred = true; - errorTextArea.setText(ERROR_MESSAGE); + setError(ERROR_MESSAGE); t.printStackTrace(); } - if (errorOccurred) { - errorPane.setVisible(true); - loggingIn.setVisible(false); - loginMain.setVisible(true); - loginProgress.setIndeterminate(false); - password.grabFocus(); - } - return null; } @@ -509,6 +500,15 @@ public void setStatus(String status) { this.status.setText("Please wait: " + status); } + public void setError(String status) { + errorTextArea.setText(status); + errorPane.setVisible(true); + loggingIn.setVisible(false); + loginMain.setVisible(true); + loginProgress.setIndeterminate(false); + password.grabFocus(); + } + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton closeButton; private javax.swing.JScrollPane errorPane; From e738ced1431f45442d40da9bfc4f45986da1f90b Mon Sep 17 00:00:00 2001 From: Mitch Gaffigan Date: Wed, 3 Sep 2025 09:55:00 -0500 Subject: [PATCH 3/3] Remove LoginPanel singleton to separate class to allow other implementations Signed-off-by: Mitch Gaffigan --- .../connect/client/ui/AbstractLoginPanel.java | 17 ++++++++++++++ .../com/mirth/connect/client/ui/Frame.java | 8 +++---- .../mirth/connect/client/ui/LoginPanel.java | 16 ++++--------- .../connect/client/ui/LoginPanelFactory.java | 23 +++++++++++++++++++ .../com/mirth/connect/client/ui/Mirth.java | 6 ++--- 5 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 client/src/com/mirth/connect/client/ui/AbstractLoginPanel.java create mode 100644 client/src/com/mirth/connect/client/ui/LoginPanelFactory.java diff --git a/client/src/com/mirth/connect/client/ui/AbstractLoginPanel.java b/client/src/com/mirth/connect/client/ui/AbstractLoginPanel.java new file mode 100644 index 000000000..0670d81ec --- /dev/null +++ b/client/src/com/mirth/connect/client/ui/AbstractLoginPanel.java @@ -0,0 +1,17 @@ +package com.mirth.connect.client.ui; + +/** + * Public interface for the login panel so alternative implementations can be provided. + */ +public abstract class AbstractLoginPanel extends javax.swing.JFrame { + + /** + * Initialize and show the login UI. + */ + public abstract void initialize(String mirthServer, String version, String user, String pass); + + /** + * Update the status text shown on the login UI. + */ + public abstract void setStatus(String status); +} diff --git a/client/src/com/mirth/connect/client/ui/Frame.java b/client/src/com/mirth/connect/client/ui/Frame.java index 633a2791a..8a366eac0 100644 --- a/client/src/com/mirth/connect/client/ui/Frame.java +++ b/client/src/com/mirth/connect/client/ui/Frame.java @@ -543,7 +543,7 @@ public void eventDispatched(AWTEvent e) */ public void setupFrame(Client mirthClient) throws ClientException { - LoginPanel login = LoginPanel.getInstance(); + AbstractLoginPanel login = LoginPanelFactory.getInstance(); // Initialize the send message dialog editMessageDialog = new EditMessageDialog(); @@ -1524,7 +1524,7 @@ public void alertThrowable(Component parentComponent, Throwable t, String custom } mirthClient.close(); this.dispose(); - LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); + LoginPanelFactory.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); return; } else if (t.getCause() != null && t.getCause() instanceof HttpHostConnectException && (StringUtils.contains(t.getCause().getMessage(), "Connection refused") || StringUtils.contains(t.getCause().getMessage(), "Host is down"))) { connectionError = true; @@ -1542,7 +1542,7 @@ public void alertThrowable(Component parentComponent, Throwable t, String custom } mirthClient.close(); this.dispose(); - LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); + LoginPanelFactory.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); return; } } @@ -2292,7 +2292,7 @@ public boolean logout(boolean quit, boolean confirmFirst) { this.dispose(); if (!quit) { - LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); + LoginPanelFactory.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); } return true; diff --git a/client/src/com/mirth/connect/client/ui/LoginPanel.java b/client/src/com/mirth/connect/client/ui/LoginPanel.java index 48cec8881..59b6274c1 100644 --- a/client/src/com/mirth/connect/client/ui/LoginPanel.java +++ b/client/src/com/mirth/connect/client/ui/LoginPanel.java @@ -26,12 +26,11 @@ import com.mirth.connect.model.LoginStatus; import com.mirth.connect.plugins.MultiFactorAuthenticationClientPlugin; -public class LoginPanel extends javax.swing.JFrame { +public class LoginPanel extends AbstractLoginPanel { private static final String ERROR_MESSAGE = "There was an error connecting to the server at the specified address. Please verify that the server is up and running."; - private static LoginPanel instance = null; - private LoginPanel() { + public LoginPanel() { initComponents(); DisplayUtil.setResizable(this, false); jLabel2.setForeground(UIConstants.HEADER_TITLE_TEXT_COLOR); @@ -69,15 +68,7 @@ public void mouseClicked(java.awt.event.MouseEvent evt) { errorTextArea.setDisabledTextColor(Color.RED); } - public static LoginPanel getInstance() { - synchronized (LoginPanel.class) { - if (instance == null) { - instance = new LoginPanel(); - } - return instance; - } - } - + @Override public void initialize(String mirthServer, String version, String user, String pass) { synchronized (this) { // Do not initialize another login window if one is already visible @@ -496,6 +487,7 @@ private void closeButtonActionPerformed(java.awt.event.ActionEvent evt)// GEN-FI System.exit(0); }// GEN-LAST:event_closeButtonActionPerformed + @Override public void setStatus(String status) { this.status.setText("Please wait: " + status); } diff --git a/client/src/com/mirth/connect/client/ui/LoginPanelFactory.java b/client/src/com/mirth/connect/client/ui/LoginPanelFactory.java new file mode 100644 index 000000000..a8fd67de2 --- /dev/null +++ b/client/src/com/mirth/connect/client/ui/LoginPanelFactory.java @@ -0,0 +1,23 @@ +package com.mirth.connect.client.ui; + +/** + * Factory for obtaining the application's LoginPanel implementation. + */ +public class LoginPanelFactory { + + private static AbstractLoginPanel provider = null; + + public static synchronized AbstractLoginPanel getInstance() { + if (provider == null) { + provider = new LoginPanel(); + } + return provider; + } + + /** + * Replace the current provider. This is used to switch between login implementations at runtime. + */ + public static synchronized void setProvider(AbstractLoginPanel newProvider) { + provider = newProvider; + } +} diff --git a/client/src/com/mirth/connect/client/ui/Mirth.java b/client/src/com/mirth/connect/client/ui/Mirth.java index 3292ccfd9..76206ec61 100644 --- a/client/src/com/mirth/connect/client/ui/Mirth.java +++ b/client/src/com/mirth/connect/client/ui/Mirth.java @@ -69,7 +69,7 @@ public Mirth(Client mirthClient) throws ClientException { UIManager.put("Tree.closedIcon", UIConstants.CLOSED_ICON); userPreferences = Preferences.userNodeForPackage(Mirth.class); - LoginPanel.getInstance().setStatus("Loading components..."); + LoginPanelFactory.getInstance().setStatus("Loading components..."); PlatformUI.MIRTH_FRAME.setupFrame(mirthClient); boolean maximized; @@ -129,7 +129,7 @@ public static void aboutMac() { * @return quit */ public static boolean quitMac() { - return (LoginPanel.getInstance().isVisible() || (PlatformUI.MIRTH_FRAME != null && PlatformUI.MIRTH_FRAME.logout(true))); + return (LoginPanelFactory.getInstance().isVisible() || (PlatformUI.MIRTH_FRAME != null && PlatformUI.MIRTH_FRAME.logout(true))); } /** @@ -291,7 +291,7 @@ private static void start(final String server, final String version, final Strin public void run() { initUIManager(); PlatformUI.BACKGROUND_IMAGE = new ImageIcon(com.mirth.connect.client.ui.Frame.class.getResource("images/header_nologo.png")); - LoginPanel.getInstance().initialize(server, version, username, password); + LoginPanelFactory.getInstance().initialize(server, version, username, password); } }); }