44
55package com .mirth .connect .client .ui ;
66
7- import static com .mirth .connect .client .core .BrandingConstants .CHECK_FOR_NOTIFICATIONS ;
8-
97import java .awt .Color ;
108import java .awt .Cursor ;
119import java .util .Collections ;
1210import java .util .HashMap ;
13- import java .util .HashSet ;
1411import java .util .List ;
1512import java .util .Map ;
16- import java .util .Properties ;
1713import java .util .Set ;
18- import java .util .prefs .Preferences ;
1914
2015import javax .swing .ImageIcon ;
2116import javax .swing .SwingWorker ;
2217
23- import org .apache .commons .lang3 .BooleanUtils ;
2418import org .apache .commons .lang3 .StringUtils ;
2519
2620import com .mirth .connect .client .core .Client ;
2721import com .mirth .connect .client .core .ClientException ;
28- import com .mirth .connect .client .core .ConnectServiceUtil ;
2922import com .mirth .connect .client .core .UnauthorizedException ;
3023import com .mirth .connect .client .core .api .servlets .UserServletInterface ;
3124import com .mirth .connect .client .ui .util .DisplayUtil ;
3225import com .mirth .connect .model .ExtendedLoginStatus ;
3326import com .mirth .connect .model .LoginStatus ;
34- import com .mirth .connect .model .PublicServerSettings ;
35- import com .mirth .connect .model .User ;
36- import com .mirth .connect .model .converters .ObjectXMLSerializer ;
3727import com .mirth .connect .plugins .MultiFactorAuthenticationClientPlugin ;
38- import com .mirth .connect .util .MirthSSLUtil ;
3928
4029public class LoginPanel extends javax .swing .JFrame {
4130
@@ -97,8 +86,6 @@ public void initialize(String mirthServer, String version, String user, String p
9786 return ;
9887 }
9988
100- PlatformUI .CLIENT_VERSION = version ;
101-
10289 setTitle (String .format ("%s %s - Login" , BrandingConstants .PRODUCT_NAME , version ));
10390 setIconImage (BrandingConstants .FAVICON .getImage ());
10491
@@ -447,7 +434,7 @@ public Void doInBackground() {
447434
448435 // If SUCCESS or SUCCESS_GRACE_PERIOD
449436 if (loginStatus != null && loginStatus .isSuccess ()) {
450- if (!handleSuccess ( loginStatus )) {
437+ if (!Mirth . handleLoginSuccess ( client , loginStatus , username . getText () )) {
451438 LoginPanel .getInstance ().setVisible (false );
452439 LoginPanel .getInstance ().initialize (PlatformUI .SERVER_URL , PlatformUI .CLIENT_VERSION , "" , "" );
453440 }
@@ -466,7 +453,7 @@ public Void doInBackground() {
466453
467454 if (loginStatus != null && loginStatus .isSuccess ()) {
468455 errorOccurred = false ;
469- if (!handleSuccess ( loginStatus )) {
456+ if (!Mirth . handleLoginSuccess ( client , loginStatus , username . getText () )) {
470457 LoginPanel .getInstance ().setVisible (false );
471458 LoginPanel .getInstance ().initialize (PlatformUI .SERVER_URL , PlatformUI .CLIENT_VERSION , "" , "" );
472459 }
@@ -499,141 +486,6 @@ public Void doInBackground() {
499486 return null ;
500487 }
501488
502- private boolean handleSuccess (LoginStatus loginStatus ) throws ClientException {
503- try {
504- PublicServerSettings publicServerSettings = client .getPublicServerSettings ();
505-
506- if (publicServerSettings .getLoginNotificationEnabled () == true ) {
507- CustomBannerPanelDialog customBannerPanelDialog = new CustomBannerPanelDialog (LoginPanel .getInstance (), "Login Notification" , publicServerSettings .getLoginNotificationMessage ());
508- boolean isAccepted = customBannerPanelDialog .isAccepted ();
509-
510- if (isAccepted == true ) {
511- client .setUserNotificationAcknowledged (client .getCurrentUser ().getId ());
512- }
513- else {
514- return false ;
515- }
516- }
517-
518- String environmentName = publicServerSettings .getEnvironmentName ();
519- if (!StringUtils .isBlank (environmentName )) {
520- PlatformUI .ENVIRONMENT_NAME = environmentName ;
521- }
522-
523- String serverName = publicServerSettings .getServerName ();
524- if (!StringUtils .isBlank (serverName )) {
525- PlatformUI .SERVER_NAME = serverName ;
526- } else {
527- PlatformUI .SERVER_NAME = null ;
528- }
529-
530- Color defaultBackgroundColor = publicServerSettings .getDefaultAdministratorBackgroundColor ();
531- if (defaultBackgroundColor != null ) {
532- PlatformUI .DEFAULT_BACKGROUND_COLOR = defaultBackgroundColor ;
533- }
534- } catch (ClientException e ) {
535- PlatformUI .SERVER_NAME = null ;
536- }
537-
538- try {
539- String database = (String ) client .getAbout ().get ("database" );
540- if (!StringUtils .isBlank (database )) {
541- PlatformUI .SERVER_DATABASE = database ;
542- } else {
543- PlatformUI .SERVER_DATABASE = null ;
544- }
545- } catch (ClientException e ) {
546- PlatformUI .SERVER_DATABASE = null ;
547- }
548-
549- try {
550- Map <String , String []> map = client .getProtocolsAndCipherSuites ();
551- PlatformUI .SERVER_HTTPS_SUPPORTED_PROTOCOLS = map .get (MirthSSLUtil .KEY_SUPPORTED_PROTOCOLS );
552- PlatformUI .SERVER_HTTPS_ENABLED_CLIENT_PROTOCOLS = map .get (MirthSSLUtil .KEY_ENABLED_CLIENT_PROTOCOLS );
553- PlatformUI .SERVER_HTTPS_ENABLED_SERVER_PROTOCOLS = map .get (MirthSSLUtil .KEY_ENABLED_SERVER_PROTOCOLS );
554- PlatformUI .SERVER_HTTPS_SUPPORTED_CIPHER_SUITES = map .get (MirthSSLUtil .KEY_SUPPORTED_CIPHER_SUITES );
555- PlatformUI .SERVER_HTTPS_ENABLED_CIPHER_SUITES = map .get (MirthSSLUtil .KEY_ENABLED_CIPHER_SUITES );
556- } catch (ClientException e ) {
557- }
558-
559- PlatformUI .USER_NAME = StringUtils .defaultString (loginStatus .getUpdatedUsername (), username .getText ());
560- setStatus ("Authenticated..." );
561- new Mirth (client );
562- LoginPanel .getInstance ().setVisible (false );
563-
564- User currentUser = PlatformUI .MIRTH_FRAME .getCurrentUser (PlatformUI .MIRTH_FRAME );
565- Properties userPreferences = new Properties ();
566- Set <String > preferenceNames = new HashSet <String >();
567- preferenceNames .add ("firstlogin" );
568- preferenceNames .add ("checkForNotifications" );
569- preferenceNames .add ("showNotificationPopup" );
570- preferenceNames .add ("archivedNotifications" );
571- try {
572- userPreferences = client .getUserPreferences (currentUser .getId (), preferenceNames );
573-
574- // Display registration dialog if it's the user's first time logging in
575- String firstlogin = userPreferences .getProperty ("firstlogin" );
576- if (firstlogin == null || BooleanUtils .toBoolean (firstlogin )) {
577- if (Integer .valueOf (currentUser .getId ()) == 1 ) {
578- // if current user is user 1:
579- // 1. check system preferences for user information
580- // 2. if system preferences exist, populate screen using currentUser
581- Preferences preferences = Preferences .userNodeForPackage (Mirth .class );
582- String systemUserInfo = preferences .get ("userLoginInfo" , null );
583- if (systemUserInfo != null ) {
584- String info [] = systemUserInfo .split ("," , 0 );
585- currentUser .setUsername (info [0 ]);
586- currentUser .setFirstName (info [1 ]);
587- currentUser .setLastName (info [2 ]);
588- currentUser .setEmail (info [3 ]);
589- currentUser .setCountry (info [4 ]);
590- currentUser .setStateTerritory (info [5 ]);
591- currentUser .setPhoneNumber (info [6 ]);
592- currentUser .setOrganization (info [7 ]);
593- currentUser .setRole (info [8 ]);
594- currentUser .setIndustry (info [9 ]);
595- currentUser .setDescription (info [10 ]);
596- }
597- }
598- FirstLoginDialog firstLoginDialog = new FirstLoginDialog (currentUser );
599- // if leaving the first login dialog without saving
600- if (!firstLoginDialog .getResult ()) {
601- return false ;
602- }
603- } else if (loginStatus .getStatus () == LoginStatus .Status .SUCCESS_GRACE_PERIOD ) {
604- new ChangePasswordDialog (currentUser , loginStatus .getMessage ());
605- }
606-
607- // Check for new notifications from update server if enabled
608- String checkForNotifications = userPreferences .getProperty ("checkForNotifications" );
609- if (CHECK_FOR_NOTIFICATIONS
610- && (checkForNotifications == null || BooleanUtils .toBoolean (checkForNotifications ))) {
611- Set <Integer > archivedNotifications = new HashSet <Integer >();
612- String archivedNotificationString = userPreferences .getProperty ("archivedNotifications" );
613- if (archivedNotificationString != null ) {
614- archivedNotifications = ObjectXMLSerializer .getInstance ().deserialize (archivedNotificationString , Set .class );
615- }
616- // Update the Other Tasks pane with the unarchived notification count
617- int unarchivedNotifications = ConnectServiceUtil .getNotificationCount (PlatformUI .SERVER_ID , PlatformUI .SERVER_VERSION , LoadedExtensions .getInstance ().getExtensionVersions (), archivedNotifications , PlatformUI .HTTPS_PROTOCOLS , PlatformUI .HTTPS_CIPHER_SUITES );
618- PlatformUI .MIRTH_FRAME .updateNotificationTaskName (unarchivedNotifications );
619-
620- // Display notification dialog if enabled and if there are new notifications
621- String showNotificationPopup = userPreferences .getProperty ("showNotificationPopup" );
622- if (showNotificationPopup == null || BooleanUtils .toBoolean (showNotificationPopup )) {
623- if (unarchivedNotifications > 0 ) {
624- new NotificationDialog ();
625- }
626- }
627- }
628- } catch (ClientException e ) {
629- PlatformUI .MIRTH_FRAME .alertThrowable (PlatformUI .MIRTH_FRAME , e );
630- }
631-
632- PlatformUI .MIRTH_FRAME .sendUsageStatistics ();
633-
634- return true ;
635- }
636-
637489 public void done () {}
638490 };
639491 worker .execute ();
0 commit comments