Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
PersonaAccountDialog.java
Go to the documentation of this file.
1 /*
2  * Central Repository
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.centralrepository.persona;
20 
21 import java.awt.Component;
22 import java.io.Serializable;
23 import java.util.Collection;
24 import java.util.logging.Level;
25 import javax.swing.JDialog;
26 import javax.swing.JLabel;
27 import javax.swing.JList;
28 import javax.swing.JOptionPane;
29 import javax.swing.ListCellRenderer;
30 import javax.swing.SwingUtilities;
31 import org.apache.commons.lang.StringUtils;
32 import org.openide.util.NbBundle.Messages;
33 import org.openide.windows.WindowManager;
40 import org.sleuthkit.datamodel.InvalidAccountIDException;
41 
45 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
46 public class PersonaAccountDialog extends JDialog {
47 
48  private static final Logger logger = Logger.getLogger(PersonaAccountDialog.class.getName());
49 
50  private static final long serialVersionUID = 1L;
51 
52  private final TypeChoiceRenderer TYPE_CHOICE_RENDERER = new TypeChoiceRenderer();
53  private final PersonaDetailsPanel pdp;
54 
55  private PersonaDetailsPanel.PAccount currentAccount = null;
56 
60  @Messages({"PersonaAccountDialog.title.text=Add Account",})
62  super(SwingUtilities.windowForComponent(pdp),
63  Bundle.PersonaAccountDialog_title_text(),
64  ModalityType.APPLICATION_MODAL);
65  this.pdp = pdp;
66 
67  initComponents();
68  typeComboBox.setRenderer(TYPE_CHOICE_RENDERER);
69  display();
70  }
71 
73  super(SwingUtilities.windowForComponent(pdp),
74  Bundle.PersonaAccountDialog_title_text(),
75  ModalityType.APPLICATION_MODAL);
76  this.pdp = pdp;
77 
78  initComponents();
79  currentAccount = acc;
80  confidenceComboBox.setSelectedItem(acc.confidence);
81  justificationTextField.setText(acc.justification);
82  typeComboBox.setSelectedItem(acc.account.getAccountType());
83  identifierTextField.setText(acc.account.getIdentifier());
84 
85  typeComboBox.setEnabled(false);
86  identifierTextField.setEnabled(false);
87 
88  typeComboBox.setRenderer(TYPE_CHOICE_RENDERER);
89  display();
90  }
91 
96  private class TypeChoiceRenderer extends JLabel implements ListCellRenderer<CentralRepoAccountType>, Serializable {
97 
98  private static final long serialVersionUID = 1L;
99 
100  @Override
102  JList<? extends CentralRepoAccountType> list, CentralRepoAccountType value,
103  int index, boolean isSelected, boolean cellHasFocus) {
104  setText(value.getAcctType().getDisplayName());
105  return this;
106  }
107  }
108 
109  @Messages({
110  "PersonaAccountDialog_get_types_exception_Title=Central Repository failure",
111  "PersonaAccountDialog_get_types_exception_msg=Failed to access central repository.",})
113  Collection<CentralRepoAccountType> allAccountTypes;
114  try {
115  allAccountTypes = CentralRepository.getInstance().getAllAccountTypes();
116  } catch (CentralRepoException e) {
117  logger.log(Level.SEVERE, "Failed to access central repository", e);
118  JOptionPane.showMessageDialog(this,
119  Bundle.PersonaAccountDialog_get_types_exception_Title(),
120  Bundle.PersonaAccountDialog_get_types_exception_msg(),
121  JOptionPane.ERROR_MESSAGE);
122  return new CentralRepoAccountType[0];
123  }
124  return allAccountTypes.toArray(new CentralRepoAccountType[0]);
125  }
126 
132  @SuppressWarnings("unchecked")
133  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
134  private void initComponents() {
135 
136  settingsPanel = new javax.swing.JPanel();
137  identiferLbl = new javax.swing.JLabel();
138  identifierTextField = new javax.swing.JTextField();
139  typeLbl = new javax.swing.JLabel();
140  typeComboBox = new javax.swing.JComboBox<>();
141  confidenceLbl = new javax.swing.JLabel();
142  confidenceComboBox = new javax.swing.JComboBox<>();
143  justificationLbl = new javax.swing.JLabel();
144  justificationTextField = new javax.swing.JTextField();
145  cancelBtn = new javax.swing.JButton();
146  okBtn = new javax.swing.JButton();
147 
148  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
149  setResizable(false);
150 
151  settingsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
152 
153  org.openide.awt.Mnemonics.setLocalizedText(identiferLbl, org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.identiferLbl.text")); // NOI18N
154 
155  identifierTextField.setText(org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.identifierTextField.text")); // NOI18N
156  identifierTextField.addActionListener(new java.awt.event.ActionListener() {
157  public void actionPerformed(java.awt.event.ActionEvent evt) {
158  identifierTextFieldActionPerformed(evt);
159  }
160  });
161 
162  org.openide.awt.Mnemonics.setLocalizedText(typeLbl, org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.typeLbl.text")); // NOI18N
163 
164  typeComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(getAllAccountTypes()));
165 
166  org.openide.awt.Mnemonics.setLocalizedText(confidenceLbl, org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.confidenceLbl.text")); // NOI18N
167 
168  confidenceComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(org.sleuthkit.autopsy.centralrepository.datamodel.Persona.Confidence.values()));
169 
170  org.openide.awt.Mnemonics.setLocalizedText(justificationLbl, org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.justificationLbl.text")); // NOI18N
171 
172  justificationTextField.setText(org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.justificationTextField.text")); // NOI18N
173 
174  javax.swing.GroupLayout settingsPanelLayout = new javax.swing.GroupLayout(settingsPanel);
175  settingsPanel.setLayout(settingsPanelLayout);
176  settingsPanelLayout.setHorizontalGroup(
177  settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178  .addGroup(settingsPanelLayout.createSequentialGroup()
179  .addContainerGap()
180  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
181  .addGroup(settingsPanelLayout.createSequentialGroup()
182  .addComponent(typeLbl)
183  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
184  .addComponent(typeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
185  .addGroup(settingsPanelLayout.createSequentialGroup()
186  .addComponent(identiferLbl)
187  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
188  .addComponent(identifierTextField))
189  .addGroup(settingsPanelLayout.createSequentialGroup()
190  .addComponent(confidenceLbl)
191  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
192  .addComponent(confidenceComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
193  .addGroup(settingsPanelLayout.createSequentialGroup()
194  .addComponent(justificationLbl)
195  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
196  .addComponent(justificationTextField)))
197  .addContainerGap())
198  );
199  settingsPanelLayout.setVerticalGroup(
200  settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
201  .addGroup(settingsPanelLayout.createSequentialGroup()
202  .addContainerGap()
203  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
204  .addComponent(identiferLbl)
205  .addComponent(identifierTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
206  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
207  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
208  .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
209  .addComponent(typeLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE))
210  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
211  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
212  .addComponent(confidenceLbl)
213  .addComponent(confidenceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
214  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
215  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
216  .addComponent(justificationLbl)
217  .addComponent(justificationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
218  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
219  );
220 
221  org.openide.awt.Mnemonics.setLocalizedText(cancelBtn, org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.cancelBtn.text")); // NOI18N
222  cancelBtn.setMaximumSize(new java.awt.Dimension(79, 23));
223  cancelBtn.setMinimumSize(new java.awt.Dimension(79, 23));
224  cancelBtn.setPreferredSize(new java.awt.Dimension(79, 23));
225  cancelBtn.addActionListener(new java.awt.event.ActionListener() {
226  public void actionPerformed(java.awt.event.ActionEvent evt) {
227  cancelBtnActionPerformed(evt);
228  }
229  });
230 
231  org.openide.awt.Mnemonics.setLocalizedText(okBtn, org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.okBtn.text")); // NOI18N
232  okBtn.addActionListener(new java.awt.event.ActionListener() {
233  public void actionPerformed(java.awt.event.ActionEvent evt) {
234  okBtnActionPerformed(evt);
235  }
236  });
237 
238  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
239  getContentPane().setLayout(layout);
240  layout.setHorizontalGroup(
241  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
242  .addGroup(layout.createSequentialGroup()
243  .addContainerGap(194, Short.MAX_VALUE)
244  .addComponent(okBtn)
245  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
246  .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
247  .addContainerGap())
248  .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
249  );
250 
251  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelBtn, okBtn});
252 
253  layout.setVerticalGroup(
254  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
255  .addGroup(layout.createSequentialGroup()
256  .addContainerGap()
257  .addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
258  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
259  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
260  .addComponent(okBtn, javax.swing.GroupLayout.Alignment.TRAILING)
261  .addComponent(cancelBtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
262  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
263  );
264 
265  pack();
266  }// </editor-fold>//GEN-END:initComponents
267 
268  private void display() {
269  this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
270  setVisible(true);
271  }
272 
273  @Messages({
274  "PersonaAccountDialog_dup_Title=Account add failure",
275  "PersonaAccountDialog_dup_msg=This account is already added to the persona.",
276  "PersonaAccountDialog_identifier_empty_Title=Empty identifier",
277  "PersonaAccountDialog_identifier_empty_msg=The identifier field cannot be empty.",
278  "PersonaAccountDialog_search_failure_Title=Account add failure",
279  "PersonaAccountDialog_search_failure_msg=Central Repository account search failed.",
280  "PersonaAccountDialog_search_empty_Title=Account not found",
281  "PersonaAccountDialog_search_empty_msg=Account not found for given identifier and type.",
282  "PersonaAccountDialog_invalid_account_Title=Invalid account identifier",
283  "PersonaAccountDialog_invalid_account_msg=Account identifier is not valid.",
284  })
285  private void okBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtnActionPerformed
286  if (StringUtils.isBlank(identifierTextField.getText())) {
287  JOptionPane.showMessageDialog(this,
288  Bundle.PersonaAccountDialog_identifier_empty_msg(),
289  Bundle.PersonaAccountDialog_identifier_empty_Title(),
290  JOptionPane.ERROR_MESSAGE);
291  return;
292  }
293  if (StringUtils.isBlank(justificationTextField.getText())) {
294  JOptionPane.showMessageDialog(this,
295  Bundle.PersonaDetailsPanel_empty_justification_msg(),
296  Bundle.PersonaDetailsPanel_empty_justification_Title(),
297  JOptionPane.ERROR_MESSAGE);
298  return;
299  }
300  Collection<CentralRepoAccount> candidates;
301  try {
302  candidates = CentralRepoAccount.getAccountsWithIdentifier(identifierTextField.getText());
303  } catch (CentralRepoException e) {
304  logger.log(Level.SEVERE, "Failed to access central repository", e);
305  JOptionPane.showMessageDialog(this,
306  Bundle.PersonaAccountDialog_search_failure_msg(),
307  Bundle.PersonaAccountDialog_search_failure_Title(),
308  JOptionPane.ERROR_MESSAGE);
309  return;
310  }
311  catch (InvalidAccountIDException e) {
312  logger.log(Level.SEVERE, "Invalid account identifier", e);
313  JOptionPane.showMessageDialog(this,
314  Bundle.PersonaAccountDialog_invalid_account_msg(),
315  Bundle.PersonaAccountDialog_invalid_account_Title(),
316  JOptionPane.ERROR_MESSAGE);
317  return;
318  }
319  if (candidates.isEmpty()) {
320  JOptionPane.showMessageDialog(this,
321  Bundle.PersonaAccountDialog_search_empty_msg(),
322  Bundle.PersonaAccountDialog_search_empty_Title(),
323  JOptionPane.ERROR_MESSAGE);
324  return;
325  }
326  CentralRepoAccount result = null;
327  for (CentralRepoAccount cand : candidates) {
328  if (cand.getAccountType().getAcctType().equals(
329  ((CentralRepoAccountType) typeComboBox.getSelectedItem()).getAcctType())) {
330  result = cand;
331  break;
332  }
333  }
334  if (result == null) {
335  JOptionPane.showMessageDialog(this,
336  Bundle.PersonaAccountDialog_search_empty_msg(),
337  Bundle.PersonaAccountDialog_search_empty_Title(),
338  JOptionPane.ERROR_MESSAGE);
339  return;
340  }
341 
342  Persona.Confidence confidence = (Persona.Confidence) confidenceComboBox.getSelectedItem();
343  String justification = justificationTextField.getText();
344 
345  if (currentAccount != null) {
346  currentAccount.confidence = confidence;
347  currentAccount.justification = justification;
348  dispose();
349  } else {
350  if (pdp.addAccount(result, justification, confidence)) {
351  dispose();
352  } else {
353  JOptionPane.showMessageDialog(this,
354  Bundle.PersonaAccountDialog_dup_msg(),
355  Bundle.PersonaAccountDialog_dup_Title(),
356  JOptionPane.ERROR_MESSAGE);
357  }
358  }
359  }//GEN-LAST:event_okBtnActionPerformed
360 
361  private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
362  dispose();
363  }//GEN-LAST:event_cancelBtnActionPerformed
364 
365  private void identifierTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_identifierTextFieldActionPerformed
366  // TODO add your handling code here:
367  }//GEN-LAST:event_identifierTextFieldActionPerformed
368 
369  // Variables declaration - do not modify//GEN-BEGIN:variables
370  private javax.swing.JButton cancelBtn;
372  private javax.swing.JLabel confidenceLbl;
373  private javax.swing.JLabel identiferLbl;
374  private javax.swing.JTextField identifierTextField;
375  private javax.swing.JLabel justificationLbl;
376  private javax.swing.JTextField justificationTextField;
377  private javax.swing.JButton okBtn;
378  private javax.swing.JPanel settingsPanel;
380  private javax.swing.JLabel typeLbl;
381  // End of variables declaration//GEN-END:variables
382 }
Component getListCellRendererComponent(JList<?extends CentralRepoAccountType > list, CentralRepoAccountType value, int index, boolean isSelected, boolean cellHasFocus)
javax.swing.JComboBox< org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoAccount.CentralRepoAccountType > typeComboBox
static Collection< CentralRepoAccount > getAccountsWithIdentifier(String accountIdentifier)
javax.swing.JComboBox< org.sleuthkit.autopsy.centralrepository.datamodel.Persona.Confidence > confidenceComboBox
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.