Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
OsAccountViewer.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  */
19 package org.sleuthkit.autopsy.contentviewers.osaccount;
20 
21 import java.awt.BorderLayout;
22 import java.awt.Component;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.util.Optional;
26 import java.util.logging.Level;
27 import org.openide.nodes.Node;
28 import org.openide.util.NbBundle.Messages;
29 import org.openide.util.lookup.ServiceProvider;
32 import org.sleuthkit.datamodel.AbstractFile;
33 import org.sleuthkit.datamodel.DataArtifact;
34 import org.sleuthkit.datamodel.OsAccount;
35 import org.sleuthkit.datamodel.TskCoreException;
36 
40 @ServiceProvider(service = DataContentViewer.class, position = 5)
41 public class OsAccountViewer extends javax.swing.JPanel implements DataContentViewer {
42 
43  private static final long serialVersionUID = 1L;
44  private final static Logger logger = Logger.getLogger(OsAccountViewer.class.getName());
45 
46  private final OsAccountDataPanel dataPanel = new OsAccountDataPanel();
47 
51  public OsAccountViewer() {
52  initComponents();
53 
54  mainScrollPane.setViewportView(dataPanel);
55  }
56 
57  @Override
58  public void setNode(Node node) {
59  Long osAccountId = null;
60  try {
61  OsAccount osAccount = node.getLookup().lookup(OsAccount.class);
62  if (osAccount != null) {
63  dataPanel.setOsAccount(osAccount);
64  return;
65  }
66 
67  Optional<Long> optional;
68  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
69  if (file != null) {
70  optional = file.getOsAccountObjectId();
71  if (optional.isPresent()) {
72  osAccountId = optional.get();
73  }
74  }
75 
76  if (osAccountId == null) {
77  DataArtifact dataArtifact = node.getLookup().lookup(DataArtifact.class);
78  if (dataArtifact != null) {
79  optional = dataArtifact.getOsAccountObjectId();
80  if (optional.isPresent()) {
81  osAccountId = optional.get();
82  }
83  }
84 
85  }
86  } catch (TskCoreException ex) {
87  logger.log(Level.SEVERE, String.format("Failed to get OsAccount for node %s", node.getDisplayName()), ex);
88  }
89 
90  if (osAccountId != null) {
91  dataPanel.setOsAccountId(osAccountId);
92  }
93  }
94 
95  @Messages({
96  "OsAccountViewer_title=OS Account"
97  })
98  @Override
99  public String getTitle() {
100  return Bundle.OsAccountViewer_title();
101  }
102 
103  @Messages({
104  "OsAccountViewer_tooltip=Viewer for Operating System accounts related to the selected node."
105  })
106  @Override
107  public String getToolTip() {
108  return Bundle.OsAccountViewer_tooltip();
109  }
110 
111  @Override
112  public DataContentViewer createInstance() {
113  return new OsAccountViewer();
114  }
115 
116  @Override
117  public Component getComponent() {
118  return this;
119  }
120 
121  @Override
122  public void resetComponent() {
123  dataPanel.setOsAccount(null);
124  }
125 
126  @Override
127  public boolean isSupported(Node node) {
128  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
129  OsAccount osAccount = node.getLookup().lookup(OsAccount.class);
130  DataArtifact dataArtifact = node.getLookup().lookup(DataArtifact.class);
131 
132  try {
133  return osAccount != null
134  || (file != null && file.getOsAccountObjectId().isPresent())
135  || (dataArtifact != null && dataArtifact.getOsAccountObjectId().isPresent());
136  } catch (TskCoreException ex) {
137  logger.log(Level.SEVERE, String.format("Failed to determine if node %s is Supported for OsAccountViewer", node.getDisplayName()), ex);
138  return false;
139  }
140  }
141 
142  @Override
143  public int isPreferred(Node node) {
144  return 1;
145  }
146 
152  @SuppressWarnings("unchecked")
153  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
154  private void initComponents() {
155  java.awt.GridBagConstraints gridBagConstraints;
156 
157  mainScrollPane = new javax.swing.JScrollPane();
158 
159  setLayout(new java.awt.GridBagLayout());
160 
161  mainScrollPane.setPreferredSize(new java.awt.Dimension(200, 0));
162  gridBagConstraints = new java.awt.GridBagConstraints();
163  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
164  gridBagConstraints.weightx = 1.0;
165  gridBagConstraints.weighty = 1.0;
166  add(mainScrollPane, gridBagConstraints);
167  }// </editor-fold>//GEN-END:initComponents
168 
169 
170  // Variables declaration - do not modify//GEN-BEGIN:variables
171  private javax.swing.JScrollPane mainScrollPane;
172  // End of variables declaration//GEN-END:variables
173 
174 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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