Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
PersonaAccountFetcher.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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  */
19 package org.sleuthkit.autopsy.contentviewers.artifactviewers;
20 
21 import java.awt.Component;
22 import java.awt.event.ActionListener;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.concurrent.CancellationException;
29 import java.util.concurrent.ExecutionException;
30 import java.util.logging.Level;
31 import javax.swing.JButton;
32 import javax.swing.SwingWorker;
33 import org.openide.util.NbBundle.Messages;
41 import org.sleuthkit.datamodel.Account;
42 import org.sleuthkit.datamodel.BlackboardArtifact;
43 import org.sleuthkit.datamodel.CommunicationsManager;
44 
48 class PersonaAccountFetcher extends SwingWorker<Map<String, Collection<Persona>>, Void> {
49 
50  private final static Logger logger = Logger.getLogger(PersonaAccountFetcher.class.getName());
51 
52  private final BlackboardArtifact artifact;
53  private final List<AccountPersonaSearcherData> personaSearchDataList;
54  private final Component parentComponent;
55 
63  PersonaAccountFetcher(BlackboardArtifact artifact, List<AccountPersonaSearcherData> personaSearchDataList, Component parentComponent) {
64  this.artifact = artifact;
65  this.personaSearchDataList = personaSearchDataList;
66  this.parentComponent = parentComponent;
67  }
68 
69  @Override
70  protected Map<String, Collection<Persona>> doInBackground() throws Exception {
71  Map<String, Collection<Persona>> accountMap = new HashMap<>();
72 
73  CommunicationsManager commManager = Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager();
74 
75  List<Account> relatedAccountList = commManager.getAccountsRelatedToArtifact(artifact);
76 
77  for (Account account : relatedAccountList) {
78 
79  if (isCancelled()) {
80  return new HashMap<>();
81  }
82 
83  Collection<PersonaAccount> personaAccountList = PersonaAccount.getPersonaAccountsForAccount(account);
84  Collection<Persona> personaList = new ArrayList<>();
85  for (PersonaAccount pAccount : personaAccountList) {
86  personaList.add(pAccount.getPersona());
87  }
88 
89  accountMap.put(account.getTypeSpecificID(), personaList);
90  }
91 
92  return accountMap;
93  }
94 
95  @Override
96  protected void done() {
97  if (isCancelled()) {
98  return;
99  }
100 
101  try {
102  Map<String, Collection<Persona>> accountMap = get();
103 
104  for (AccountPersonaSearcherData searcherData : personaSearchDataList) {
105  Collection<Persona> persona = accountMap.get(searcherData.getAccountIdentifer());
106  updatePersonaControls(searcherData, persona);
107  }
108 
109  } catch (CancellationException ex) {
110  logger.log(Level.INFO, "Persona searching was canceled."); //NON-NLS
111  } catch (InterruptedException ex) {
112  logger.log(Level.INFO, "Persona searching was interrupted."); //NON-NLS
113  } catch (ExecutionException ex) {
114  logger.log(Level.SEVERE, "Fatal error during Persona search.", ex); //NON-NLS
115  }
116 
117  parentComponent.repaint();
118  }
119 
120  @Messages({
121  "# {0} - Persona count",
122  "PersonaDisplayTask_persona_count_suffix=(1 of {0})"
123  })
124 
131  private void updatePersonaControls(AccountPersonaSearcherData personaSearcherData, Collection<Persona> personas) {
132  //Update the Persona label and button based on the search result
133  String personaLabelText = Bundle.CommunicationArtifactViewerHelper_persona_label();
134  String personaButtonText;
135  ActionListener buttonActionListener;
136 
137  if (personas == null || personas.isEmpty()) {
138  // No persona found
139  personaLabelText += Bundle.CommunicationArtifactViewerHelper_persona_unknown();
140 
141  // show a 'Create' button
142  personaButtonText = Bundle.CommunicationArtifactViewerHelper_persona_button_create();
143  buttonActionListener = new CreatePersonaButtonListener(parentComponent, personaSearcherData);
144  } else {
145  Persona persona = personas.iterator().next();
146  personaLabelText += persona.getName();
147  if (personas.size() > 1) {
148  personaLabelText += Bundle.PersonaDisplayTask_persona_count_suffix(Integer.toString(personas.size()));
149  }
150  // Show a 'View' button
151  personaButtonText = Bundle.CommunicationArtifactViewerHelper_persona_button_view();
152  buttonActionListener = new ViewPersonaButtonListener(parentComponent, persona);
153  }
154 
155  personaSearcherData.getPersonaNameLabel().setText(personaLabelText);
156  personaSearcherData.getPersonaActionButton().setText(personaButtonText);
157  personaSearcherData.getPersonaActionButton().setEnabled(true);
158 
159  // set button action
160  personaSearcherData.getPersonaActionButton().addActionListener(buttonActionListener);
161  }
162 
166  private class CreatePersonaButtonListener implements ActionListener {
167 
168  private final Component parentComponent;
169  private final AccountPersonaSearcherData personaSearcherData;
170 
171  CreatePersonaButtonListener(Component parentComponent, AccountPersonaSearcherData personaSearcherData) {
172  this.parentComponent = parentComponent;
173  this.personaSearcherData = personaSearcherData;
174  }
175 
176  @Override
177  public void actionPerformed(java.awt.event.ActionEvent evt) {
178  // Launch the Persona Create dialog
179  new PersonaDetailsDialog(parentComponent,
180  PersonaDetailsMode.CREATE, null, new PersonaCreateCallbackImpl(parentComponent, personaSearcherData));
181  }
182  }
183 
187  private class ViewPersonaButtonListener implements ActionListener {
188 
189  private final Component parentComponent;
190  private final Persona persona;
191 
192  ViewPersonaButtonListener(Component parentComponent, Persona persona) {
193  this.parentComponent = parentComponent;
194  this.persona = persona;
195  }
196 
197  @Override
198  public void actionPerformed(java.awt.event.ActionEvent evt) {
199  new PersonaDetailsDialog(parentComponent,
200  PersonaDetailsMode.VIEW, persona, new PersonaViewCallbackImpl());
201  }
202  }
203 
207  class PersonaCreateCallbackImpl implements PersonaDetailsDialogCallback {
208 
209  private final Component parentComponent;
210  private final AccountPersonaSearcherData personaSearcherData;
211 
212  PersonaCreateCallbackImpl(Component parentComponent, AccountPersonaSearcherData personaSearcherData) {
213  this.parentComponent = parentComponent;
214  this.personaSearcherData = personaSearcherData;
215  }
216 
217  @Override
218  public void callback(Persona persona) {
219  JButton personaButton = personaSearcherData.getPersonaActionButton();
220  if (persona != null) {
221  // update the persona name label with newly created persona,
222  // and change the button to a "View" button
223  personaSearcherData.getPersonaNameLabel().setText(Bundle.CommunicationArtifactViewerHelper_persona_label() + persona.getName());
224  personaSearcherData.getPersonaActionButton().setText(Bundle.CommunicationArtifactViewerHelper_persona_button_view());
225 
226  // replace action listener with a View button listener
227  for (ActionListener act : personaButton.getActionListeners()) {
228  personaButton.removeActionListener(act);
229  }
230  personaButton.addActionListener(new ViewPersonaButtonListener(parentComponent, persona));
231 
232  }
233 
234  personaButton.getParent().revalidate();
235  }
236  }
237 
241  class PersonaViewCallbackImpl implements PersonaDetailsDialogCallback {
242 
243  @Override
244  public void callback(Persona persona) {
245  // nothing to do
246  }
247  }
248 
249 }

Copyright © 2012-2020 Basis Technology. Generated on: Mon Jul 6 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.