19package org.sleuthkit.autopsy.contentviewers.osaccount;
21import java.awt.BorderLayout;
23import java.awt.GridBagConstraints;
24import java.awt.GridBagLayout;
25import java.awt.Insets;
26import java.text.SimpleDateFormat;
27import java.util.ArrayList;
29import java.util.HashMap;
31import static java.util.Locale.US;
33import java.util.Optional;
34import java.util.concurrent.ExecutionException;
35import java.util.logging.Level;
36import java.util.logging.Logger;
37import javax.swing.Box;
38import javax.swing.JLabel;
39import javax.swing.JPanel;
40import javax.swing.SwingWorker;
41import javax.swing.UIManager;
42import javax.swing.border.EmptyBorder;
43import org.openide.util.NbBundle.Messages;
44import org.sleuthkit.autopsy.casemodule.Case;
45import org.sleuthkit.autopsy.contentviewers.layout.ContentViewerDefaults;
46import org.sleuthkit.autopsy.contentviewers.osaccount.Section.SectionData;
47import org.sleuthkit.autopsy.contentviewers.osaccount.Section.RowData;
48import org.sleuthkit.autopsy.coreutils.TimeZoneUtils;
49import org.sleuthkit.datamodel.BlackboardAttribute;
50import org.sleuthkit.datamodel.Content;
51import org.sleuthkit.datamodel.DataSource;
52import org.sleuthkit.datamodel.Host;
53import org.sleuthkit.datamodel.OsAccount;
54import org.sleuthkit.datamodel.OsAccount.OsAccountAttribute;
55import org.sleuthkit.datamodel.OsAccountInstance;
56import org.sleuthkit.datamodel.OsAccountManager;
57import org.sleuthkit.datamodel.OsAccountRealm;
58import org.sleuthkit.datamodel.SleuthkitCase;
63public class OsAccountDataPanel
extends JPanel {
76 private static final SimpleDateFormat
DATE_FORMAT =
new SimpleDateFormat(
"MMM dd yyyy", US);
81 OsAccountDataPanel() {
89 this.setLayout(
new GridBagLayout());
99 void setOsAccountId(Long osAccountId) {
103 if (osAccountId !=
null) {
104 setLayout(
new BorderLayout());
105 add(
new JLabel(
"Loading OsAccount Data..."), BorderLayout.NORTH);
116 void setOsAccount(OsAccount account) {
120 if (account !=
null) {
121 setLayout(
new BorderLayout());
122 add(
new JLabel(
"Loading OsAccount Data..."), BorderLayout.NORTH);
142 for (Section section : panelData) {
143 addTitle(section.getTitle(), rowCnt++);
144 for (SectionData data : section) {
145 String subtitle = data.getTitle();
146 if (subtitle !=
null) {
150 for (RowData<String, String> rowData : data) {
151 String key = rowData.getKey();
152 String value = rowData.getValue();
167 GridBagConstraints constraints =
new GridBagConstraints();
168 constraints.gridx = 0;
169 constraints.gridy = rowCnt;
170 constraints.gridwidth = 2;
171 constraints.fill = GridBagConstraints.BOTH;
172 constraints.weightx = 1;
173 constraints.weighty = 1;
174 add(Box.createVerticalGlue(), constraints);
178 "OsAccountDataPanel_basic_title=Basic Properties",
179 "OsAccountDataPanel_basic_login=Login",
180 "OsAccountDataPanel_basic_fullname=Full Name",
181 "OsAccountDataPanel_basic_address=Address",
182 "OsAccountDataPanel_basic_admin=Administrator",
183 "OsAccountDataPanel_basic_type=Type",
184 "OsAccountDataPanel_basic_creationDate=Creation Date",
185 "OsAccountDataPanel_basic_objId=Object ID"})
195 Section section =
new Section(Bundle.OsAccountDataPanel_basic_title());
197 SectionData data =
new SectionData();
199 Optional<String> optional = account.getLoginName();
200 data.addData(Bundle.OsAccountDataPanel_basic_login(),
201 optional.isPresent() ? optional.get() :
"");
203 optional = account.getFullName();
204 data.addData(Bundle.OsAccountDataPanel_basic_fullname(),
205 optional.isPresent() ? optional.get() :
"");
207 data.addData(Bundle.OsAccountDataPanel_basic_address(),
208 account.getName() ==
null || account.getName().isEmpty() ?
"" : account.getName());
210 data.addData(Bundle.OsAccountDataPanel_basic_type(),
211 account.getOsAccountType().isPresent() ? account.getOsAccountType().get().getName() :
"");
213 Optional<Long> crTime = account.getCreationTime();
216 data.addData(Bundle.OsAccountDataPanel_basic_objId(), Long.toString(account.getId()));
218 section.addSectionData(data);
223 "OsAccountDataPanel_realm_title=Realm Properties",
224 "OsAccountDataPanel_realm_name=Name",
225 "OsAccountDataPanel_realm_address=Address",
226 "OsAccountDataPanel_realm_confidence=Confidence",
227 "OsAccountDataPanel_realm_unknown=Unknown",
228 "OsAccountDataPanel_realm_scope=Scope",})
238 Section section =
new Section(Bundle.OsAccountDataPanel_realm_title());
239 SectionData data =
new SectionData();
241 String realmName = realm.getRealmNames().isEmpty() ? Bundle.OsAccountDataPanel_realm_unknown() : realm.getRealmNames().get(0);
242 data.addData(Bundle.OsAccountDataPanel_realm_name(), realmName);
244 Optional<String> optional = realm.getRealmAddr();
245 data.addData(Bundle.OsAccountDataPanel_realm_address(),
246 optional.isPresent() ? optional.get() :
"");
248 data.addData(Bundle.OsAccountDataPanel_realm_scope(),
249 realm.getScope().getName());
251 data.addData(Bundle.OsAccountDataPanel_realm_confidence(),
252 realm.getScopeConfidence().getName());
254 section.addSectionData(data);
260 "OsAccountDataPanel_host_section_title={0} Details",
261 "OsAccountDataPanel_host_count_title=Login Count",
262 "OsAccountDataPanel_data_accessed_title=Last Login",
263 "OsAccountDataPanel_administrator_title=Administrator"
265 private Section
buildHostData(Host host, Map<DataSource, List<OsAccountAttribute>> attributeDataSourceMap) {
266 String sectionTitle =
"Global Host Details";
269 sectionTitle = Bundle.OsAccountDataPanel_host_section_title(host.getName());
272 Section section =
new Section(sectionTitle);
274 for (DataSource dataSource : attributeDataSourceMap.keySet()) {
275 List<OsAccountAttribute> attributeList = attributeDataSourceMap.get(dataSource);
276 SectionData data =
new SectionData((attributeDataSourceMap.size() > 1 && dataSource !=
null) ? dataSource.getName() :
null);
277 if (attributeList !=
null) {
278 for (OsAccountAttribute attribute : attributeList) {
279 String displayName = attribute.getAttributeType().getDisplayName();
280 String value = attribute.getDisplayString();
282 if (attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COUNT.getTypeID()) {
283 displayName = Bundle.OsAccountDataPanel_host_count_title();
284 }
else if (attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_IS_ADMIN.getTypeID()) {
285 displayName = Bundle.OsAccountDataPanel_administrator_title();
286 if (attribute.getValueInt() == 0) {
291 }
else if (attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID()) {
292 displayName = Bundle.OsAccountDataPanel_data_accessed_title();
295 data.addData(displayName, value);
298 data.addData(
"No details available",
null);
301 section.addSectionData(data);
314 JLabel label =
new JLabel(title);
321 JLabel label =
new JLabel(title);
323 label.setFont(label.getFont().deriveFont(Font.BOLD));
334 JLabel label =
new JLabel(key +
":");
345 JLabel label =
new JLabel(text);
357 JLabel label =
new JLabel(value);
369 GridBagConstraints constraints =
new GridBagConstraints();
371 constraints.gridx = 0;
372 constraints.gridy = row;
373 constraints.gridwidth = 2;
374 constraints.gridheight = 1;
375 constraints.anchor = GridBagConstraints.NORTHWEST;
376 constraints.fill = GridBagConstraints.HORIZONTAL;
377 constraints.weightx = 1;
378 constraints.insets = (row == 0)
386 GridBagConstraints constraints =
new GridBagConstraints();
388 constraints.gridx = 0;
389 constraints.gridy = row;
390 constraints.gridwidth = 2;
391 constraints.gridheight = 1;
392 constraints.anchor = GridBagConstraints.NORTHWEST;
393 constraints.fill = GridBagConstraints.HORIZONTAL;
394 constraints.weightx = 1;
408 GridBagConstraints constraints =
new GridBagConstraints();
411 constraints.gridy = row;
412 constraints.gridwidth = 1;
413 constraints.gridheight = 1;
414 constraints.anchor = GridBagConstraints.WEST;
428 GridBagConstraints constraints =
new GridBagConstraints();
431 constraints.gridy = row;
432 constraints.gridwidth = 1;
433 constraints.gridheight = 1;
434 constraints.fill = GridBagConstraints.HORIZONTAL;
436 constraints.weightx = 1;
444 private class PanelDataFetcher
extends SwingWorker<WorkerResults, Void> {
461 this.accountId =
null;
466 Map<Host, Map<DataSource, List<OsAccountAttribute>>> hostMap =
new HashMap<>();
467 Map<Host, DataSource> instanceMap =
new HashMap<>();
469 OsAccountManager osAccountManager = skCase.getOsAccountManager();
475 OsAccountRealm realm = skCase.getOsAccountRealmManager().getRealmByRealmId(
account.getRealmId());
477 List<Host> hosts = osAccountManager.getHosts(
account);
478 List<OsAccountAttribute> attributeList =
account.getExtendedOsAccountAttributes();
481 Map<Long, Map<DataSource, List<OsAccountAttribute>>> idMap2 =
new HashMap<>();
482 if (attributeList !=
null) {
483 for (OsAccountAttribute attribute : attributeList) {
485 Long key = attribute.getHostId().orElse(
null);
486 Long sourceID = attribute.getSourceObjectId().orElse(
null);
487 DataSource dataSource =
null;
489 if (sourceID !=
null) {
490 Content sourceContent = skCase.getContentById(sourceID);
491 if (sourceContent !=
null) {
492 dataSource = (DataSource) sourceContent.getDataSource();
496 Map<DataSource, List<OsAccountAttribute>> atMap = idMap2.get(key);
498 atMap =
new HashMap<>();
499 idMap2.put(key, atMap);
502 List<OsAccountAttribute> mapList = atMap.get(dataSource);
503 if (mapList ==
null) {
504 mapList =
new ArrayList<>();
505 atMap.put(dataSource, mapList);
507 mapList.add(attribute);
513 for (Host host : hosts) {
514 hostMap.put(host, idMap2.get(host.getHostId()));
518 hostMap.put(
null, idMap2.get(
null));
519 Map<DataSource, List<OsAccountAttribute>> atMap = idMap2.get(
null);
521 hostMap.put(
null, atMap);
526 for (OsAccountInstance instance :
account.getOsAccountInstances()) {
527 instanceMap.put(instance.getDataSource().getHost(), instance.getDataSource());
538 if (this.isCancelled()) {
543 }
catch (ExecutionException | InterruptedException ex) {
544 logger.log(Level.SEVERE, String.format(
"Failed to retrieve data for OsAccount (%d)",
account.getId()), ex);
547 if (results !=
null) {
549 setLayout(
new GridBagLayout());
551 List<Section> data =
new ArrayList<>();
553 Map<Host, Map<DataSource, List<OsAccountAttribute>>> hostDataMap = results.getAttributeMap();
554 if (hostDataMap !=
null && !hostDataMap.isEmpty()) {
555 hostDataMap.entrySet().stream().forEach(pair -> {
556 if (pair.getKey() !=
null && pair.getValue() !=
null) {
562 OsAccountRealm realm = results.getRealm();
588 private final class WorkerResults {
590 private final Map<Host, Map<DataSource, List<OsAccountAttribute>>>
attributeMap;
602 WorkerResults(Map<Host, Map<DataSource, List<OsAccountAttribute>>>
attributeMap, Map<Host, DataSource>
instanceMap, OsAccountRealm
realm) {
615 Map<Host, Map<DataSource, List<OsAccountAttribute>>> getAttributeMap() {
624 Map<Host, DataSource> getDataSourceMap() {
628 OsAccountRealm getRealm() {
SleuthkitCase getSleuthkitCase()
static Case getCurrentCase()
static Insets getPanelInsets()
static Font getHeaderFont()
static int getColumnSpacing()
static Integer getSectionIndent()
static Integer getSectionSpacing()
static Integer getLineSpacing()
WorkerResults doInBackground()
final Map< Host, Map< DataSource, List< OsAccountAttribute > > > attributeMap
final Map< Host, DataSource > instanceMap
final OsAccountRealm realm
void addLabel(String text, int row)
void addSubTitle(String title, int row)
static final Insets KEY_COLUMN_INSETS
PanelDataFetcher dataFetcher
void addPropertyName(String key, int row)
static final long serialVersionUID
GridBagConstraints getPropertyNameContraints(int row)
final static Logger logger
void addDataComponents(List< Section > panelData)
static final SimpleDateFormat DATE_FORMAT
GridBagConstraints getTitleContraints(int row)
static final Insets VALUE_COLUMN_INSETS
static final Insets SUBHEADER_COLUMN_INSETS
Section buildRealmProperties(OsAccountRealm realm)
Section buildBasicProperties(OsAccount account)
static final int VALUE_COLUMN
GridBagConstraints getSubtitleContraints(int row)
GridBagConstraints getPropertyValueContraints(int row)
static final Insets FIRST_HEADER_INSETS
void addPropertyValue(String value, int row)
static final int KEY_COLUMN
void addTitle(String title, int row)
Section buildHostData(Host host, Map< DataSource, List< OsAccountAttribute > > attributeDataSourceMap)
static final Insets HEADER_INSETS
synchronized static Logger getLogger(String name)
static String getFormattedTime(long epochTime)