19 package org.sleuthkit.autopsy.contentviewers.osaccount;
21 import java.awt.BorderLayout;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Insets;
26 import java.text.SimpleDateFormat;
27 import java.util.ArrayList;
28 import java.util.Date;
29 import java.util.HashMap;
30 import java.util.List;
31 import static java.util.Locale.US;
33 import java.util.Optional;
34 import java.util.concurrent.ExecutionException;
35 import java.util.logging.Level;
36 import java.util.logging.Logger;
37 import javax.swing.Box;
38 import javax.swing.JLabel;
39 import javax.swing.JPanel;
40 import javax.swing.SwingWorker;
41 import javax.swing.UIManager;
42 import javax.swing.border.EmptyBorder;
43 import org.openide.util.NbBundle.Messages;
54 import org.
sleuthkit.datamodel.OsAccount.OsAccountAttribute;
76 private static final SimpleDateFormat
DATE_FORMAT =
new SimpleDateFormat(
"MMM dd yyyy", US);
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);
107 if (dataFetcher != null && !dataFetcher.isDone()) {
108 dataFetcher.cancel(
true);
111 dataFetcher =
new PanelDataFetcher(osAccountId);
112 dataFetcher.execute();
116 void setOsAccount(OsAccount account) {
120 if (account != null) {
121 setLayout(
new BorderLayout());
122 add(
new JLabel(
"Loading OsAccount Data..."), BorderLayout.NORTH);
124 if (dataFetcher != null && !dataFetcher.isDone()) {
125 dataFetcher.cancel(
true);
128 dataFetcher =
new PanelDataFetcher(account);
129 dataFetcher.execute();
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)
379 ? FIRST_HEADER_INSETS
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;
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();
471 if (account == null) {
472 account = osAccountManager.getOsAccountByObjectId(accountId);
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();
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() {
void addPropertyName(String key, int row)
static final long serialVersionUID
final Map< Host, DataSource > instanceMap
GridBagConstraints getSubtitleContraints(int row)
GridBagConstraints getPropertyValueContraints(int row)
PanelDataFetcher dataFetcher
static Integer getLineSpacing()
Section buildBasicProperties(OsAccount account)
WorkerResults doInBackground()
static String getFormattedTime(long epochTime)
final OsAccountRealm realm
final Map< Host, Map< DataSource, List< OsAccountAttribute > > > attributeMap
static Insets getPanelInsets()
void addTitle(String title, int row)
GridBagConstraints getPropertyNameContraints(int row)
static final int VALUE_COLUMN
static Integer getSectionIndent()
static final Insets SUBHEADER_COLUMN_INSETS
final static Logger logger
void addLabel(String text, int row)
static final Insets VALUE_COLUMN_INSETS
static final Insets KEY_COLUMN_INSETS
static Font getHeaderFont()
void addPropertyValue(String value, int row)
static final int KEY_COLUMN
void addSubTitle(String title, int row)
SleuthkitCase getSleuthkitCase()
GridBagConstraints getTitleContraints(int row)
Section buildHostData(Host host, Map< DataSource, List< OsAccountAttribute >> attributeDataSourceMap)
static int getColumnSpacing()
static final Insets HEADER_INSETS
static Integer getSectionSpacing()
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
static final SimpleDateFormat DATE_FORMAT
Section buildRealmProperties(OsAccountRealm realm)
static final Insets FIRST_HEADER_INSETS
void addDataComponents(List< Section > panelData)