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