From f0b5fc617dcc7abcb7f7f8b503c6cc6e6aa4a19f Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Mon, 22 Feb 2021 16:00:04 -0500 Subject: [PATCH] working through menu items --- .../hosts/AssociateNewPersonAction.java | 105 ++++++++++++++++++ .../hosts/AssociatePersonAction.java | 83 ++++++++++++++ .../hosts/RemoveParentPersonAction.java | 79 +++++++++++++ .../datamodel/persons/DeletePersonAction.java | 78 +++++++++++++ 4 files changed, 345 insertions(+) create mode 100644 Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociateNewPersonAction.java create mode 100644 Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonAction.java create mode 100644 Core/src/org/sleuthkit/autopsy/datamodel/hosts/RemoveParentPersonAction.java create mode 100644 Core/src/org/sleuthkit/autopsy/datamodel/persons/DeletePersonAction.java diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociateNewPersonAction.java b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociateNewPersonAction.java new file mode 100644 index 0000000000..246c6ca110 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociateNewPersonAction.java @@ -0,0 +1,105 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2021 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.datamodel.hosts; + +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.util.logging.Level; +import javax.swing.AbstractAction; +import javax.swing.JOptionPane; +import org.apache.commons.lang.StringUtils; +import org.openide.util.NbBundle.Messages; +import org.openide.windows.WindowManager; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.casemodule.TskCoreException; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.datamodel.Host; +import org.sleuthkit.datamodel.Person; + +/** + * Allows someone to associate a new person with a parentless host. + */ +@Messages({ + "AssociateNewPersonAction_menuTitle=New...", + "AssociateNewPersonAction_onError_title=Error While Associating New Person", + "# {0} - hostName", + "# {1} - personName", + "AssociateNewPersonAction_onError_description=There was an error while associating host {0} with new person {1}."}) +public class AssociateNewPersonAction extends AbstractAction { + + private static final Logger logger = Logger.getLogger(AssociateNewPersonAction.class.getName()); + + private final Host host; + + /** + * Main constructor. + * + * @param host The host to be associated with new person. + */ + public AssociateNewPersonAction(Host host) { + super(Bundle.RemoveParentPersonAction_menuTitle()); + this.host = host; + } + + @Override + public void actionPerformed(ActionEvent e) { + String newPersonName = getAddEditDialogName(); + if (StringUtils.isNotBlank(newPersonName)) { + try { + + Person person = Case.getCurrentCaseThrows.getSleuthkitCase().getPersonManager().createPerson(newPersonName); + Case.getCurrentCaseThrows().getSleuthkitCase().getHostManager().setPerson(host, person); + + } catch (NoCurrentCaseException | TskCoreException ex) { + String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName(); + logger.log(Level.WARNING, String.format("Unable to remove parent from host: %s", hostName), ex); + + JOptionPane.showMessageDialog( + WindowManager.getDefault().getMainWindow(), + Bundle.AssociateNewPersonAction_onError_description(hostName, newPersonName), + Bundle.AssociateNewPersonAction_onError_title(), + JOptionPane.WARNING_MESSAGE); + } + } + } + + private String getAddEditDialogName() { + Frame parent = WindowManager.getDefault().getMainWindow(); + + AddEditPersonDialog addEditDialog + = new AddEditPersonDialog( + parent, + hostChildrenMap.keySet(), + null); + + addEditDialog.setResizable(false); + addEditDialog.setLocationRelativeTo(parent); + addEditDialog.setVisible(true); + addEditDialog.toFront(); + + if (addEditDialog.isChanged()) { + String newHostName = addEditDialog.getValue(); + return newHostName; + } + + return null; + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonAction.java b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonAction.java new file mode 100644 index 0000000000..99dcdefd9b --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonAction.java @@ -0,0 +1,83 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2021 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.datamodel.hosts; + +import java.awt.event.ActionEvent; +import java.util.logging.Level; +import javax.swing.AbstractAction; +import javax.swing.JOptionPane; +import org.openide.util.NbBundle.Messages; +import org.openide.windows.WindowManager; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.casemodule.TskCoreException; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.datamodel.Host; +import org.sleuthkit.datamodel.Person; + +/** + * Removes the parent person from the specified host. + */ +@Messages({ + "# {0} - personName", + "RemoveParentPersonAction_menuTitle=Remove from Person ({0})", + "RemoveParentPersonAction_unknownPerson=Unknown Person", + "RemoveParentPersonAction_onError_title=Error Removing Host from Person", + "# {0} - hostName", + "RemoveParentPersonAction_onError_description=There was an error removing person from host: {0}.",}) +public class AssociatePersonAction extends AbstractAction { + + private static final Logger logger = Logger.getLogger(AssociatePersonAction.class.getName()); + + private final Host host; + + /** + * Main constructor. + * + * @param host The host that will become parentless. + * @param person The person to be removed as a parent from the host. + */ + public AssociatePersonAction(Host host) { + super(Bundle.RemoveParentPersonAction_menuTitle( + person == null || person.getName() == null + ? Bundle.RemoveParentPersonAction_unknownPerson() : person.getName())); + this.host = host; + } + + public AssociatePersonAction(Host host) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void actionPerformed(ActionEvent e) { + try { + Case.getCurrentCaseThrows().getSleuthkitCase().getHostManager().setPerson(host, null); + } catch (NoCurrentCaseException | TskCoreException ex) { + String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName(); + logger.log(Level.WARNING, String.format("Unable to remove parent from host: %s", hostName), ex); + + JOptionPane.showMessageDialog( + WindowManager.getDefault().getMainWindow(), + Bundle.RemoveParentPersonAction_onError_description(hostName), + Bundle.RemoveParentPersonAction_onError_title(), + JOptionPane.WARNING_MESSAGE); + } + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/RemoveParentPersonAction.java b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/RemoveParentPersonAction.java new file mode 100644 index 0000000000..47fbe6207e --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/RemoveParentPersonAction.java @@ -0,0 +1,79 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2021 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.datamodel.hosts; + +import java.awt.event.ActionEvent; +import java.util.logging.Level; +import javax.swing.AbstractAction; +import javax.swing.JOptionPane; +import org.openide.util.NbBundle.Messages; +import org.openide.windows.WindowManager; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.casemodule.TskCoreException; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.datamodel.Host; +import org.sleuthkit.datamodel.Person; + +/** + * Removes the parent person from the specified host. + */ +@Messages({ + "# {0} - personName", + "RemoveParentPersonAction_menuTitle=Remove from Person ({0})", + "RemoveParentPersonAction_unknownPerson=Unknown Person", + "RemoveParentPersonAction_onError_title=Error Removing Host from Person", + "# {0} - hostName", + "RemoveParentPersonAction_onError_description=There was an error removing person from host: {0}.",}) +public class RemoveParentPersonAction extends AbstractAction { + + private static final Logger logger = Logger.getLogger(RemoveParentPersonAction.class.getName()); + + private final Host host; + + /** + * Main constructor. + * + * @param host The host that will become parentless. + * @param person The person to be removed as a parent from the host. + */ + public RemoveParentPersonAction(Host host, Person person) { + super(Bundle.RemoveParentPersonAction_menuTitle( + person == null || person.getName() == null + ? Bundle.RemoveParentPersonAction_unknownPerson() : person.getName())); + this.host = host; + } + + @Override + public void actionPerformed(ActionEvent e) { + try { + Case.getCurrentCaseThrows().getSleuthkitCase().getHostManager().setPerson(host, null); + } catch (NoCurrentCaseException | TskCoreException ex) { + String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName(); + logger.log(Level.WARNING, String.format("Unable to remove parent from host: %s", hostName), ex); + + JOptionPane.showMessageDialog( + WindowManager.getDefault().getMainWindow(), + Bundle.RemoveParentPersonAction_onError_description(hostName), + Bundle.RemoveParentPersonAction_onError_title(), + JOptionPane.WARNING_MESSAGE); + } + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/persons/DeletePersonAction.java b/Core/src/org/sleuthkit/autopsy/datamodel/persons/DeletePersonAction.java new file mode 100644 index 0000000000..9a06bd7a64 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/datamodel/persons/DeletePersonAction.java @@ -0,0 +1,78 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2021 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.datamodel.persons; + +import java.awt.event.ActionEvent; +import java.util.logging.Level; +import javax.swing.AbstractAction; +import javax.swing.JOptionPane; +import org.openide.util.NbBundle.Messages; +import org.openide.windows.WindowManager; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.casemodule.TskCoreException; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.datamodel.Host; +import org.sleuthkit.datamodel.Person; + +/** + * Removes person from case. + */ +@Messages({ + "# {0} - personName", + "DeletePersonAction_menuTitle=Delete Person", + "DeletePersonAction_onError_title=Error Removing Host from Person", + "# {0} - hostName", + "RemoveParentPersonAction_onError_description=There was an error removing person from host: {0}.",}) +public class DeletePersonAction extends AbstractAction { + + private static final Logger logger = Logger.getLogger(DeletePersonAction.class.getName()); + + private final Person person; + + /** + * Main constructor. + * + * @param person The person to be removed. + */ + public DeletePersonAction(Person person) { + super(Bundle.DeletePersonAction_menuTitle()); + this.person = person; + } + + @Override + public void actionPerformed(ActionEvent e) { + if (person != null && person.getName() != null) { + try { + Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().deletePerson(person.getName()); + } catch (NoCurrentCaseException | TskCoreException ex) { + String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName(); + logger.log(Level.WARNING, String.format("Unable to remove parent from host: %s", hostName), ex); + + JOptionPane.showMessageDialog( + WindowManager.getDefault().getMainWindow(), + Bundle.RemoveParentPersonAction_onError_description(hostName), + Bundle.RemoveParentPersonAction_onError_title(), + JOptionPane.WARNING_MESSAGE); + } + } + + } + +}