Autopsy  4.5.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AccountsRootChildren.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017 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.communications;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.openide.nodes.AbstractNode;
26 import org.openide.nodes.ChildFactory;
27 import org.openide.nodes.Children;
28 import org.openide.nodes.Node;
29 import org.openide.nodes.Sheet;
30 import org.openide.util.NbBundle;
31 import org.openide.util.lookup.Lookups;
34 import org.sleuthkit.datamodel.Account;
35 import org.sleuthkit.datamodel.AccountDeviceInstance;
36 import org.sleuthkit.datamodel.CommunicationsFilter;
37 import org.sleuthkit.datamodel.CommunicationsManager;
38 import org.sleuthkit.datamodel.DataSource;
39 import org.sleuthkit.datamodel.SleuthkitCase;
40 import org.sleuthkit.datamodel.TskCoreException;
41 
42 class AccountsRootChildren extends ChildFactory<AccountDeviceInstanceKey> {
43 
44  private static final Logger logger = Logger.getLogger(AccountsRootChildren.class.getName());
45 
46  private final CommunicationsManager commsManager;
47  private final CommunicationsFilter commsFilter;
48 
49  AccountsRootChildren(CommunicationsManager commsManager, CommunicationsFilter commsFilter) {
50  super();
51  this.commsManager = commsManager;
52  this.commsFilter = commsFilter;
53  }
54 
55  @Override
56  protected boolean createKeys(List<AccountDeviceInstanceKey> list) {
57  List<AccountDeviceInstanceKey> accountDeviceInstanceKeys = new ArrayList<>();
58  try {
59  for (AccountDeviceInstance accountDeviceInstance : commsManager.getAccountDeviceInstancesWithRelationships(commsFilter)) {
60  long communicationsCount = commsManager.getRelationshipSourcesCount(accountDeviceInstance, commsFilter);
61  String dataSourceName = getDataSourceName(accountDeviceInstance);
62  accountDeviceInstanceKeys.add(new AccountDeviceInstanceKey(accountDeviceInstance, commsFilter, communicationsCount, dataSourceName));
63  };
64  } catch (TskCoreException tskCoreException) {
65  logger.log(Level.SEVERE, "Error getting filtered account device instances", tskCoreException);
66  }
67  list.addAll(accountDeviceInstanceKeys);
68 
69  return true;
70  }
71 
72  @Override
73  protected Node createNodeForKey(AccountDeviceInstanceKey key) {
74  return new AccountDeviceInstanceNode(key, commsManager);
75  }
76 
77  private String getDataSourceName(AccountDeviceInstance accountDeviceInstance) {
78  try {
79  final SleuthkitCase sleuthkitCase = Case.getCurrentCase().getSleuthkitCase();
80  for (DataSource dataSource : sleuthkitCase.getDataSources()) {
81  if (dataSource.getDeviceId().equals(accountDeviceInstance.getDeviceId())) {
82  return sleuthkitCase.getContentById(dataSource.getId()).getName();
83  }
84  }
85  } catch (TskCoreException ex) {
86  logger.log(Level.SEVERE, "Error getting datasource name, falling back on device ID.", ex);
87  }
88  return accountDeviceInstance.getDeviceId();
89  }
90 
94  static class AccountDeviceInstanceNode extends AbstractNode {
95 
96  private final AccountDeviceInstanceKey accountDeviceInstanceKey;
97  private final CommunicationsManager commsManager;
98  private final Account account;
99 
100  private AccountDeviceInstanceNode(AccountDeviceInstanceKey accountDeviceInstanceKey, CommunicationsManager commsManager) {
101  super(Children.LEAF, Lookups.fixed(accountDeviceInstanceKey, commsManager));
102  this.accountDeviceInstanceKey = accountDeviceInstanceKey;
103  this.commsManager = commsManager;
104  this.account = accountDeviceInstanceKey.getAccountDeviceInstance().getAccount();
105  setName(account.getTypeSpecificID());
106  setIconBaseWithExtension("org/sleuthkit/autopsy/communications/images/" + Utils.getIconFileName(account.getAccountType()));
107  }
108 
109  public AccountDeviceInstance getAccountDeviceInstance() {
110  return accountDeviceInstanceKey.getAccountDeviceInstance();
111  }
112 
113  public CommunicationsManager getCommsManager() {
114  return commsManager;
115  }
116 
117  public CommunicationsFilter getFilter() {
118  return accountDeviceInstanceKey.getCommunicationsFilter();
119  }
120 
121  @Override
122  @NbBundle.Messages(value = {"AccountNode.device=Device",
123  "AccountNode.accountName=Account",
124  "AccountNode.accountType=Type",
125  "AccountNode.messageCount=Msgs"})
126  protected Sheet createSheet() {
127  Sheet s = super.createSheet();
128  Sheet.Set properties = s.get(Sheet.PROPERTIES);
129  if (properties == null) {
130  properties = Sheet.createPropertiesSet();
131  s.put(properties);
132  }
133 
134  properties.put(new NodeProperty<>("type", Bundle.AccountNode_accountType(), "type",
135  account.getAccountType().getDisplayName())); // NON-NLS
136  properties.put(new NodeProperty<>("count", Bundle.AccountNode_messageCount(), "count",
137  accountDeviceInstanceKey.getMessageCount())); // NON-NLS
138  properties.put(new NodeProperty<>("device", Bundle.AccountNode_device(), "device",
139  accountDeviceInstanceKey.getDataSourceName())); // NON-NLS
140  return s;
141  }
142  }
143 }

Copyright © 2012-2016 Basis Technology. Generated on: Tue Feb 20 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.