From ea75fcd45b3943163806299e763fd5b0013e3608 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Mon, 16 Oct 2023 21:14:36 -0400 Subject: [PATCH 1/3] move around code to prevent showing issue --- .../CentralRepositoryNotificationDialog.java | 5 +- .../eventlisteners/Installer.java | 71 ------------ .../eventlisteners/OnUIShowing.java | 107 ++++++++++++++++++ 3 files changed, 110 insertions(+), 73 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/OnUIShowing.java diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java index 883d979c90..aa2e908674 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java @@ -34,8 +34,9 @@ public class CentralRepositoryNotificationDialog { * application is running with a GUI. */ static boolean shouldDisplay() { - return Version.getBuildType() == Version.Type.RELEASE - && RuntimeProperties.runningWithGUI(); + return //Version.getBuildType() == Version.Type.RELEASE + //&& + RuntimeProperties.runningWithGUI(); } /** diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java index f15dec3029..f5b486e78d 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java @@ -90,7 +90,6 @@ public class Installer extends ModuleInstall { public void restored() { // must happen first to move any legacy settings that exist. upgradeSettingsPath(); - setupDefaultCentralRepository(); } @@ -151,76 +150,6 @@ public class Installer extends ModuleInstall { } } - /** - * Checks if the central repository has been set up and configured. If not, - * does the set up unconditionally. If the application is running with a - * GUI, a notification will be displayed to the user if the mode is RELEASE - * (in other words, developers are exempt from seeing the notification). - */ - private void setupDefaultCentralRepository() { - Map centralRepoSettings = ModuleSettings.getConfigSettings(CentralRepoSettings.getInstance().getModuleSettingsKey()); - String initializedStr = centralRepoSettings.get("initialized"); - - // check to see if the repo has been initialized asking to setup cr - boolean initialized = Boolean.parseBoolean(initializedStr); - - // if it hasn't received that flag, check for a previous install where cr is already setup - if (!initialized) { - boolean prevRepo = Boolean.parseBoolean(centralRepoSettings.get("db.useCentralRepo")); - // if it has been previously set up and is in use, mark as previously initialized and save the settings - if (prevRepo) { - initialized = true; - ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); - } - } - - if(initialized) { - return; // Nothing to do - } - - if (CentralRepositoryNotificationDialog.shouldDisplay()) { - CentralRepositoryNotificationDialog.display(); - } - - try { - CentralRepoDbManager manager = new CentralRepoDbManager(); - if (UserPreferences.getIsMultiUserModeEnabled()) { - // Set up using existing multi-user settings. - manager.setupPostgresDb(CentralRepoDbChoice.POSTGRESQL_MULTIUSER); - } else { - manager.setupDefaultSqliteDb(); - } - } catch (CentralRepoException ex) { - logger.log(Level.SEVERE, "There was an error while initializing the central repository database", ex); - - doMessageBoxIfRunningInGUI(ex); - } - - ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); - } - - /** - * Display a central repository exception in a message box if running with a - * GUI. - * - * @param ex The exception. - */ - @NbBundle.Messages({"Installer.centralRepoUpgradeFailed.title=Central repository disabled"}) - private void doMessageBoxIfRunningInGUI(CentralRepoException ex) { - if (RuntimeProperties.runningWithGUI()) { - try { - SwingUtilities.invokeAndWait(() -> { - JOptionPane.showMessageDialog(null, - ex.getUserMessage(), - NbBundle.getMessage(this.getClass(), "Installer.centralRepoUpgradeFailed.title"), - JOptionPane.ERROR_MESSAGE); - }); - } catch (InterruptedException | InvocationTargetException e) { - logger.log(Level.WARNING, e.getMessage(), e); - } - } - } - @Override public void uninstalled() { /* diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/OnUIShowing.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/OnUIShowing.java new file mode 100644 index 0000000000..5db0906748 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/OnUIShowing.java @@ -0,0 +1,107 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package org.sleuthkit.autopsy.centralrepository.eventlisteners; + +import java.lang.reflect.InvocationTargetException; +import java.util.Map; +import java.util.logging.Level; +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; +import org.openide.util.NbBundle; +import org.openide.windows.OnShowing; +import org.sleuthkit.autopsy.centralrepository.CentralRepoSettings; +import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbChoice; +import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbManager; +import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoException; +import org.sleuthkit.autopsy.core.RuntimeProperties; +import org.sleuthkit.autopsy.core.UserPreferences; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.coreutils.ModuleSettings; + +/** + * + * @author gregd + */ +@OnShowing +public class OnUIShowing implements Runnable { + private static final Logger logger = Logger.getLogger(OnUIShowing.class.getName()); + + @Override + public void run() { + setupDefaultCentralRepository(); + } + + /** + * Checks if the central repository has been set up and configured. If not, + * does the set up unconditionally. If the application is running with a + * GUI, a notification will be displayed to the user if the mode is RELEASE + * (in other words, developers are exempt from seeing the notification). + */ + private void setupDefaultCentralRepository() { + Map centralRepoSettings = ModuleSettings.getConfigSettings(CentralRepoSettings.getInstance().getModuleSettingsKey()); + String initializedStr = centralRepoSettings.get("initialized"); + + // check to see if the repo has been initialized asking to setup cr + boolean initialized = Boolean.parseBoolean(initializedStr); + + // if it hasn't received that flag, check for a previous install where cr is already setup + if (!initialized) { + boolean prevRepo = Boolean.parseBoolean(centralRepoSettings.get("db.useCentralRepo")); + // if it has been previously set up and is in use, mark as previously initialized and save the settings + if (prevRepo) { + initialized = true; + ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); + } + } + + if(initialized) { + return; // Nothing to do + } + + if (CentralRepositoryNotificationDialog.shouldDisplay()) { + CentralRepositoryNotificationDialog.display(); + } + + try { + CentralRepoDbManager manager = new CentralRepoDbManager(); + if (UserPreferences.getIsMultiUserModeEnabled()) { + // Set up using existing multi-user settings. + manager.setupPostgresDb(CentralRepoDbChoice.POSTGRESQL_MULTIUSER); + } else { + manager.setupDefaultSqliteDb(); + } + } catch (CentralRepoException ex) { + logger.log(Level.SEVERE, "There was an error while initializing the central repository database", ex); + + doMessageBoxIfRunningInGUI(ex); + } + + ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); + } + + /** + * Display a central repository exception in a message box if running with a + * GUI. + * + * @param ex The exception. + */ + @NbBundle.Messages({"Installer.centralRepoUpgradeFailed.title=Central repository disabled"}) + private void doMessageBoxIfRunningInGUI(CentralRepoException ex) { + if (RuntimeProperties.runningWithGUI()) { + try { + SwingUtilities.invokeAndWait(() -> { + JOptionPane.showMessageDialog(null, + ex.getUserMessage(), + NbBundle.getMessage(this.getClass(), "Installer.centralRepoUpgradeFailed.title"), + JOptionPane.ERROR_MESSAGE); + }); + } catch (InterruptedException | InvocationTargetException e) { + logger.log(Level.WARNING, e.getMessage(), e); + } + } + } + + +} From e4d240e6f04c77054bda974b4f308a3ded28bfd9 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Thu, 19 Oct 2023 13:54:46 -0400 Subject: [PATCH 2/3] updates to display when gui opens but before startup window --- ...Showing.java => CRDefaultSetupAction.java} | 60 +++++++++++-------- .../CentralRepositoryNotificationDialog.java | 4 +- .../eventlisteners/Installer.java | 9 --- .../autopsy/corecomponents/Installer.java | 24 +++++++- 4 files changed, 60 insertions(+), 37 deletions(-) rename Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/{OnUIShowing.java => CRDefaultSetupAction.java} (71%) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/OnUIShowing.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CRDefaultSetupAction.java similarity index 71% rename from Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/OnUIShowing.java rename to Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CRDefaultSetupAction.java index 5db0906748..fc514ff5f7 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/OnUIShowing.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CRDefaultSetupAction.java @@ -1,6 +1,20 @@ /* - * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license - * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + * Autopsy Forensic Browser + * + * Copyright 2017-2020 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.sleuthkit.autopsy.centralrepository.eventlisteners; @@ -10,7 +24,6 @@ import java.util.logging.Level; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import org.openide.util.NbBundle; -import org.openide.windows.OnShowing; import org.sleuthkit.autopsy.centralrepository.CentralRepoSettings; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbChoice; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbManager; @@ -21,25 +34,28 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; /** - * - * @author gregd + * Runs the default setup for central repository and notifies the user if a) + * running with GUI and b) first launch. */ -@OnShowing -public class OnUIShowing implements Runnable { - private static final Logger logger = Logger.getLogger(OnUIShowing.class.getName()); +public class CRDefaultSetupAction { + + private static final Logger logger = Logger.getLogger(CRDefaultSetupAction.class.getName()); + private static final CRDefaultSetupAction INSTANCE = new CRDefaultSetupAction(); - @Override - public void run() { - setupDefaultCentralRepository(); + public static CRDefaultSetupAction getInstance() { + return INSTANCE; } - + + private CRDefaultSetupAction() { + } + /** * Checks if the central repository has been set up and configured. If not, - * does the set up unconditionally. If the application is running with a - * GUI, a notification will be displayed to the user if the mode is RELEASE - * (in other words, developers are exempt from seeing the notification). + * does the set up unconditionally. + * + * @return Returns true if first run and a default CR was setup. */ - private void setupDefaultCentralRepository() { + public boolean setupDefaultCentralRepository() { Map centralRepoSettings = ModuleSettings.getConfigSettings(CentralRepoSettings.getInstance().getModuleSettingsKey()); String initializedStr = centralRepoSettings.get("initialized"); @@ -55,13 +71,9 @@ public class OnUIShowing implements Runnable { ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); } } - - if(initialized) { - return; // Nothing to do - } - if (CentralRepositoryNotificationDialog.shouldDisplay()) { - CentralRepositoryNotificationDialog.display(); + if (initialized) { + return false; // Nothing to do } try { @@ -79,8 +91,9 @@ public class OnUIShowing implements Runnable { } ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); + return true; } - + /** * Display a central repository exception in a message box if running with a * GUI. @@ -103,5 +116,4 @@ public class OnUIShowing implements Runnable { } } - } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java index aa2e908674..5c18c4235e 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java @@ -33,7 +33,7 @@ public class CentralRepositoryNotificationDialog { * This dialog should display iff the mode is RELEASE and the * application is running with a GUI. */ - static boolean shouldDisplay() { + public static boolean shouldDisplay() { return //Version.getBuildType() == Version.Type.RELEASE //&& RuntimeProperties.runningWithGUI(); @@ -51,7 +51,7 @@ public class CentralRepositoryNotificationDialog { "CentralRepositoryNotificationDialog.bulletThree=Create personas that group accounts", "CentralRepositoryNotificationDialog.finalRemarks=To limit what is stored, use the Central Repository options panel." }) - static void display() { + public static void display() { assert shouldDisplay(); MessageNotifyUtil.Message.info( diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java index f5b486e78d..d233e2764f 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java @@ -20,21 +20,12 @@ package org.sleuthkit.autopsy.centralrepository.eventlisteners; import java.io.File; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.nio.file.Paths; import java.util.Map; import java.util.logging.Level; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; import org.apache.commons.io.FileUtils; import org.openide.modules.ModuleInstall; -import org.openide.util.NbBundle; -import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbChoice; -import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbManager; -import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoException; import org.sleuthkit.autopsy.centralrepository.CentralRepoSettings; -import org.sleuthkit.autopsy.core.RuntimeProperties; -import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.PlatformUtil; diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/Installer.java b/Core/src/org/sleuthkit/autopsy/corecomponents/Installer.java index 74412e9c62..b5b4fd5b4d 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/Installer.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/Installer.java @@ -43,6 +43,8 @@ import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.casemodule.StartupWindowProvider; +import org.sleuthkit.autopsy.centralrepository.eventlisteners.CRDefaultSetupAction; +import org.sleuthkit.autopsy.centralrepository.eventlisteners.CentralRepositoryNotificationDialog; import org.sleuthkit.autopsy.commandlineingest.CommandLineOptionProcessor; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; @@ -89,6 +91,12 @@ public class Installer extends ModuleInstall { final CommandLineOptionProcessor finalprocessor = processor; + /** + * Runs central repo default setup. Triggered here to track if this is + * first time setup in order to show CR notification dialog prior to any + * startup window. + */ + final boolean crFirstTimeSetup = CRDefaultSetupAction.getInstance().setupDefaultCentralRepository(); // When the --nogui flag is supplied invokeWhenUIReady happens a lot sooner // than it would when running wiht the gui. Makes sense. That means that @@ -102,19 +110,31 @@ public class Installer extends ModuleInstall { // be called. WindowManager.getDefault().invokeWhenUIReady(() -> { if(WindowManager.getDefault().getMainWindow().isVisible() || finalprocessor == null || finalprocessor.getState() == CommandLineOptionProcessor.ProcessState.COMPLETED) { - StartupWindowProvider.getInstance().open(); + showStartupWindows(crFirstTimeSetup); } else { finalprocessor.addPropertyChangeListener(new PropertyChangeListener(){ @Override public void propertyChange(PropertyChangeEvent evt) { if(evt.getPropertyName().equals(CommandLineOptionProcessor.PROCESSING_COMPLETED)) { - StartupWindowProvider.getInstance().open(); + showStartupWindows(crFirstTimeSetup); } } }); } }); } + + /** + * Show startup window(s) in sequence. + * @param crFirstTimeSetup If true, attempts to show the central repo notification dialog + */ + private void showStartupWindows(boolean crFirstTimeSetup) { + if (crFirstTimeSetup && CentralRepositoryNotificationDialog.shouldDisplay()) { + CentralRepositoryNotificationDialog.display(); + } + + StartupWindowProvider.getInstance().open(); + } @Override public void uninstalled() { From ced30868fddf0893cfaaafa6468efccdd335b42f Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Thu, 19 Oct 2023 15:15:21 -0400 Subject: [PATCH 3/3] fix --- .../eventlisteners/CentralRepositoryNotificationDialog.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java index 5c18c4235e..39ce238b2d 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CentralRepositoryNotificationDialog.java @@ -34,9 +34,8 @@ public class CentralRepositoryNotificationDialog { * application is running with a GUI. */ public static boolean shouldDisplay() { - return //Version.getBuildType() == Version.Type.RELEASE - //&& - RuntimeProperties.runningWithGUI(); + return Version.getBuildType() == Version.Type.RELEASE + && RuntimeProperties.runningWithGUI(); } /**