Autopsy  4.16.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;
34 import org.openide.util.NbBundle.Messages;
46 import org.sleuthkit.datamodel.Account;
47 import org.sleuthkit.datamodel.BlackboardArtifact;
48 import org.sleuthkit.datamodel.CommunicationsManager;
49 import org.sleuthkit.datamodel.InvalidAccountIDException;
50 
54 class PersonaAccountFetcher extends SwingWorker<Map<String, Collection<Persona>>, Void> {
55 
56  private final static Logger logger = Logger.getLogger(PersonaAccountFetcher.class.getName());
57 
58  private final BlackboardArtifact artifact;
59  private final List<AccountPersonaSearcherData> personaSearchDataList;
60  private final Component parentComponent;
61 
69  PersonaAccountFetcher(BlackboardArtifact artifact, List<AccountPersonaSearcherData> personaSearchDataList, Component parentComponent) {
70  this.artifact = artifact;
71  this.personaSearchDataList = personaSearchDataList;
72  this.parentComponent = parentComponent;
73  }
74 
75  @Override
76  protected Map<String, Collection<Persona>> doInBackground() throws Exception {
77  Map<String, Collection<Persona>> accountMap = new HashMap<>();
78 
79  CommunicationsManager commManager = Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager();
80 
81  List<Account> relatedAccountList = commManager.getAccountsRelatedToArtifact(artifact);
82 
83  for (Account account : relatedAccountList) {
84 
85  if (isCancelled()) {
86  return new HashMap<>();
87  }
88 
89  Collection<PersonaAccount> personaAccountList = PersonaAccount.getPersonaAccountsForAccount(account);
90  Collection<Persona> personaList = new ArrayList<>();
91  for (PersonaAccount pAccount : personaAccountList) {
92  personaList.add(pAccount.getPersona());
93  }
94 
95  accountMap.put(account.getTypeSpecificID(), personaList);
96  }
97 
98  return accountMap;
99  }
100 
101  @Override
102  protected void done() {
103  if (isCancelled()) {
104  return;
105  }
106 
107  try {
108  Map<String, Collection<Persona>> accountMap = get();
109 
110  for (AccountPersonaSearcherData searcherData : personaSearchDataList) {
111  Collection<Persona> persona = accountMap.get(searcherData.getAccountIdentifer());
112  updatePersonaControls(searcherData, persona);
113  }
114 
115  } catch (CancellationException ex) {
116  logger.log(Level.INFO, "Persona searching was canceled."); //NON-NLS
117  } catch (InterruptedException ex) {
118  logger.log(Level.INFO, "Persona searching was interrupted."); //NON-NLS
119  } catch (ExecutionException ex) {
120  logger.log(Level.SEVERE, "Fatal error during Persona search.", ex); //NON-NLS
121  }
122 
123  parentComponent.repaint();
124  }
125 
126  @Messages({
127  "# {0} - Persona count",
128  "PersonaDisplayTask_persona_count_suffix=(1 of {0})"
129  })
130 
137  private void updatePersonaControls(AccountPersonaSearcherData personaSearcherData, Collection<Persona> personas) {
138  //Update the Persona label and button based on the search result
139  String personaLabelText = Bundle.CommunicationArtifactViewerHelper_persona_label();
140  String personaButtonText;
141  ActionListener buttonActionListener;
142 
143  if (personas == null || personas.isEmpty()) {
144  // No persona found
145  personaLabelText += Bundle.CommunicationArtifactViewerHelper_persona_unknown();
146 
147  // show a 'Create' button
148  personaButtonText = Bundle.CommunicationArtifactViewerHelper_persona_button_create();
149  buttonActionListener = new CreatePersonaButtonListener(parentComponent, personaSearcherData);
150  } else {
151  Persona persona = personas.iterator().next();
152  personaLabelText += persona.getName();
153  if (personas.size() > 1) {
154  personaLabelText += Bundle.PersonaDisplayTask_persona_count_suffix(Integer.toString(personas.size()));
155  }
156  // Show a 'View' button
157  personaButtonText = Bundle.CommunicationArtifactViewerHelper_persona_button_view();
158  buttonActionListener = new ViewPersonaButtonListener(parentComponent, persona);
159  }
160 
161  personaSearcherData.getPersonaNameLabel().setText(personaLabelText);
162  personaSearcherData.getPersonaActionButton().setText(personaButtonText);
163  personaSearcherData.getPersonaActionButton().setEnabled(true);
164 
165  // set button action
166  personaSearcherData.getPersonaActionButton().addActionListener(buttonActionListener);
167  }
168 
172  private class CreatePersonaButtonListener implements ActionListener {
173 
174  private final Component parentComponent;
175  private final AccountPersonaSearcherData personaSearcherData;
176 
177  CreatePersonaButtonListener(Component parentComponent, AccountPersonaSearcherData personaSearcherData) {
178  this.parentComponent = parentComponent;
179  this.personaSearcherData = personaSearcherData;
180  }
181 
182  @NbBundle.Messages({
183  "PersonaAccountFetcher.account.justification=Account found in Call Log artifact"
184  })
185  @Override
186  public void actionPerformed(java.awt.event.ActionEvent evt) {
187  // Launch the Persona Create dialog
188 
189  PersonaDetailsDialog dialog = new PersonaDetailsDialog(parentComponent,
190  PersonaDetailsMode.CREATE, null, new PersonaCreateCallbackImpl(parentComponent, personaSearcherData), false);
191 
192  // Pre populate the persona name and accounts if we have them.
193  PersonaDetailsPanel personaPanel = dialog.getDetailsPanel();
194 
195  // Set a default name
196  personaPanel.setPersonaName(personaSearcherData.getAccountIdentifer());
197 
198  // Set up each matching account. We don't know what type of account we have, so check all the types to
199  // find any matches.
200  try {
202  try {
203  // Try to load any matching accounts of this type. Throws an InvalidAccountIDException if the account is the
204  // wrong format (i.e., when we try to load email accounts for a phone number-type string).
205  CentralRepoAccount account = CentralRepository.getInstance().getAccount(type, personaSearcherData.getAccountIdentifer());
206  if (account != null) {
207  personaPanel.addAccount(account, Bundle.PersonaAccountFetcher_account_justification(), Persona.Confidence.HIGH);
208  }
209  } catch (InvalidAccountIDException ex2) {
210  // These are expected when the account identifier doesn't match the format of the account type.
211  }
212  }
213  } catch (CentralRepoException ex) {
214  logger.log(Level.SEVERE, "Error looking up account types in the central repository", ex);
215  }
216 
217  // display the dialog now
218  dialog.display();
219  }
220  }
221 
225  private class ViewPersonaButtonListener implements ActionListener {
226 
227  private final Component parentComponent;
228  private final Persona persona;
229 
230  ViewPersonaButtonListener(Component parentComponent, Persona persona) {
231  this.parentComponent = parentComponent;
232  this.persona = persona;
233  }
234 
235  @Override
236  public void actionPerformed(java.awt.event.ActionEvent evt) {
237  new PersonaDetailsDialog(parentComponent,
238  PersonaDetailsMode.VIEW, persona, new PersonaViewCallbackImpl());
239  }
240  }
241 
245  class PersonaCreateCallbackImpl implements PersonaDetailsDialogCallback {
246 
247  private final Component parentComponent;
248  private final AccountPersonaSearcherData personaSearcherData;
249 
250  PersonaCreateCallbackImpl(Component parentComponent, AccountPersonaSearcherData personaSearcherData) {
251  this.parentComponent = parentComponent;
252  this.personaSearcherData = personaSearcherData;
253  }
254 
255  @Override
256  public void callback(Persona persona) {
257  JButton personaButton = personaSearcherData.getPersonaActionButton();
258  if (persona != null) {
259  // update the persona name label with newly created persona,
260  // and change the button to a "View" button
261  personaSearcherData.getPersonaNameLabel().setText(Bundle.CommunicationArtifactViewerHelper_persona_label() + persona.getName());
262  personaSearcherData.getPersonaActionButton().setText(Bundle.CommunicationArtifactViewerHelper_persona_button_view());
263 
264  // replace action listener with a View button listener
265  for (ActionListener act : personaButton.getActionListeners()) {
266  personaButton.removeActionListener(act);
267  }
268  personaButton.addActionListener(new ViewPersonaButtonListener(parentComponent, persona));
269 
270  }
271 
272  personaButton.getParent().revalidate();
273  }
274  }
275 
279  class PersonaViewCallbackImpl implements PersonaDetailsDialogCallback {
280 
281  @Override
282  public void callback(Persona persona) {
283  // nothing to do
284  }
285  }
286 
287 }
boolean addAccount(CentralRepoAccount account, String justification, Persona.Confidence confidence)
CentralRepoAccount getAccount(CentralRepoAccount.CentralRepoAccountType crAccountType, String accountUniqueID)

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