updates from PR

This commit is contained in:
Greg DiCristofaro 2020-03-06 08:36:42 -05:00
parent d093a2169b
commit 167c12f00c
9 changed files with 46 additions and 52 deletions

View File

@ -18,23 +18,22 @@
*/ */
package org.sleuthkit.autopsy.centralrepository.datamodel; package org.sleuthkit.autopsy.centralrepository.datamodel;
import org.openide.util.NbBundle.Messages;
/** /**
* the database choices available for central repo * the database choices available for central repo
*/ */
public class CentralRepoDbChoice { @Messages({
public static final CentralRepoDbChoice DISABLED = new CentralRepoDbChoice("Disabled", CentralRepoPlatforms.DISABLED); "CentralRepoDbChoice.Disabled.Text=Disabled",
"CentralRepoDbChoice.Sqlite.Text=SQLite",
public static final CentralRepoDbChoice SQLITE = new CentralRepoDbChoice("Sqlite", "SQLite", CentralRepoPlatforms.SQLITE); "CentralRepoDbChoice.PostgreSQL_Multiuser.Text=PostgreSQL using multi-user settings",
"CentralRepoDbChoice.PostgreSQL.Text=Custom PostgreSQL",
public static final CentralRepoDbChoice POSTGRESQL_MULTIUSER = })
new CentralRepoDbChoice("PostgreSQL_Multiuser", "PostgreSQL using multi-user settings", CentralRepoPlatforms.POSTGRESQL); public enum CentralRepoDbChoice {
DISABLED("Disabled", Bundle.CentralRepoDbChoice_Disabled_Text(), CentralRepoPlatforms.DISABLED),
public static final CentralRepoDbChoice POSTGRESQL_CUSTOM = SQLITE("Sqlite", Bundle.CentralRepoDbChoice_Sqlite_Text(), CentralRepoPlatforms.SQLITE),
new CentralRepoDbChoice("PostgreSQL", "Custom PostgreSQL", CentralRepoPlatforms.POSTGRESQL); POSTGRESQL_MULTIUSER("PostgreSQL_Multiuser", Bundle.CentralRepoDbChoice_PostgreSQL_Multiuser_Text(), CentralRepoPlatforms.POSTGRESQL),
POSTGRESQL_CUSTOM("PostgreSQL", Bundle.CentralRepoDbChoice_PostgreSQL_Text(), CentralRepoPlatforms.POSTGRESQL);
public static final CentralRepoDbChoice[] CHOICES = new CentralRepoDbChoice[]{
DISABLED, SQLITE, POSTGRESQL_MULTIUSER, POSTGRESQL_CUSTOM
};
public static final CentralRepoDbChoice[] DB_CHOICES = new CentralRepoDbChoice[]{ public static final CentralRepoDbChoice[] DB_CHOICES = new CentralRepoDbChoice[]{
SQLITE, POSTGRESQL_MULTIUSER, POSTGRESQL_CUSTOM SQLITE, POSTGRESQL_MULTIUSER, POSTGRESQL_CUSTOM
@ -50,10 +49,6 @@ public class CentralRepoDbChoice {
this.title = title; this.title = title;
this.platform = platform; this.platform = platform;
} }
CentralRepoDbChoice(String key, CentralRepoPlatforms platform) {
this(key, key, platform);
}
public String getSettingKey() { public String getSettingKey() {
return settingKey; return settingKey;

View File

@ -37,14 +37,14 @@ public class CentralRepoDbManager {
private static volatile CentralRepoDbChoice SAVED_CHOICE = null; private static volatile CentralRepoDbChoice savedChoice = null;
/** /**
* Save the selected platform to the config file. * Save the selected platform to the config file.
*/ */
public static synchronized CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice) { public static synchronized CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice) {
choice = (choice == null) ? CentralRepoDbChoice.DISABLED : choice; choice = (choice == null) ? CentralRepoDbChoice.DISABLED : choice;
SAVED_CHOICE = choice; savedChoice = choice;
ModuleSettings.setConfigSetting("CentralRepository", "db.selectedPlatform", choice.getSettingKey()); ModuleSettings.setConfigSetting("CentralRepository", "db.selectedPlatform", choice.getSettingKey());
return choice; return choice;
} }
@ -53,17 +53,17 @@ public class CentralRepoDbManager {
* Load the selectedPlatform boolean from the config file, if it is set. * Load the selectedPlatform boolean from the config file, if it is set.
*/ */
public static synchronized CentralRepoDbChoice getSavedDbChoice() { public static synchronized CentralRepoDbChoice getSavedDbChoice() {
if (SAVED_CHOICE == null) { if (savedChoice == null) {
String selectedPlatformString = ModuleSettings.getConfigSetting("CentralRepository", "db.selectedPlatform"); // NON-NLS String selectedPlatformString = ModuleSettings.getConfigSetting("CentralRepository", "db.selectedPlatform"); // NON-NLS
SAVED_CHOICE = fromKey(selectedPlatformString); savedChoice = fromKey(selectedPlatformString);
} }
return SAVED_CHOICE; return savedChoice;
} }
private static CentralRepoDbChoice fromKey(String keyName) { private static CentralRepoDbChoice fromKey(String keyName) {
for (CentralRepoDbChoice dbChoice : CentralRepoDbChoice.CHOICES) { for (CentralRepoDbChoice dbChoice : CentralRepoDbChoice.values()) {
if (dbChoice.getSettingKey().equalsIgnoreCase(keyName)) { if (dbChoice.getSettingKey().equalsIgnoreCase(keyName)) {
return dbChoice; return dbChoice;
} }
@ -201,8 +201,8 @@ public class CentralRepoDbManager {
public CentralRepoDbManager() { public CentralRepoDbManager() {
selectedDbChoice = getSavedDbChoice(); selectedDbChoice = getSavedDbChoice();
dbSettingsPostgres = new PostgresCentralRepoSettings(PostgresSettingsLoader.CUSTOM_LOADER); dbSettingsPostgres = new PostgresCentralRepoSettings(PostgresSettingsLoader.CUSTOM_SETTINGS_LOADER);
dbSettingsMultiUser = new PostgresCentralRepoSettings(PostgresSettingsLoader.MULTIUSER_LOADER); dbSettingsMultiUser = new PostgresCentralRepoSettings(PostgresSettingsLoader.MULTIUSER_SETTINGS_LOADER);
dbSettingsSqlite = new SqliteCentralRepoSettings(); dbSettingsSqlite = new SqliteCentralRepoSettings();
} }
@ -236,7 +236,7 @@ public class CentralRepoDbManager {
} }
// the only successful setup status is tested ok // the only successful setup status is tested ok
if (curStatus != DatabaseTestResult.TESTEDOK) { if (curStatus != DatabaseTestResult.TESTED_OK) {
throw new CentralRepoException("Unable to successfully create sqlite database"); throw new CentralRepoException("Unable to successfully create sqlite database");
} }
@ -320,7 +320,7 @@ public class CentralRepoDbManager {
throw new CentralRepoException(schemaError); throw new CentralRepoException(schemaError);
} }
testingStatus = DatabaseTestResult.TESTEDOK; testingStatus = DatabaseTestResult.TESTED_OK;
return true; return true;
} }
@ -360,7 +360,7 @@ public class CentralRepoDbManager {
selectedDbSettings.saveSettings(); selectedDbSettings.saveSettings();
// Load those newly saved settings into the postgres db manager instance // Load those newly saved settings into the postgres db manager instance
// in case we are still using the same instance. // in case we are still using the same instance.
if (selectedDbChoice != null && selectedDbSettings != CentralRepoDbChoice.DISABLED) { if (selectedDbChoice != null && selectedDbChoice != CentralRepoDbChoice.DISABLED) {
try { try {
logger.info("Saving central repo settings for db: " + selectedDbSettings); logger.info("Saving central repo settings for db: " + selectedDbSettings);
CentralRepository.getInstance().updateSettings(); CentralRepository.getInstance().updateSettings();

View File

@ -81,7 +81,7 @@ public class CentralRepoPostgresSettingsUtil {
} }
} }
private static void handleTry(TryHandler handler) { private static void logException(TryHandler handler) {
try { try {
handler.operation(); handler.operation();
} }
@ -109,14 +109,14 @@ public class CentralRepoPostgresSettingsUtil {
return settings; return settings;
} }
handleTry(() -> settings.setHost(valOrDefault(muConn.getHost(), DEFAULT_HOST))); logException(() -> settings.setHost(valOrDefault(muConn.getHost(), DEFAULT_HOST)));
handleTry(() -> settings.setDbName(DEFAULT_DBNAME)); logException(() -> settings.setDbName(DEFAULT_DBNAME));
handleTry(() -> settings.setUserName(valOrDefault(muConn.getUserName(), DEFAULT_USERNAME))); logException(() -> settings.setUserName(valOrDefault(muConn.getUserName(), DEFAULT_USERNAME)));
handleTry(() -> settings.setPort(valOrDefault(muConn.getPort(), DEFAULT_PORT, 1, 65535))); logException(() -> settings.setPort(valOrDefault(muConn.getPort(), DEFAULT_PORT, 1, 65535)));
handleTry(() -> settings.setBulkThreshold(RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD)); logException(() -> settings.setBulkThreshold(RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD));
handleTry(() -> settings.setPassword(valOrDefault(muConn.getPassword(), DEFAULT_PASSWORD))); logException(() -> settings.setPassword(valOrDefault(muConn.getPassword(), DEFAULT_PASSWORD)));
return settings; return settings;
} }
@ -127,12 +127,12 @@ public class CentralRepoPostgresSettingsUtil {
Map<String, String> keyVals = ModuleSettings.getConfigSettings(MODULE_KEY); Map<String, String> keyVals = ModuleSettings.getConfigSettings(MODULE_KEY);
handleTry(() -> settings.setHost(valOrDefault(keyVals.get(HOST_KEY), DEFAULT_HOST))); logException(() -> settings.setHost(valOrDefault(keyVals.get(HOST_KEY), DEFAULT_HOST)));
handleTry(() -> settings.setDbName(valOrDefault(keyVals.get(DBNAME_KEY), DEFAULT_DBNAME))); logException(() -> settings.setDbName(valOrDefault(keyVals.get(DBNAME_KEY), DEFAULT_DBNAME)));
handleTry(() -> settings.setUserName(valOrDefault(keyVals.get(USER_KEY), DEFAULT_USERNAME))); logException(() -> settings.setUserName(valOrDefault(keyVals.get(USER_KEY), DEFAULT_USERNAME)));
handleTry(() -> settings.setPort(valOrDefault(keyVals.get(PORT_KEY), DEFAULT_PORT, 1, 65535))); logException(() -> settings.setPort(valOrDefault(keyVals.get(PORT_KEY), DEFAULT_PORT, 1, 65535)));
handleTry(() -> settings.setBulkThreshold(valOrDefault(keyVals.get(BULK_THRESHOLD_KEY), RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD, 1, null))); logException(() -> settings.setBulkThreshold(valOrDefault(keyVals.get(BULK_THRESHOLD_KEY), RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD, 1, null)));
String passwordHex = keyVals.get(PASSWORD_KEY); String passwordHex = keyVals.get(PASSWORD_KEY);
String password; String password;
@ -145,7 +145,7 @@ public class CentralRepoPostgresSettingsUtil {
final String finalPassword = password; final String finalPassword = password;
handleTry(() -> settings.setPassword(finalPassword)); logException(() -> settings.setPassword(finalPassword));
return settings; return settings;
} }

View File

@ -26,6 +26,6 @@ public enum DatabaseTestResult {
CONNECTION_FAILED, CONNECTION_FAILED,
SCHEMA_INVALID, SCHEMA_INVALID,
DB_DOES_NOT_EXIST, DB_DOES_NOT_EXIST,
TESTEDOK; TESTED_OK;
} }

View File

@ -48,9 +48,9 @@ public final class PostgresCentralRepoSettings implements CentralRepoDbConnectiv
private static PostgresSettingsLoader getLoaderFromSaved() throws CentralRepoException { private static PostgresSettingsLoader getLoaderFromSaved() throws CentralRepoException {
CentralRepoDbChoice choice = CentralRepoDbManager.getSavedDbChoice(); CentralRepoDbChoice choice = CentralRepoDbManager.getSavedDbChoice();
if (choice == CentralRepoDbChoice.POSTGRESQL_CUSTOM) if (choice == CentralRepoDbChoice.POSTGRESQL_CUSTOM)
return PostgresSettingsLoader.CUSTOM_LOADER; return PostgresSettingsLoader.CUSTOM_SETTINGS_LOADER;
else if (choice == CentralRepoDbChoice.POSTGRESQL_MULTIUSER) else if (choice == CentralRepoDbChoice.POSTGRESQL_MULTIUSER)
return PostgresSettingsLoader.MULTIUSER_LOADER; return PostgresSettingsLoader.MULTIUSER_SETTINGS_LOADER;
else else
throw new CentralRepoException("cannot load or save postgres settings for selection: " + choice); throw new CentralRepoException("cannot load or save postgres settings for selection: " + choice);
} }
@ -362,7 +362,7 @@ public final class PostgresCentralRepoSettings implements CentralRepoDbConnectiv
if (verifyConnection()) { if (verifyConnection()) {
if (verifyDatabaseExists()) { if (verifyDatabaseExists()) {
if (verifyDatabaseSchema()) { if (verifyDatabaseSchema()) {
return DatabaseTestResult.TESTEDOK; return DatabaseTestResult.TESTED_OK;
} else { } else {
return DatabaseTestResult.SCHEMA_INVALID; return DatabaseTestResult.SCHEMA_INVALID;
} }

View File

@ -25,8 +25,8 @@ public interface PostgresSettingsLoader {
PostgresConnectionSettings loadSettings(); PostgresConnectionSettings loadSettings();
void saveSettings(PostgresConnectionSettings settings); void saveSettings(PostgresConnectionSettings settings);
PostgresSettingsLoader CUSTOM_LOADER = new Custom(); PostgresSettingsLoader CUSTOM_SETTINGS_LOADER = new Custom();
PostgresSettingsLoader MULTIUSER_LOADER = new MultiUser(); PostgresSettingsLoader MULTIUSER_SETTINGS_LOADER = new MultiUser();
/** /**

View File

@ -358,7 +358,7 @@ public final class SqliteCentralRepoSettings implements CentralRepoDbConnectivit
if (dbFileExists()) { if (dbFileExists()) {
if (verifyConnection()) { if (verifyConnection()) {
if (verifyDatabaseSchema()) { if (verifyDatabaseSchema()) {
return DatabaseTestResult.TESTEDOK; return DatabaseTestResult.TESTED_OK;
} else { } else {
return DatabaseTestResult.SCHEMA_INVALID; return DatabaseTestResult.SCHEMA_INVALID;
} }

View File

@ -197,7 +197,7 @@ public class EamDbSettingsDialog extends JDialog {
} }
} }
return (manager.getStatus() == DatabaseTestResult.TESTEDOK); return (manager.getStatus() == DatabaseTestResult.TESTED_OK);
} }

View File

@ -75,7 +75,6 @@ public final class UserPreferences {
public static final String SHOW_ONLY_CURRENT_USER_TAGS = "ShowOnlyCurrentUserTags"; public static final String SHOW_ONLY_CURRENT_USER_TAGS = "ShowOnlyCurrentUserTags";
public static final String HIDE_SCO_COLUMNS = "HideCentralRepoCommentsAndOccurrences"; //The key for this setting pre-dates the settings current functionality //NON-NLS public static final String HIDE_SCO_COLUMNS = "HideCentralRepoCommentsAndOccurrences"; //The key for this setting pre-dates the settings current functionality //NON-NLS
public static final String DISPLAY_TRANSLATED_NAMES = "DisplayTranslatedNames"; public static final String DISPLAY_TRANSLATED_NAMES = "DisplayTranslatedNames";
private static final boolean DISPLAY_TRANSLATED_NAMES_DEFAULT = true;
public static final String EXTERNAL_HEX_EDITOR_PATH = "ExternalHexEditorPath"; public static final String EXTERNAL_HEX_EDITOR_PATH = "ExternalHexEditorPath";
public static final String SOLR_MAX_JVM_SIZE = "SolrMaxJVMSize"; public static final String SOLR_MAX_JVM_SIZE = "SolrMaxJVMSize";
public static final String RESULTS_TABLE_PAGE_SIZE = "ResultsTablePageSize"; public static final String RESULTS_TABLE_PAGE_SIZE = "ResultsTablePageSize";
@ -266,7 +265,7 @@ public final class UserPreferences {
} }
public static boolean displayTranslatedFileNames() { public static boolean displayTranslatedFileNames() {
return preferences.getBoolean(DISPLAY_TRANSLATED_NAMES, DISPLAY_TRANSLATED_NAMES_DEFAULT); return preferences.getBoolean(DISPLAY_TRANSLATED_NAMES, false);
} }
/** /**