mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 10:17:41 +00:00
Add a default organization when the central repo db is created
This commit is contained in:
parent
1761c5afcb
commit
6487af2f57
@ -37,6 +37,7 @@ public class EamDbUtil {
|
|||||||
private final static Logger LOGGER = Logger.getLogger(EamDbUtil.class.getName());
|
private final static Logger LOGGER = Logger.getLogger(EamDbUtil.class.getName());
|
||||||
private static final String CENTRAL_REPO_NAME = "CentralRepository";
|
private static final String CENTRAL_REPO_NAME = "CentralRepository";
|
||||||
private static final String CENTRAL_REPO_USE_KEY = "db.useCentralRepo";
|
private static final String CENTRAL_REPO_USE_KEY = "db.useCentralRepo";
|
||||||
|
private static final String DEFAULT_ORG_NAME = "Not Specified";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the prepared statement.
|
* Close the prepared statement.
|
||||||
@ -175,11 +176,51 @@ public class EamDbUtil {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the given org is the default organization.
|
||||||
|
*
|
||||||
|
* @param org
|
||||||
|
* @return true if it is the default org, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean isDefaultOrg(EamOrganization org) {
|
||||||
|
return DEFAULT_ORG_NAME.equals(org.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the default organization to the database
|
||||||
|
*
|
||||||
|
* @param conn
|
||||||
|
* @return true if successful, false otherwise
|
||||||
|
*/
|
||||||
|
static boolean insertDefaultOrganization(Connection conn) {
|
||||||
|
if (null == conn) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
String sql = "INSERT INTO organizations(org_name, poc_name, poc_email, poc_phone) VALUES (?, ?, ?, ?)";
|
||||||
|
try {
|
||||||
|
preparedStatement = conn.prepareStatement(sql);
|
||||||
|
preparedStatement.setString(1, DEFAULT_ORG_NAME);
|
||||||
|
preparedStatement.setString(2, "");
|
||||||
|
preparedStatement.setString(3, "");
|
||||||
|
preparedStatement.setString(4, "");
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
LOGGER.log(Level.SEVERE, "Error adding default organization", ex);
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
EamDbUtil.closePreparedStatement(preparedStatement);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the Central Repos use has been enabled.
|
* If the Central Repos use has been enabled.
|
||||||
*
|
*
|
||||||
* @return true if the Central Repo may be configured, false if it should
|
* @return true if the Central Repo may be configured, false if it should
|
||||||
* not be able to be
|
* not be able to be
|
||||||
*/
|
*/
|
||||||
public static boolean useCentralRepo() {
|
public static boolean useCentralRepo() {
|
||||||
return Boolean.parseBoolean(ModuleSettings.getConfigSetting(CENTRAL_REPO_NAME, CENTRAL_REPO_USE_KEY));
|
return Boolean.parseBoolean(ModuleSettings.getConfigSetting(CENTRAL_REPO_NAME, CENTRAL_REPO_USE_KEY));
|
||||||
@ -190,7 +231,7 @@ public class EamDbUtil {
|
|||||||
* configured.
|
* configured.
|
||||||
*
|
*
|
||||||
* @param centralRepoCheckBoxIsSelected - true if the central repo can be
|
* @param centralRepoCheckBoxIsSelected - true if the central repo can be
|
||||||
* used
|
* used
|
||||||
*/
|
*/
|
||||||
public static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected) {
|
public static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected) {
|
||||||
ModuleSettings.setConfigSetting(CENTRAL_REPO_NAME, CENTRAL_REPO_USE_KEY, Boolean.toString(centralRepoCheckBoxIsSelected));
|
ModuleSettings.setConfigSetting(CENTRAL_REPO_NAME, CENTRAL_REPO_USE_KEY, Boolean.toString(centralRepoCheckBoxIsSelected));
|
||||||
|
@ -485,7 +485,8 @@ public final class PostgresEamDbSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean result = EamDbUtil.insertDefaultCorrelationTypes(conn)
|
boolean result = EamDbUtil.insertDefaultCorrelationTypes(conn)
|
||||||
&& EamDbUtil.insertSchemaVersion(conn);
|
&& EamDbUtil.insertSchemaVersion(conn)
|
||||||
|
&& EamDbUtil.insertDefaultOrganization(conn);
|
||||||
EamDbUtil.closeConnection(conn);
|
EamDbUtil.closeConnection(conn);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -434,7 +434,8 @@ public final class SqliteEamDbSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean result = EamDbUtil.insertDefaultCorrelationTypes(conn)
|
boolean result = EamDbUtil.insertDefaultCorrelationTypes(conn)
|
||||||
&& EamDbUtil.insertSchemaVersion(conn);
|
&& EamDbUtil.insertSchemaVersion(conn)
|
||||||
|
&& EamDbUtil.insertDefaultOrganization(conn);
|
||||||
EamDbUtil.closeConnection(conn);
|
EamDbUtil.closeConnection(conn);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ import org.openide.util.NbBundle.Messages;
|
|||||||
import org.openide.windows.WindowManager;
|
import org.openide.windows.WindowManager;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
||||||
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ public final class ManageOrganizationsDialog extends JDialog {
|
|||||||
organizationList.setModel(rulesListModel);
|
organizationList.setModel(rulesListModel);
|
||||||
organizationList.addListSelectionListener(new OrganizationListSelectionListener());
|
organizationList.addListSelectionListener(new OrganizationListSelectionListener());
|
||||||
populateList();
|
populateList();
|
||||||
setButtonsEnabled(organizationList.getSelectedValue() != null);
|
setButtonsEnabled(organizationList.getSelectedValue());
|
||||||
newOrg = null;
|
newOrg = null;
|
||||||
} catch (EamDbException ex) {
|
} catch (EamDbException ex) {
|
||||||
Exceptions.printStackTrace(ex);
|
Exceptions.printStackTrace(ex);
|
||||||
@ -421,9 +422,15 @@ public final class ManageOrganizationsDialog extends JDialog {
|
|||||||
return newOrg;
|
return newOrg;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setButtonsEnabled(boolean isSelected) {
|
private void setButtonsEnabled(EamOrganization selectedOrg) {
|
||||||
editButton.setEnabled(isSelected);
|
boolean isSelected = (selectedOrg != null);
|
||||||
deleteButton.setEnabled(isSelected);
|
boolean isDefaultOrg = false;
|
||||||
|
if(selectedOrg != null){
|
||||||
|
isDefaultOrg = EamDbUtil.isDefaultOrg(selectedOrg);
|
||||||
|
}
|
||||||
|
|
||||||
|
editButton.setEnabled(isSelected && (! isDefaultOrg));
|
||||||
|
deleteButton.setEnabled(isSelected && (! isDefaultOrg));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -436,9 +443,8 @@ public final class ManageOrganizationsDialog extends JDialog {
|
|||||||
if (e.getValueIsAdjusting()) {
|
if (e.getValueIsAdjusting()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EamOrganization selected = organizationList.getSelectedValue();
|
EamOrganization selected = organizationList.getSelectedValue();
|
||||||
boolean isSelected = (selected != null);
|
setButtonsEnabled(selected);
|
||||||
setButtonsEnabled(isSelected);
|
|
||||||
if (selected != null) {
|
if (selected != null) {
|
||||||
orgNameTextField.setText(selected.getName());
|
orgNameTextField.setText(selected.getName());
|
||||||
pocNameTextField.setText(selected.getPocName());
|
pocNameTextField.setText(selected.getPocName());
|
||||||
|
@ -33,6 +33,7 @@ import org.openide.util.NbBundle;
|
|||||||
import org.openide.windows.WindowManager;
|
import org.openide.windows.WindowManager;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
||||||
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalSet;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalSet;
|
||||||
import org.sleuthkit.autopsy.centralrepository.optionspanel.ManageOrganizationsDialog;
|
import org.sleuthkit.autopsy.centralrepository.optionspanel.ManageOrganizationsDialog;
|
||||||
@ -154,8 +155,12 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog {
|
|||||||
orgs = dbManager.getOrganizations();
|
orgs = dbManager.getOrganizations();
|
||||||
orgs.forEach((org) -> {
|
orgs.forEach((org) -> {
|
||||||
orgComboBox.addItem(org.getName());
|
orgComboBox.addItem(org.getName());
|
||||||
|
if(EamDbUtil.isDefaultOrg(org)){
|
||||||
|
orgComboBox.setSelectedItem(org.getName());
|
||||||
|
selectedOrg = org;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (!orgs.isEmpty()) {
|
if ((selectedOrg == null) && (!orgs.isEmpty())) {
|
||||||
selectedOrg = orgs.get(0);
|
selectedOrg = orgs.get(0);
|
||||||
}
|
}
|
||||||
} catch (EamDbException ex) {
|
} catch (EamDbException ex) {
|
||||||
|
@ -34,6 +34,7 @@ import org.openide.util.NbBundle;
|
|||||||
import org.openide.windows.WindowManager;
|
import org.openide.windows.WindowManager;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
||||||
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization;
|
||||||
import org.sleuthkit.autopsy.centralrepository.optionspanel.ManageOrganizationsDialog;
|
import org.sleuthkit.autopsy.centralrepository.optionspanel.ManageOrganizationsDialog;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
@ -148,8 +149,12 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
|
|||||||
orgs = dbManager.getOrganizations();
|
orgs = dbManager.getOrganizations();
|
||||||
orgs.forEach((org) -> {
|
orgs.forEach((org) -> {
|
||||||
orgComboBox.addItem(org.getName());
|
orgComboBox.addItem(org.getName());
|
||||||
|
if(EamDbUtil.isDefaultOrg(org)){
|
||||||
|
orgComboBox.setSelectedItem(org.getName());
|
||||||
|
selectedOrg = org;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (!orgs.isEmpty()) {
|
if ((selectedOrg == null) && (!orgs.isEmpty())) {
|
||||||
selectedOrg = orgs.get(0);
|
selectedOrg = orgs.get(0);
|
||||||
}
|
}
|
||||||
} catch (EamDbException ex) {
|
} catch (EamDbException ex) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user