19 package org.sleuthkit.autopsy.centralrepository.datamodel;
21 import java.beans.PropertyChangeListener;
22 import java.beans.PropertyChangeSupport;
24 import java.sql.SQLException;
25 import java.util.logging.Level;
26 import org.openide.util.NbBundle;
76 if (clearDisabledDueToError) {
83 savedChoice = newChoice;
85 propertyChangeSupport.firePropertyChange(
"savedChoice", oldChoice, newChoice);
115 if (savedChoice == null) {
117 savedChoice =
fromKey(selectedPlatformString);
147 propertyChangeSupport.firePropertyChange(
"disabledDueToFailure", oldValue, disabledDueToFailure);
173 propertyChangeSupport.addPropertyChangeListener(listener);
182 propertyChangeSupport.removePropertyChangeListener(listener);
187 if (dbChoice.getSettingKey().equalsIgnoreCase(keyName)) {
206 }
catch (CentralRepoException ex) {
207 logger.log(Level.SEVERE,
"Error updating central repository, unable to make connection", ex);
208 onUpgradeError(
"Error updating central repository, unable to make connection",
209 Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
230 return db.getExclusiveMultiUserDbLock();
233 logger.log(Level.SEVERE,
"Error updating central repository, unable to acquire exclusive lock", ex);
234 onUpgradeError(
"Error updating central repository, unable to acquire exclusive lock",
235 Bundle.EamDbUtil_exclusiveLockAquisitionFailure_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
253 }
catch (CentralRepoException ex) {
254 logger.log(Level.SEVERE,
"Error updating central repository", ex);
256 }
catch (SQLException ex) {
257 logger.log(Level.SEVERE,
"Error updating central repository", ex);
259 Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
261 logger.log(Level.SEVERE,
"Error updating central repository", ex);
263 ex.getMessage() +
"\n\n" + Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
269 logger.log(Level.SEVERE,
"Error releasing database lock", ex);
280 @NbBundle.Messages(value = {
"EamDbUtil.centralRepoDisabled.message= The Central Repository has been disabled.",
"EamDbUtil.centralRepoUpgradeFailed.message=Failed to upgrade Central Repository.",
"EamDbUtil.centralRepoConnectionFailed.message=Unable to connect to Central Repository.",
"EamDbUtil.exclusiveLockAquisitionFailure.message=Unable to acquire exclusive lock for Central Repository."})
294 Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), null);
305 logger.log(Level.SEVERE,
"Error shutting down central repo connection pool", ex2);
308 if (innerException == null) {
378 throw new CentralRepoException(
"Unable to successfully create sqlite database");
411 throw new CentralRepoException(
"Unknown database type: " + selectedDbChoice);
428 throw new CentralRepoException(
"Unknown database type: " + selectedDbChoice);
440 if (selectedDbSettings == null) {
441 throw new CentralRepoException(
"Unable to derive connectivity manager from settings: " + selectedDbChoice);
444 boolean result =
false;
445 boolean dbCreated =
true;
456 }
catch (CentralRepoException ex) {
457 logger.log(Level.SEVERE,
"Unable to create database for central repository with settings " + selectedDbSettings, ex);
467 String schemaError =
"Unable to initialize database schema or insert contents into central repository.";
468 logger.severe(schemaError);
469 throw new CentralRepoException(schemaError);
479 @NbBundle.Messages({
"CentralRepoDbManager.connectionErrorMsg.text=Failed to connect to central repository database."})
491 if (null != previousDbManager) {
496 logger.log(Level.SEVERE,
"Failed to close database connections in previously selected platform.", ex);
514 logger.info(
"Saving central repo settings for db: " + selectedDbSettings);
516 configurationChanged =
true;
518 logger.log(Level.SEVERE, Bundle.CentralRepoDbManager_connectionErrorMsg_text(), ex);
558 selectedDbChoice = newSelected;
569 String tbDbHostname, String tbDbPort, String tbDbUsername, String tfDatabasePath, String jpDbPassword)
throws CentralRepoException, NumberFormatException {
572 dbSettingsPostgres.
setHost(tbDbHostname);
573 dbSettingsPostgres.
setPort(Integer.parseInt(tbDbPort));
574 dbSettingsPostgres.
setDbName(CENTRAL_REPO_DB_NAME);
578 File databasePath =
new File(tfDatabasePath);
582 throw new IllegalStateException(
"Central Repo has an unknown selected platform: " + selectedDbChoice);
597 if (manager != null) {
600 }
catch (CentralRepoException e) {
601 logger.log(Level.WARNING,
"unable to test status of db connection in central repo", e);
final SqliteCentralRepoSettings dbSettingsSqlite
static synchronized String getConfigSetting(String moduleName, String settingName)
DatabaseTestResult getStatus()
DatabaseTestResult testStatus()
void setupDefaultSqliteDb()
static void removePropertyChangeListener(PropertyChangeListener listener)
static CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice, boolean clearDisabledDueToError)
static final Object disabledDueToFailureLock
boolean insertDefaultDatabaseContent()
CentralRepoDbConnectivityManager getSelectedSettings()
PostgresCentralRepoSettings getDbSettingsMultiUser()
static void onUpgradeError(String message, String desc, Exception innerException)
SqliteCentralRepoSettings getDbSettingsSqlite()
static volatile CentralRepoDbChoice savedChoice
void setUserName(String userName)
DatabaseTestResult testingStatus
static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected)
static final String CENTRAL_REPOSITORY_SETTINGS_KEY
static CentralRepoDbChoice fromKey(String keyName)
static void upgradeDatabase()
static CentralRepoDbChoice getSavedDbChoice()
static boolean getIsMultiUserModeEnabled()
static boolean isPostgresMultiuserAllowed()
static final String DISABLED_DUE_TO_FAILURE_KEY
PostgresSettingsLoader MULTIUSER_SETTINGS_LOADER
static CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice)
PostgresSettingsLoader CUSTOM_SETTINGS_LOADER
void saveNewCentralRepo()
static void disableDueToFailure()
static final String DB_SELECTED_PLATFORM_KEY
static boolean isDisabledDueToFailure()
static final String CENTRAL_REPO_DB_NAME
static CoordinationService.Lock obtainCentralRepoLock(CentralRepository db)
void setDbName(String dbName)
boolean testDatabaseSettingsAreValid(String tbDbHostname, String tbDbPort, String tbDbUsername, String tfDatabasePath, String jpDbPassword)
DatabaseTestResult testStatus()
void setupDefaultSettings()
void setPassword(String password)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
void setHost(String host)
void shutdownConnections()
static CentralRepository obtainCentralRepository()
final PostgresCentralRepoSettings dbSettingsPostgres
CentralRepoDbChoice getSelectedDbChoice()
PostgresCentralRepoSettings getDbSettingsPostgres()
boolean wasConfigurationChanged()
static void addPropertyChangeListener(PropertyChangeListener listener)
void setDbDirectory(String dbDirectory)
static void updatedDbSchema(CentralRepository db, CoordinationService.Lock lock)
boolean verifyDatabaseExists()
final PostgresCentralRepoSettings dbSettingsMultiUser
DatabaseTestResult testStatus()
synchronized static Logger getLogger(String name)
void setDbName(String dbName)
CentralRepoDbChoice selectedDbChoice
static final Object dbChoiceLock
boolean initializeDatabaseSchema()
static void setDisabledDueToFailure(boolean disabledDueToFailure)
static final String DEFAULT_DBNAME
void setSelctedDbChoice(CentralRepoDbChoice newSelected)
static CentralRepository getInstance()
boolean configurationChanged
static final PropertyChangeSupport propertyChangeSupport
RdbmsCentralRepoFactory getDbFactory()
static final Logger logger
static boolean isEnabled()