diff --git a/Core/nbproject/project.xml b/Core/nbproject/project.xml index be742fc4ac6f537f928a0e6dbd3bc5623299521f..e9e80c88ed1487a30cfa724b345ec007fb4cdb92 100644 --- a/Core/nbproject/project.xml +++ b/Core/nbproject/project.xml @@ -316,6 +316,7 @@ <package>org.sleuthkit.autopsy.casemodule.multiusercases</package> <package>org.sleuthkit.autopsy.casemodule.multiusercasesbrowser</package> <package>org.sleuthkit.autopsy.casemodule.services</package> + <package>org.sleuthkit.autopsy.centralrepository.settings</package> <package>org.sleuthkit.autopsy.contentviewers</package> <package>org.sleuthkit.autopsy.coordinationservice</package> <package>org.sleuthkit.autopsy.core</package> diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagNameDefinition.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagNameDefinition.java index f3645fd7c6443c06183277b2b5693a335f8e4c1d..60a38f3a84a8a63dd5e0cb665b3531e61c846487 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagNameDefinition.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagNameDefinition.java @@ -31,6 +31,7 @@ import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.centralrepository.settings.CentralRepoSettings; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.datamodel.TagName; @@ -375,7 +376,7 @@ private static void updatePropertyFile() { * @return A list of tag names, or empty list if none were found. */ private static List<String> getCRNotableList() { - String notableTagsProp = ModuleSettings.getConfigSetting("CentralRepository", "db.badTags"); // NON-NLS + String notableTagsProp = ModuleSettings.getConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "db.badTags"); // NON-NLS if (notableTagsProp != null && !notableTagsProp.isEmpty()) { return Arrays.asList(notableTagsProp.split(",")); } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java index d3a0e61ecf14998448f4b3f4c349bab9b3703541..95bfeca2b5d920c35c729805016727e94e98ebb4 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbManager.java @@ -24,6 +24,7 @@ import java.sql.SQLException; import java.util.logging.Level; import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.centralrepository.settings.CentralRepoSettings; import org.sleuthkit.autopsy.coordinationservice.CoordinationService; import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.coreutils.Logger; @@ -38,7 +39,7 @@ public class CentralRepoDbManager { private static final Logger logger = Logger.getLogger(CentralRepoDbManager.class.getName()); private static final String CENTRAL_REPO_DB_NAME = "central_repository"; - private static final String CENTRAL_REPOSITORY_SETTINGS_KEY = "CentralRepository"; + private static final String CENTRAL_REPOSITORY_SETTINGS_KEY = CentralRepoSettings.getInstance().getModuleSettingsKey(); private static final String DB_SELECTED_PLATFORM_KEY = "db.selectedPlatform"; private static final String DISABLED_DUE_TO_FAILURE_KEY = "disabledDueToFailure"; diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbUtil.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbUtil.java index 0b1c5970625e2224f77cec8037fc5acd06d11951..4ff0cb7a2e8c8288e0cca0a5b02014eb6518f59b 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbUtil.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDbUtil.java @@ -32,6 +32,7 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import static org.sleuthkit.autopsy.centralrepository.datamodel.RdbmsCentralRepo.SOFTWARE_CR_DB_SCHEMA_VERSION; +import org.sleuthkit.autopsy.centralrepository.settings.CentralRepoSettings; /** * @@ -39,7 +40,7 @@ public class CentralRepoDbUtil { private final static Logger LOGGER = Logger.getLogger(CentralRepoDbUtil.class.getName()); - private static final String CENTRAL_REPO_NAME = "CentralRepository"; + private static final String CENTRAL_REPO_NAME = CentralRepoSettings.getInstance().getModuleSettingsKey(); private static final String CENTRAL_REPO_USE_KEY = "db.useCentralRepo"; private static final String DEFAULT_ORG_NAME = "Not Specified"; diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoPostgresSettingsUtil.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoPostgresSettingsUtil.java index 86f929ba0e54125b0ab1e77c841f919205a2f8a7..bf47d92e359f2f21dccb4dccff5e7ce4f19d48c3 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoPostgresSettingsUtil.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoPostgresSettingsUtil.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; import java.util.logging.Level; +import org.sleuthkit.autopsy.centralrepository.settings.CentralRepoSettings; import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.core.UserPreferencesException; import org.sleuthkit.autopsy.coreutils.Logger; @@ -46,7 +47,7 @@ public class CentralRepoPostgresSettingsUtil { private static final String DBNAME_KEY = "db.postgresql.dbName"; private static final String HOST_KEY = "db.postgresql.host"; - private static final String MODULE_KEY = "CentralRepository"; + private static final String MODULE_KEY = CentralRepoSettings.getInstance().getModuleSettingsKey(); private static CentralRepoPostgresSettingsUtil instance = null; diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteCentralRepoSettings.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteCentralRepoSettings.java index 2e526944160760c6050b54487756e5d9d1e00aa3..807349af1adb60568e4f66368b1874661940315d 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteCentralRepoSettings.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteCentralRepoSettings.java @@ -29,6 +29,7 @@ import java.sql.SQLException; import java.util.logging.Level; import java.util.regex.Pattern; +import org.sleuthkit.autopsy.centralrepository.settings.CentralRepoSettings; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.PlatformUtil; @@ -41,13 +42,13 @@ */ public final class SqliteCentralRepoSettings implements CentralRepoDbConnectivityManager { - public final static String DEFAULT_DBNAME = "central_repository.db"; // NON-NLS + public final static String DEFAULT_DBNAME = CentralRepoSettings.getInstance().getDefaultDbName(); // NON-NLS private final static Logger LOGGER = Logger.getLogger(SqliteCentralRepoSettings.class.getName()); private final Path userConfigDir = Paths.get(PlatformUtil.getUserDirectory().getAbsolutePath()); - private final static String DEFAULT_DBDIRECTORY = PlatformUtil.getUserDirectory() + File.separator + "central_repository"; // NON-NLS + private final static String DEFAULT_DBDIRECTORY = CentralRepoSettings.getInstance().getDefaultDbPath(); //property names - private static final String PROFILE_NAME = "CentralRepository"; + private static final String PROFILE_NAME = CentralRepoSettings.getInstance().getModuleSettingsKey(); private static final String DATABASE_NAME = "db.sqlite.dbName"; //NON-NLS private static final String DATABASE_PATH = "db.sqlite.dbDirectory"; //NON-NLS private static final String BULK_THRESHOLD = "db.sqlite.bulkThreshold"; //NON-NLS diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java index 5835058630e746aeadf23dee04bb87ff0f1f7e96..0f11e750701256690bdab8e948a1d43f6e49256b 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/Installer.java @@ -28,6 +28,7 @@ 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.settings.CentralRepoSettings; import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.coreutils.Logger; @@ -88,7 +89,7 @@ public void restored() { * (in other words, developers are exempt from seeing the notification). */ private void setupDefaultCentralRepository() { - Map<String, String> centralRepoSettings = ModuleSettings.getConfigSettings("CentralRepository"); + Map<String, String> centralRepoSettings = ModuleSettings.getConfigSettings(CentralRepoSettings.getInstance().getModuleSettingsKey()); String initializedStr = centralRepoSettings.get("initialized"); // check to see if the repo has been initialized asking to setup cr @@ -100,7 +101,7 @@ private void setupDefaultCentralRepository() { // 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("CentralRepository", "initialized", "true"); + ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); } } @@ -126,7 +127,7 @@ private void setupDefaultCentralRepository() { doMessageBoxIfRunningInGUI(ex); } - ModuleSettings.setConfigSetting("CentralRepository", "initialized", "true"); + ModuleSettings.setConfigSetting(CentralRepoSettings.getInstance().getModuleSettingsKey(), "initialized", "true"); } /** diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/settings/CentralRepoSettings.java b/Core/src/org/sleuthkit/autopsy/centralrepository/settings/CentralRepoSettings.java new file mode 100644 index 0000000000000000000000000000000000000000..4af78f6ae1da68a690caadc61d01a7806ab3fd63 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/settings/CentralRepoSettings.java @@ -0,0 +1,75 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2022 Basis Technology Corp. + * Contact: carrier <at> sleuthkit <dot> 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.settings; + +import com.google.common.annotations.Beta; +import java.nio.file.Paths; +import org.sleuthkit.autopsy.coreutils.PlatformUtil; + +/** + * Location for central repo settings and paths. + */ +@Beta +public class CentralRepoSettings { + + private static final CentralRepoSettings instance = new CentralRepoSettings(); + + /** + * @return The singleton instance of this class. + */ + public static CentralRepoSettings getInstance() { + return instance; + } + + private static final String CENTRAL_REPOSITORY_FOLDER = "CentralRepository"; + private static final String CENTRAL_REPOSITORY_SETTINGS_NAME = "CentralRepository"; + private static final String CENTRAL_REPO_BASE_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), CENTRAL_REPOSITORY_FOLDER).toString(); + private static final String DEFAULT_DB_PARENT_PATH = Paths.get(CENTRAL_REPO_BASE_PATH, "LocalDatabase").toString(); + private static final String DEFAULT_DB_NAME = "central_repository.db"; + private static final String MODULE_SETTINGS_KEY = Paths.get(CENTRAL_REPOSITORY_FOLDER, CENTRAL_REPOSITORY_SETTINGS_NAME).toString(); + + /** + * @return The base path for central repository settings. + */ + public String getSettingsBaseFolder() { + return CENTRAL_REPO_BASE_PATH; + } + + /** + * @return The module settings key that places the settings file within + * getSettingsBaseFolder. + */ + public String getModuleSettingsKey() { + return MODULE_SETTINGS_KEY; + } + + /** + * @return The default database parent path for sqlite cr. + */ + public String getDefaultDbPath() { + return DEFAULT_DB_PARENT_PATH; + } + + /** + * @return The default sqlite database name. + */ + public String getDefaultDbName() { + return DEFAULT_DB_NAME; + } +} diff --git a/Core/test/qa-functional/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDatamodelTest.java b/Core/test/qa-functional/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDatamodelTest.java index 2101645962caf41db2015527e2781e248da521f1..4f7395bd4a4cf5ad20123643df2c210dbe1cb9cb 100755 --- a/Core/test/qa-functional/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDatamodelTest.java +++ b/Core/test/qa-functional/src/org/sleuthkit/autopsy/centralrepository/datamodel/CentralRepoDatamodelTest.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.centralrepository.datamodel; -import java.io.IOException; import java.util.Map; import java.util.List; import java.util.ArrayList; @@ -43,9 +42,8 @@ import org.sleuthkit.autopsy.casemodule.CaseDetails; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.datamodel.TskData; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.centralrepository.settings.CentralRepoSettings; import org.sleuthkit.autopsy.coreutils.FileUtil; /** @@ -59,7 +57,7 @@ */ public class CentralRepoDatamodelTest extends TestCase { - private static final String PROPERTIES_FILE = "CentralRepository"; + private static final String PROPERTIES_FILE = CentralRepoSettings.getInstance().getModuleSettingsKey(); private static final String CR_DB_NAME = "testcentralrepo.db"; private static final Path testDirectory = Paths.get(System.getProperty("java.io.tmpdir"), "CentralRepoDatamodelTest");