Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AssociateNewPersonAction.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2021 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.sleuthkit.autopsy.datamodel.hosts;
20
21import java.awt.Frame;
22import java.awt.event.ActionEvent;
23import java.util.Collections;
24import java.util.logging.Level;
25import javax.swing.AbstractAction;
26import javax.swing.JOptionPane;
27import org.apache.commons.lang.StringUtils;
28import org.openide.util.NbBundle.Messages;
29import org.openide.windows.WindowManager;
30import org.sleuthkit.autopsy.casemodule.Case;
31import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
32import org.sleuthkit.autopsy.coreutils.Logger;
33import org.sleuthkit.autopsy.datamodel.persons.AddEditPersonDialog;
34import org.sleuthkit.datamodel.Host;
35import org.sleuthkit.datamodel.Person;
36import org.sleuthkit.datamodel.TskCoreException;
37
41@Messages({
42 "AssociateNewPersonAction_menuTitle=New Person...",
43 "AssociateNewPersonAction_onError_title=Error While Associating New Person",
44 "# {0} - hostName",
45 "# {1} - personName",
46 "AssociateNewPersonAction_onError_description=There was an error while associating host {0} with new person {1}."})
47public class AssociateNewPersonAction extends AbstractAction {
48
49 private static final Logger logger = Logger.getLogger(AssociateNewPersonAction.class.getName());
50
51 private final Host host;
52
59 super(Bundle.AssociateNewPersonAction_menuTitle());
60 this.host = host;
61 }
62
63 @Override
64 public void actionPerformed(ActionEvent e) {
65 String newPersonName = "";
66 try {
67 newPersonName = getAddDialogName();
68 if (StringUtils.isNotBlank(newPersonName)) {
69 Person person = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().newPerson(newPersonName);
70 Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().addHostsToPerson(person, Collections.singletonList(host));
71 }
72 } catch (NoCurrentCaseException | TskCoreException ex) {
73 String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName();
74 logger.log(Level.WARNING, String.format("Unable to remove parent from host: %s", hostName), ex);
75
76 JOptionPane.showMessageDialog(
77 WindowManager.getDefault().getMainWindow(),
78 Bundle.AssociateNewPersonAction_onError_description(hostName, newPersonName),
79 Bundle.AssociateNewPersonAction_onError_title(),
80 JOptionPane.WARNING_MESSAGE);
81 }
82
83 }
84
92 private String getAddDialogName() throws NoCurrentCaseException, TskCoreException {
93 Frame parent = WindowManager.getDefault().getMainWindow();
94
95 AddEditPersonDialog addEditDialog
97 parent,
98 Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().getPersons(),
99 null);
100
101 addEditDialog.setResizable(false);
102 addEditDialog.setLocationRelativeTo(parent);
103 addEditDialog.setVisible(true);
104 addEditDialog.toFront();
105
106 if (addEditDialog.isChanged()) {
107 String newHostName = addEditDialog.getValue();
108 return newHostName;
109 }
110
111 return null;
112 }
113
114}
synchronized static Logger getLogger(String name)
Definition Logger.java:124

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.