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;
49 import org.
sleuthkit.datamodel.OsAccount.OsAccountAttribute;
70 private static final SimpleDateFormat
DATE_FORMAT =
new SimpleDateFormat(
"MMM dd yyyy", US);
83 this.setLayout(
new GridBagLayout());
93 void setOsAccountId(Long osAccountId) {
97 if (osAccountId != null) {
98 setLayout(
new BorderLayout());
99 add(
new JLabel(
"Loading OsAccount Data..."), BorderLayout.NORTH);
101 if (dataFetcher != null && !dataFetcher.isDone()) {
102 dataFetcher.cancel(
true);
105 dataFetcher =
new PanelDataFetcher(osAccountId);
106 dataFetcher.execute();
110 void setOsAccount(OsAccount account) {
114 if (account != null) {
115 setLayout(
new BorderLayout());
116 add(
new JLabel(
"Loading OsAccount Data..."), BorderLayout.NORTH);
118 if (dataFetcher != null && !dataFetcher.isDone()) {
119 dataFetcher.cancel(
true);
122 dataFetcher =
new PanelDataFetcher(account);
123 dataFetcher.execute();
135 for (SectionData section : panelData) {
136 addTitle(section.getTitle(), rowCnt++);
138 for (RowData<String, String> rowData : section) {
139 String key = rowData.getKey();
140 String value = rowData.getValue();
149 GridBagConstraints constraints =
new GridBagConstraints();
150 constraints.gridx = 0;
151 constraints.gridy = rowCnt;
152 constraints.gridwidth = 2;
153 constraints.fill = GridBagConstraints.BOTH;
154 constraints.weightx = 1;
155 constraints.weighty = 1;
156 add(Box.createVerticalGlue(), constraints);
160 "OsAccountDataPanel_basic_title=Basic Properties",
161 "OsAccountDataPanel_basic_login=Login",
162 "OsAccountDataPanel_basic_fullname=Full Name",
163 "OsAccountDataPanel_basic_address=Address",
164 "OsAccountDataPanel_basic_admin=Administrator",
165 "OsAccountDataPanel_basic_type=Type",
166 "OsAccountDataPanel_basic_creationDate=Creation Date",})
176 SectionData data =
new SectionData(Bundle.OsAccountDataPanel_basic_title());
178 Optional<String> optional = account.getLoginName();
179 data.addData(Bundle.OsAccountDataPanel_basic_login(),
180 optional.isPresent() ? optional.get() :
"");
182 optional = account.getFullName();
183 data.addData(Bundle.OsAccountDataPanel_basic_fullname(),
184 optional.isPresent() ? optional.get() :
"");
186 data.addData(Bundle.OsAccountDataPanel_basic_address(),
187 account.getName() == null || account.getName().isEmpty() ?
"" : account.getName());
190 data.addData(Bundle.OsAccountDataPanel_basic_type(),
191 account.getOsAccountType().isPresent() ? account.getOsAccountType().get().getName() :
"");
193 Optional<Long> crTime = account.getCreationTime();
194 if (crTime.isPresent()) {
195 data.addData(Bundle.OsAccountDataPanel_basic_creationDate(), DATE_FORMAT.format(
new Date(crTime.get() * 1000)));
197 data.addData(Bundle.OsAccountDataPanel_basic_creationDate(),
"");
204 "OsAccountDataPanel_realm_title=Realm Properties",
205 "OsAccountDataPanel_realm_name=Name",
206 "OsAccountDataPanel_realm_address=Address",
207 "OsAccountDataPanel_realm_confidence=Confidence",
208 "OsAccountDataPanel_realm_unknown=Unknown",
209 "OsAccountDataPanel_realm_scope=Scope",})
219 SectionData data =
new SectionData(Bundle.OsAccountDataPanel_realm_title());
221 String realmName = realm.getRealmNames().isEmpty() ? Bundle.OsAccountDataPanel_realm_unknown() : realm.getRealmNames().get(0);
222 data.addData(Bundle.OsAccountDataPanel_realm_name(), realmName);
224 Optional<String> optional = realm.getRealmAddr();
225 data.addData(Bundle.OsAccountDataPanel_realm_address(),
226 optional.isPresent() ? optional.get() :
"");
228 data.addData(Bundle.OsAccountDataPanel_realm_scope(),
229 realm.getScope().getName());
231 data.addData(Bundle.OsAccountDataPanel_realm_confidence(),
232 realm.getScopeConfidence().getName());
239 "OsAccountDataPanel_host_section_title={0} Details",
240 "OsAccountDataPanel_host_count_title=Login Count",
241 "OsAccountDataPanel_data_accessed_title=Last Login",
242 "OsAccountDataPanel_administrator_title=Administrator"
244 private SectionData
buildHostData(Host host, List<OsAccountAttribute> attributeList) {
245 SectionData data =
new SectionData(Bundle.OsAccountDataPanel_host_section_title(host.getName()));
246 for (OsAccountAttribute attribute : attributeList) {
247 String displayName = attribute.getAttributeType().getDisplayName();
248 String value = attribute.getDisplayString();
250 if(attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COUNT.getTypeID()) {
251 displayName = Bundle.OsAccountDataPanel_host_count_title();
252 }
else if(attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_IS_ADMIN.getTypeID()) {
253 displayName = Bundle.OsAccountDataPanel_administrator_title();
254 if(attribute.getValueInt() == 0) {
259 }
else if(attribute.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED.getTypeID()) {
260 displayName = Bundle.OsAccountDataPanel_data_accessed_title();
263 data.addData(displayName, value);
276 JLabel label =
new JLabel(title);
289 JLabel label =
new JLabel(key +
":");
300 JLabel label =
new JLabel(value);
312 GridBagConstraints constraints =
new GridBagConstraints();
314 constraints.gridx = 0;
315 constraints.gridy = row;
316 constraints.gridwidth = 2;
317 constraints.gridheight = 1;
318 constraints.anchor = GridBagConstraints.NORTHWEST;
319 constraints.fill = GridBagConstraints.HORIZONTAL;
320 constraints.weightx = 1;
321 constraints.insets = (row == 0)
322 ? FIRST_HEADER_INSETS
336 GridBagConstraints constraints =
new GridBagConstraints();
339 constraints.gridy = row;
340 constraints.gridwidth = 1;
341 constraints.gridheight = 1;
342 constraints.anchor = GridBagConstraints.WEST;
356 GridBagConstraints constraints =
new GridBagConstraints();
359 constraints.gridy = row;
360 constraints.gridwidth = 1;
361 constraints.gridheight = 1;
362 constraints.fill = GridBagConstraints.HORIZONTAL;
364 constraints.weightx = 1;
389 this.accountId = null;
394 Map<Host, List<OsAccountAttribute>> hostMap =
new HashMap<>();
395 Map<Host, DataSource> instanceMap =
new HashMap<>();
397 OsAccountManager osAccountManager = skCase.getOsAccountManager();
399 if(account == null) {
400 account = osAccountManager.getOsAccountByObjectId(accountId);
403 OsAccountRealm realm = skCase.getOsAccountRealmManager().getRealmByRealmId(account.getRealmId());
405 List<Host> hosts = osAccountManager.getHosts(account);
406 List<OsAccountAttribute> attributeList = account.getExtendedOsAccountAttributes();
408 if (attributeList != null) {
411 Map<Long, List<OsAccountAttribute>> idMap =
new HashMap<>();
412 for (OsAccountAttribute attribute : attributeList) {
413 List<OsAccountAttribute> atList = null;
414 Optional<Long> optionalId = attribute.getHostId();
416 if (optionalId.isPresent()) {
417 key = optionalId.get();
420 atList = idMap.get(key);
422 if (atList == null) {
423 atList =
new ArrayList<>();
424 idMap.put(key, atList);
427 atList.add(attribute);
431 for (Host host : hosts) {
432 List<OsAccountAttribute> atList = idMap.get(host.getHostId());
433 if (atList != null) {
434 hostMap.put(host, atList);
438 List<OsAccountAttribute> atList = idMap.get(null);
439 if (atList != null) {
440 hostMap.put(null, atList);
445 for (OsAccountInstance instance : account.getOsAccountInstances()) {
446 instanceMap.put(instance.getDataSource().getHost(), instance.getDataSource());
450 hostMap.put(null, attributeList);
462 if (this.isCancelled()) {
467 }
catch (ExecutionException | InterruptedException ex) {
468 logger.log(Level.SEVERE, String.format(
"Failed to retrieve data for OsAccount (%d)", account.getId()), ex);
471 if (results != null) {
473 setLayout(
new GridBagLayout());
475 List<SectionData> data =
new ArrayList<>();
477 Map<Host, List<OsAccountAttribute>> hostDataMap = results.getAttributeMap();
478 if (hostDataMap != null && !hostDataMap.isEmpty()) {
479 hostDataMap.forEach((K, V) -> data.add(
buildHostData(K, V)));
482 OsAccountRealm realm = results.getRealm();
523 WorkerResults(Map<Host, List<OsAccountAttribute>> attributeMap, Map<Host, DataSource> instanceMap, OsAccountRealm realm) {
536 Map<Host, List<OsAccountAttribute>> getAttributeMap() {
545 Map<Host, DataSource> getDataSourceMap() {
549 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()
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)