Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AllCasesSearchDialog.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 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.allcasessearch;
20 
21 import java.awt.Color;
22 import java.awt.event.ItemEvent;
23 import java.awt.event.ItemListener;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.concurrent.ExecutionException;
28 import java.util.logging.Level;
29 import javax.swing.JFrame;
30 import javax.swing.SwingWorker;
31 import javax.swing.event.DocumentEvent;
32 import javax.swing.event.DocumentListener;
33 import org.openide.nodes.Node;
34 import org.openide.util.NbBundle.Messages;
35 import org.openide.windows.TopComponent;
36 import org.openide.windows.WindowManager;
49 
50 @Messages({
51  "AllCasesSearchDialog.dialogTitle.text=Search All Cases",
52  "AllCasesSearchDialog.resultsTitle.text=All Cases",
53  "AllCasesSearchDialog.resultsDescription.text=All Cases Search",
54  "AllCasesSearchDialog.emptyNode.text=No results found.",
55  "AllCasesSearchDialog.validation.invalidHash=The supplied value is not a valid MD5 hash.",
56  "AllCasesSearchDialog.validation.invalidEmail=The supplied value is not a valid e-mail address.",
57  "AllCasesSearchDialog.validation.invalidDomain=The supplied value is not a valid domain.",
58  "AllCasesSearchDialog.validation.invalidPhone=The supplied value is not a valid phone number.",
59  "AllCasesSearchDialog.validation.invalidSsid=The supplied value is not a valid wireless network.",
60  "AllCasesSearchDialog.validation.invalidMac=The supplied value is not a valid MAC address.",
61  "AllCasesSearchDialog.validation.invalidImei=The supplied value is not a valid IMEI number.",
62  "AllCasesSearchDialog.validation.invalidImsi=The supplied value is not a valid IMSI number.",
63  "AllCasesSearchDialog.validation.invalidIccid=The supplied value is not a valid ICCID number.",
64  "AllCasesSearchDialog.validation.genericMessage=The supplied value is not valid.",
65  "# {0} - number of cases",
66  "AllCasesSearchDialog.caseLabel.text=The current Central Repository contains {0} case(s)."
67 })
72 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
73 final class AllCasesSearchDialog extends javax.swing.JDialog {
74 
75  private static final Logger logger = Logger.getLogger(AllCasesSearchDialog.class.getName());
76  private static final long serialVersionUID = 1L;
77 
78  private final List<CorrelationAttributeInstance.Type> correlationTypes;
79  private CorrelationAttributeInstance.Type selectedCorrelationType;
80  private TextPrompt correlationValueTextFieldPrompt;
81 
85  AllCasesSearchDialog() {
86  super((JFrame) WindowManager.getDefault().getMainWindow(), Bundle.AllCasesSearchDialog_dialogTitle_text(), true);
87  this.correlationTypes = new ArrayList<>();
88  initComponents();
89  customizeComponents();
90  }
91 
98  private void search(CorrelationAttributeInstance.Type type, String value) {
99  new SwingWorker<List<CorrelationAttributeInstance>, Void>() {
100 
101  @Override
102  protected List<CorrelationAttributeInstance> doInBackground() {
103  List<CorrelationAttributeInstance> correlationInstances = new ArrayList<>();
104 
105  try {
106  correlationInstances = CentralRepository.getInstance().getArtifactInstancesByTypeValue(type, value);
107  } catch (CentralRepoException ex) {
108  logger.log(Level.SEVERE, "Unable to connect to the Central Repository database.", ex);
109  } catch (CorrelationAttributeNormalizationException ex) {
110  logger.log(Level.SEVERE, "Unable to retrieve data from the Central Repository.", ex);
111  }
112 
113  return correlationInstances;
114  }
115 
116  @Override
117  protected void done() {
118  try {
119  super.done();
120  List<CorrelationAttributeInstance> correlationInstances = this.get();
121  DataResultViewerTable table = new DataResultViewerTable();
122  Collection<DataResultViewer> viewers = new ArrayList<>(1);
123  viewers.add(table);
124 
125  AllCasesSearchNode searchNode = new AllCasesSearchNode(correlationInstances);
126  TableFilterNode tableFilterNode = new TableFilterNode(searchNode, true, searchNode.getName());
127 
128  String resultsText = String.format("%s (%s; \"%s\")",
129  Bundle.AllCasesSearchDialog_resultsTitle_text(), type.getDisplayName(), value);
130  final TopComponent searchResultWin;
131  if (correlationInstances.isEmpty()) {
132  Node emptyNode = new TableFilterNode(
133  new EmptyNode(Bundle.AllCasesSearchDialog_emptyNode_text()), true);
134  searchResultWin = DataResultTopComponent.createInstance(
135  resultsText, Bundle.AllCasesSearchDialog_resultsDescription_text(), emptyNode, 0);
136  } else {
137  searchResultWin = DataResultTopComponent.createInstance(
138  resultsText, Bundle.AllCasesSearchDialog_resultsDescription_text(), tableFilterNode, correlationInstances.size(), viewers);
139  }
140  searchResultWin.requestActive(); // make it the active top component
141  } catch (ExecutionException | InterruptedException ex) {
142  logger.log(Level.SEVERE, "Unable to get CorrelationAttributeInstances.", ex);
143  }
144  }
145  }.execute();
146  }
147 
153  @SuppressWarnings("unchecked")
154  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
155  private void initComponents() {
156 
157  correlationValueLabel = new javax.swing.JLabel();
158  correlationValueTextField = new javax.swing.JTextField();
159  searchButton = new javax.swing.JButton();
160  correlationTypeComboBox = new javax.swing.JComboBox<>();
161  correlationTypeLabel = new javax.swing.JLabel();
162  errorLabel = new javax.swing.JLabel();
163  descriptionLabel = new javax.swing.JLabel();
164  casesLabel = new javax.swing.JLabel();
165 
166  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
167  setResizable(false);
168 
169  org.openide.awt.Mnemonics.setLocalizedText(correlationValueLabel, org.openide.util.NbBundle.getMessage(AllCasesSearchDialog.class, "AllCasesSearchDialog.correlationValueLabel.text")); // NOI18N
170 
171  correlationValueTextField.setText(org.openide.util.NbBundle.getMessage(AllCasesSearchDialog.class, "AllCasesSearchDialog.correlationValueTextField.text")); // NOI18N
172  correlationValueTextField.addKeyListener(new java.awt.event.KeyAdapter() {
173  public void keyReleased(java.awt.event.KeyEvent evt) {
174  valueFieldKeyReleaseListener(evt);
175  }
176  });
177 
178  org.openide.awt.Mnemonics.setLocalizedText(searchButton, org.openide.util.NbBundle.getMessage(AllCasesSearchDialog.class, "AllCasesSearchDialog.searchButton.text")); // NOI18N
179  searchButton.addActionListener(new java.awt.event.ActionListener() {
180  public void actionPerformed(java.awt.event.ActionEvent evt) {
181  searchButtonActionPerformed(evt);
182  }
183  });
184 
185  correlationTypeComboBox.addActionListener(new java.awt.event.ActionListener() {
186  public void actionPerformed(java.awt.event.ActionEvent evt) {
187  correlationTypeComboBoxActionPerformed(evt);
188  }
189  });
190 
191  org.openide.awt.Mnemonics.setLocalizedText(correlationTypeLabel, org.openide.util.NbBundle.getMessage(AllCasesSearchDialog.class, "AllCasesSearchDialog.correlationTypeLabel.text")); // NOI18N
192 
193  errorLabel.setForeground(new java.awt.Color(255, 0, 0));
194  org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(AllCasesSearchDialog.class, "AllCasesSearchDialog.errorLabel.text")); // NOI18N
195 
196  org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(AllCasesSearchDialog.class, "AllCasesSearchDialog.descriptionLabel.text")); // NOI18N
197 
198  casesLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
199  org.openide.awt.Mnemonics.setLocalizedText(casesLabel, org.openide.util.NbBundle.getMessage(AllCasesSearchDialog.class, "AllCasesSearchDialog.casesLabel.text")); // NOI18N
200 
201  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
202  getContentPane().setLayout(layout);
203  layout.setHorizontalGroup(
204  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
205  .addGroup(layout.createSequentialGroup()
206  .addContainerGap()
207  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
208  .addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
209  .addGroup(layout.createSequentialGroup()
210  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
211  .addComponent(correlationValueLabel)
212  .addComponent(correlationTypeLabel))
213  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
214  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
215  .addComponent(correlationTypeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
216  .addComponent(correlationValueTextField)
217  .addComponent(errorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
218  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
219  .addComponent(casesLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
220  .addGap(18, 18, 18)
221  .addComponent(searchButton)))
222  .addContainerGap())
223  );
224  layout.setVerticalGroup(
225  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
227  .addContainerGap()
228  .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
229  .addGap(18, 18, 18)
230  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
231  .addComponent(correlationTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
232  .addComponent(correlationTypeLabel))
233  .addGap(15, 15, 15)
234  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
235  .addComponent(correlationValueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
236  .addComponent(correlationValueLabel))
237  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
238  .addComponent(errorLabel)
239  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
240  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
241  .addComponent(searchButton)
242  .addComponent(casesLabel))
243  .addContainerGap())
244  );
245 
246  searchButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AllCasesSearchDialog.class, "AllCasesSearchDialog.searchButton.AccessibleContext.accessibleName")); // NOI18N
247  searchButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AllCasesSearchDialog.class, "AllCasesSearchDialog.searchButton.AccessibleContext.accessibleDescription")); // NOI18N
248 
249  pack();
250  }// </editor-fold>//GEN-END:initComponents
251 
252  private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
253  CorrelationAttributeInstance.Type correlationType = selectedCorrelationType;
254  String correlationValue = correlationValueTextField.getText().trim();
255 
256  if (validateInputs(correlationType, correlationValue)) {
257  search(correlationType, correlationValue);
258  dispose();
259  } else {
260  String validationMessage;
261  switch (correlationType.getId()) {
262  case CorrelationAttributeInstance.FILES_TYPE_ID:
263  validationMessage = Bundle.AllCasesSearchDialog_validation_invalidHash();
264  break;
265  case CorrelationAttributeInstance.DOMAIN_TYPE_ID:
266  validationMessage = Bundle.AllCasesSearchDialog_validation_invalidDomain();
267  break;
268  case CorrelationAttributeInstance.EMAIL_TYPE_ID:
269  validationMessage = Bundle.AllCasesSearchDialog_validation_invalidEmail();
270  break;
271  case CorrelationAttributeInstance.PHONE_TYPE_ID:
272  validationMessage = Bundle.AllCasesSearchDialog_validation_invalidPhone();
273  break;
274  case CorrelationAttributeInstance.SSID_TYPE_ID:
275  validationMessage = Bundle.AllCasesSearchDialog_validation_invalidSsid();
276  break;
277  case CorrelationAttributeInstance.MAC_TYPE_ID:
278  validationMessage = Bundle.AllCasesSearchDialog_validation_invalidMac();
279  break;
280  case CorrelationAttributeInstance.IMEI_TYPE_ID:
281  validationMessage = Bundle.AllCasesSearchDialog_validation_invalidImei();
282  break;
283  case CorrelationAttributeInstance.IMSI_TYPE_ID:
284  validationMessage = Bundle.AllCasesSearchDialog_validation_invalidImsi();
285  break;
286  case CorrelationAttributeInstance.ICCID_TYPE_ID:
287  validationMessage = Bundle.AllCasesSearchDialog_validation_invalidIccid();
288  break;
289  default:
290  validationMessage = Bundle.AllCasesSearchDialog_validation_genericMessage();
291  break;
292 
293  }
294  errorLabel.setText(validationMessage);
295  searchButton.setEnabled(false);
296  correlationValueTextField.grabFocus();
297  }
298  }//GEN-LAST:event_searchButtonActionPerformed
299 
300  private void correlationTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_correlationTypeComboBoxActionPerformed
301  //make error message go away when combo box is selected
302  errorLabel.setText("");
303  }//GEN-LAST:event_correlationTypeComboBoxActionPerformed
304 
305  private void valueFieldKeyReleaseListener(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_valueFieldKeyReleaseListener
306  //make error message go away when the user enters anything in the value field
307  errorLabel.setText("");
308  }//GEN-LAST:event_valueFieldKeyReleaseListener
309 
318  private boolean validateInputs(CorrelationAttributeInstance.Type type, String value) {
319  try {
320  CorrelationAttributeNormalizer.normalize(type, value);
321  } catch (CorrelationAttributeNormalizationException ex) {
322  // No need to log this.
323  return false;
324  }
325 
326  return true;
327  }
328 
332  private void customizeComponents() {
333  searchButton.setEnabled(false);
334 
335  /*
336  * Add correlation types to the combo-box.
337  */
338  try {
339  CentralRepository dbManager = CentralRepository.getInstance();
340  correlationTypes.clear();
341  correlationTypes.addAll(dbManager.getDefinedCorrelationTypes());
342  int numberOfCases = dbManager.getCases().size();
343  casesLabel.setText(Bundle.AllCasesSearchDialog_caseLabel_text(numberOfCases));
344  } catch (CentralRepoException ex) {
345  logger.log(Level.SEVERE, "Unable to connect to the Central Repository database.", ex);
346  }
347 
348  for (CorrelationAttributeInstance.Type type : correlationTypes) {
349  correlationTypeComboBox.addItem(type.getDisplayName());
350  }
351  correlationTypeComboBox.setSelectedIndex(0);
352 
353  correlationTypeComboBox.addItemListener(new ItemListener() {
354  @Override
355  public void itemStateChanged(ItemEvent e) {
356  updateSelectedType();
357  updateCorrelationValueTextFieldPrompt();
358  updateSearchButton();
359  }
360  });
361 
362  updateSelectedType();
363 
364  /*
365  * Create listener for text input.
366  */
367  correlationValueTextField.getDocument().addDocumentListener(new DocumentListener() {
368  @Override
369  public void changedUpdate(DocumentEvent e) {
370  updateSearchButton();
371  }
372 
373  @Override
374  public void insertUpdate(DocumentEvent e) {
375  updateSearchButton();
376  }
377 
378  @Override
379  public void removeUpdate(DocumentEvent e) {
380  updateSearchButton();
381  }
382  });
383 
384  updateCorrelationValueTextFieldPrompt();
385  }
386 
387  @Messages({
388  "AllCasesSearchDialog.correlationValueTextField.filesExample=Example: \"f0e1d2c3b4a5968778695a4b3c2d1e0f\"",
389  "AllCasesSearchDialog.correlationValueTextField.domainExample=Example: \"domain.com\"",
390  "AllCasesSearchDialog.correlationValueTextField.emailExample=Example: \"user@host.com\"",
391  "AllCasesSearchDialog.correlationValueTextField.phoneExample=Example: \"(800)123-4567\"",
392  "AllCasesSearchDialog.correlationValueTextField.usbExample=Example: \"4&1234567&0\"",
393  "AllCasesSearchDialog.correlationValueTextField.ssidExample=Example: \"WirelessNetwork-5G\"",
394  "AllCasesSearchDialog.correlationValueTextField.macExample=Example: \"0C-14-F2-01-AF-45\"",
395  "AllCasesSearchDialog.correlationValueTextField.imeiExample=Example: \"351756061523999\"",
396  "AllCasesSearchDialog.correlationValueTextField.imsiExample=Example: \"310150123456789\"",
397  "AllCasesSearchDialog.correlationValueTextField.iccidExample=Example: \"89 91 19 1299 99 329451 0\""
398  })
403  private void updateCorrelationValueTextFieldPrompt() {
407  String text;
408  switch (selectedCorrelationType.getId()) {
409  case CorrelationAttributeInstance.FILES_TYPE_ID:
410  text = Bundle.AllCasesSearchDialog_correlationValueTextField_filesExample();
411  break;
412  case CorrelationAttributeInstance.DOMAIN_TYPE_ID:
413  text = Bundle.AllCasesSearchDialog_correlationValueTextField_domainExample();
414  break;
415  case CorrelationAttributeInstance.EMAIL_TYPE_ID:
416  text = Bundle.AllCasesSearchDialog_correlationValueTextField_emailExample();
417  break;
418  case CorrelationAttributeInstance.PHONE_TYPE_ID:
419  text = Bundle.AllCasesSearchDialog_correlationValueTextField_phoneExample();
420  break;
421  case CorrelationAttributeInstance.USBID_TYPE_ID:
422  text = Bundle.AllCasesSearchDialog_correlationValueTextField_usbExample();
423  break;
424  case CorrelationAttributeInstance.SSID_TYPE_ID:
425  text = Bundle.AllCasesSearchDialog_correlationValueTextField_ssidExample();
426  break;
427  case CorrelationAttributeInstance.MAC_TYPE_ID:
428  text = Bundle.AllCasesSearchDialog_correlationValueTextField_macExample();
429  break;
430  case CorrelationAttributeInstance.IMEI_TYPE_ID:
431  text = Bundle.AllCasesSearchDialog_correlationValueTextField_imeiExample();
432  break;
433  case CorrelationAttributeInstance.IMSI_TYPE_ID:
434  text = Bundle.AllCasesSearchDialog_correlationValueTextField_imsiExample();
435  break;
436  case CorrelationAttributeInstance.ICCID_TYPE_ID:
437  text = Bundle.AllCasesSearchDialog_correlationValueTextField_iccidExample();
438  break;
439  default:
440  text = "";
441  break;
442  }
443  correlationValueTextFieldPrompt = new TextPrompt(text, correlationValueTextField);
444 
448  correlationValueTextFieldPrompt.setForeground(Color.LIGHT_GRAY);
449  correlationValueTextFieldPrompt.changeAlpha(0.9f); // Mostly opaque
450 
451  validate();
452  repaint();
453  }
454 
459  private void updateSelectedType() {
460  for (CorrelationAttributeInstance.Type type : correlationTypes) {
461  if (type.getDisplayName().equals((String) correlationTypeComboBox.getSelectedItem())) {
462  selectedCorrelationType = type;
463  break;
464  }
465  }
466  }
467 
472  private void updateSearchButton() {
473  searchButton.setEnabled(correlationValueTextField.getText().isEmpty() == false);
474  }
475 
479  public void display() {
480  this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
481  setVisible(true);
482  }
483 
484  // Variables declaration - do not modify//GEN-BEGIN:variables
485  private javax.swing.JLabel casesLabel;
486  private javax.swing.JComboBox<String> correlationTypeComboBox;
487  private javax.swing.JLabel correlationTypeLabel;
488  private javax.swing.JLabel correlationValueLabel;
489  private javax.swing.JTextField correlationValueTextField;
490  private javax.swing.JLabel descriptionLabel;
491  private javax.swing.JLabel errorLabel;
492  private javax.swing.JButton searchButton;
493  // End of variables declaration//GEN-END:variables
494 }

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.