19 package org.sleuthkit.autopsy.contentviewers.osaccount;
21 import java.awt.BorderLayout;
22 import java.awt.GridBagConstraints;
23 import java.awt.GridBagLayout;
24 import java.awt.Insets;
25 import java.text.SimpleDateFormat;
26 import java.util.ArrayList;
27 import java.util.Date;
28 import java.util.HashMap;
29 import java.util.List;
30 import static java.util.Locale.US;
32 import java.util.Optional;
33 import java.util.concurrent.ExecutionException;
34 import java.util.logging.Level;
35 import java.util.logging.Logger;
36 import javax.swing.Box;
37 import javax.swing.JLabel;
38 import javax.swing.JPanel;
39 import javax.swing.SwingWorker;
40 import javax.swing.border.EmptyBorder;
41 import org.openide.util.NbBundle.Messages;
50 import org.
sleuthkit.datamodel.OsAccount.OsAccountAttribute;
71 private static final SimpleDateFormat
DATE_FORMAT =
new SimpleDateFormat(
"MMM dd yyyy", US);
84 this.setLayout(
new GridBagLayout());
94 void setOsAccountId(Long osAccountId) {
98 if (osAccountId != null) {
99 setLayout(
new BorderLayout());
100 add(
new JLabel(
"Loading OsAccount Data..."), BorderLayout.NORTH);
102 if (dataFetcher != null && !dataFetcher.isDone()) {
103 dataFetcher.cancel(
true);
106 dataFetcher =
new PanelDataFetcher(osAccountId);
107 dataFetcher.execute();
111 void setOsAccount(OsAccount account) {
115 if (account != null) {
116 setLayout(
new BorderLayout());
117 add(
new JLabel(
"Loading OsAccount Data..."), BorderLayout.NORTH);
119 if (dataFetcher != null && !dataFetcher.isDone()) {
120 dataFetcher.cancel(
true);
123 dataFetcher =
new PanelDataFetcher(account);
124 dataFetcher.execute();
136 for (SectionData section : panelData) {
137 addTitle(section.getTitle(), rowCnt++);
139 for (RowData<String, String> rowData : section) {
140 String key = rowData.getKey();
141 String value = rowData.getValue();
150 GridBagConstraints constraints =
new GridBagConstraints();
151 constraints.gridx = 0;
152 constraints.gridy = rowCnt;
153 constraints.gridwidth = 2;
154 constraints.fill = GridBagConstraints.BOTH;
155 constraints.weightx = 1;
156 constraints.weighty = 1;
157 add(Box.createVerticalGlue(), constraints);
161 "OsAccountDataPanel_basic_title=Basic Properties",
162 "OsAccountDataPanel_basic_login=Login",
163 "OsAccountDataPanel_basic_fullname=Full Name",
164 "OsAccountDataPanel_basic_address=Address",
165 "OsAccountDataPanel_basic_admin=Administrator",
166 "OsAccountDataPanel_basic_type=Type",
167 "OsAccountDataPanel_basic_creationDate=Creation Date",})
177 SectionData data =
new SectionData(Bundle.OsAccountDataPanel_basic_title());
179 Optional<String> optional = account.getLoginName();
180 data.addData(Bundle.OsAccountDataPanel_basic_login(),
181 optional.isPresent() ? optional.get() :
"");
183 optional = account.getFullName();
184 data.addData(Bundle.OsAccountDataPanel_basic_fullname(),
185 optional.isPresent() ? optional.get() :
"");
187 data.addData(Bundle.OsAccountDataPanel_basic_address(),
188 account.getName() == null || account.getName().isEmpty() ?
"" : account.getName());
191 data.addData(Bundle.OsAccountDataPanel_basic_type(),
192 account.getOsAccountType().isPresent() ? account.getOsAccountType().get().getName() :
"");
194 Optional<Long> crTime = account.getCreationTime();
201 "OsAccountDataPanel_realm_title=Realm Properties",
202 "OsAccountDataPanel_realm_name=Name",
203 "OsAccountDataPanel_realm_address=Address",
204 "OsAccountDataPanel_realm_confidence=Confidence",
205 "OsAccountDataPanel_realm_unknown=Unknown",
206 "OsAccountDataPanel_realm_scope=Scope",})
216 SectionData data =
new SectionData(Bundle.OsAccountDataPanel_realm_title());
218 String realmName = realm.getRealmNames().isEmpty() ? Bundle.OsAccountDataPanel_realm_unknown() : realm.getRealmNames().get(0);
219 data.addData(Bundle.OsAccountDataPanel_realm_name(), realmName);
221 Optional<String> optional = realm.getRealmAddr();
222 data.addData(Bundle.OsAccountDataPanel_realm_address(),
223 optional.isPresent() ? optional.get() :
"");
225 data.addData(Bundle.OsAccountDataPanel_realm_scope(),
226 realm.getScope().getName());
228 data.addData(Bundle.OsAccountDataPanel_realm_confidence(),
229 realm.getScopeConfidence().getName());
236 "OsAccountDataPanel_host_section_title={0} Details",
237 "OsAccountDataPanel_host_count_title=Login Count",
238 "OsAccountDataPanel_data_accessed_title=Last Login",
239 "OsAccountDataPanel_administrator_title=Administrator"
241 private SectionData
buildHostData(Host host, List<OsAccountAttribute> attributeList) {
242 SectionData data =
new SectionData(Bundle.OsAccountDataPanel_host_section_title(host.getName()));
243 for (OsAccountAttribute attribute : attributeList) {
244 String displayName = attribute.getAttributeType().getDisplayName();
245 String value = attribute.getDisplayString();
247 if(attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COUNT.getTypeID()) {
248 displayName = Bundle.OsAccountDataPanel_host_count_title();
249 }
else if(attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_IS_ADMIN.getTypeID()) {
250 displayName = Bundle.OsAccountDataPanel_administrator_title();
251 if(attribute.getValueInt() == 0) {
256 }
else if(attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID()) {
257 displayName = Bundle.OsAccountDataPanel_data_accessed_title();
260 data.addData(displayName, value);
273 JLabel label =
new JLabel(title);
286 JLabel label =
new JLabel(key +
":");
297 JLabel label =
new JLabel(value);
309 GridBagConstraints constraints =
new GridBagConstraints();
311 constraints.gridx = 0;
312 constraints.gridy = row;
313 constraints.gridwidth = 2;
314 constraints.gridheight = 1;
315 constraints.anchor = GridBagConstraints.NORTHWEST;
316 constraints.fill = GridBagConstraints.HORIZONTAL;
317 constraints.weightx = 1;
318 constraints.insets = (row == 0)
319 ? FIRST_HEADER_INSETS
333 GridBagConstraints constraints =
new GridBagConstraints();
336 constraints.gridy = row;
337 constraints.gridwidth = 1;
338 constraints.gridheight = 1;
339 constraints.anchor = GridBagConstraints.WEST;
353 GridBagConstraints constraints =
new GridBagConstraints();
356 constraints.gridy = row;
357 constraints.gridwidth = 1;
358 constraints.gridheight = 1;
359 constraints.fill = GridBagConstraints.HORIZONTAL;
361 constraints.weightx = 1;
386 this.accountId = null;
391 Map<Host, List<OsAccountAttribute>> hostMap =
new HashMap<>();
392 Map<Host, DataSource> instanceMap =
new HashMap<>();
394 OsAccountManager osAccountManager = skCase.getOsAccountManager();
396 if(account == null) {
397 account = osAccountManager.getOsAccountByObjectId(accountId);
400 OsAccountRealm realm = skCase.getOsAccountRealmManager().getRealmByRealmId(account.getRealmId());
402 List<Host> hosts = osAccountManager.getHosts(account);
403 List<OsAccountAttribute> attributeList = account.getExtendedOsAccountAttributes();
405 if (attributeList != null) {
408 Map<Long, List<OsAccountAttribute>> idMap =
new HashMap<>();
409 for (OsAccountAttribute attribute : attributeList) {
410 List<OsAccountAttribute> atList = null;
411 Optional<Long> optionalId = attribute.getHostId();
413 if (optionalId.isPresent()) {
414 key = optionalId.get();
417 atList = idMap.get(key);
419 if (atList == null) {
420 atList =
new ArrayList<>();
421 idMap.put(key, atList);
424 atList.add(attribute);
428 for (Host host : hosts) {
429 List<OsAccountAttribute> atList = idMap.get(host.getHostId());
430 if (atList != null) {
431 hostMap.put(host, atList);
435 List<OsAccountAttribute> atList = idMap.get(null);
436 if (atList != null) {
437 hostMap.put(null, atList);
442 for (OsAccountInstance instance : account.getOsAccountInstances()) {
443 instanceMap.put(instance.getDataSource().getHost(), instance.getDataSource());
447 hostMap.put(null, attributeList);
459 if (this.isCancelled()) {
464 }
catch (ExecutionException | InterruptedException ex) {
465 logger.log(Level.SEVERE, String.format(
"Failed to retrieve data for OsAccount (%d)", account.getId()), ex);
468 if (results != null) {
470 setLayout(
new GridBagLayout());
472 List<SectionData> data =
new ArrayList<>();
474 Map<Host, List<OsAccountAttribute>> hostDataMap = results.getAttributeMap();
475 if (hostDataMap != null && !hostDataMap.isEmpty()) {
476 hostDataMap.forEach((K, V) -> data.add(
buildHostData(K, V)));
479 OsAccountRealm realm = results.getRealm();
520 WorkerResults(Map<Host, List<OsAccountAttribute>> attributeMap, Map<Host, DataSource> instanceMap, OsAccountRealm realm) {
533 Map<Host, List<OsAccountAttribute>> getAttributeMap() {
542 Map<Host, DataSource> getDataSourceMap() {
546 OsAccountRealm getRealm() {
void addPropertyName(String key, int row)
static final long serialVersionUID
final Map< Host, DataSource > instanceMap
GridBagConstraints getPropertyValueContraints(int row)
PanelDataFetcher dataFetcher
static Integer getLineSpacing()
SectionData buildRealmProperties(OsAccountRealm realm)
SectionData buildBasicProperties(OsAccount account)
WorkerResults doInBackground()
static String getFormattedTime(long epochTime)
final OsAccountRealm realm
static Insets getPanelInsets()
void addTitle(String title, int row)
GridBagConstraints getPropertyNameContraints(int row)
static final int VALUE_COLUMN
static Integer getSectionIndent()
final static Logger logger
static final Insets VALUE_COLUMN_INSETS
SectionData buildHostData(Host host, List< OsAccountAttribute > attributeList)
static final Insets KEY_COLUMN_INSETS
static Font getHeaderFont()
void addPropertyValue(String value, int row)
static final int KEY_COLUMN
SleuthkitCase getSleuthkitCase()
GridBagConstraints getTitleContraints(int row)
static int getColumnSpacing()
static final Insets HEADER_INSETS
static Integer getSectionSpacing()
static Case getCurrentCase()
final Map< Host, List< OsAccountAttribute > > attributeMap
synchronized static Logger getLogger(String name)
static final SimpleDateFormat DATE_FORMAT
static final Insets FIRST_HEADER_INSETS
void addDataComponents(List< SectionData > panelData)