19 package org.sleuthkit.autopsy.recentactivity;
21 import java.nio.file.Path;
22 import java.nio.file.Paths;
23 import java.util.HashMap;
24 import java.util.List;
26 import java.util.Optional;
32 import org.
sleuthkit.datamodel.OsAccount.OsAccountAttribute;
41 final class RAOsAccountCache {
43 private final Map<String, OsAccount> accountCache =
new HashMap<>();
54 void initialize(SleuthkitCase tskCase, Host host)
throws TskCoreException {
55 buildAccountMap(tskCase, host);
74 Optional<OsAccount> getOsAccount(AbstractFile file)
throws TskCoreException {
75 Optional<Long> optional = file.getOsAccountObjectId();
77 if (!optional.isPresent()) {
78 return getAccountForPath(file.getParentPath());
81 OsAccount osAccount = Case.getCurrentCase().getSleuthkitCase().getOsAccountManager().getOsAccountByObjectId(optional.get());
82 if (osAccount.getName().equals(
"S-1-5-32-544")) {
83 return getAccountForPath(file.getParentPath());
86 return Optional.ofNullable(osAccount);
97 private Optional<OsAccount> getAccountForPath(String path) {
98 Path filePath = Paths.get(path.toLowerCase());
100 if (filePath.startsWith(Paths.get(
"/users")) || filePath.startsWith(
"/document and settings")) {
101 for (String key : accountCache.keySet()) {
102 if (filePath.startsWith(Paths.get(key))) {
103 return Optional.of(accountCache.get(key));
107 return Optional.empty();
115 private void buildAccountMap(SleuthkitCase tskCase, Host host)
throws TskCoreException {
116 BlackboardAttribute.Type homeDir =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_HOME_DIR);
117 List<OsAccount> accounts = tskCase.getOsAccountManager().getOsAccounts(host);
119 for (OsAccount account : accounts) {
120 List<OsAccountAttribute> attributeList = account.getExtendedOsAccountAttributes();
122 for (OsAccountAttribute attribute : attributeList) {
123 if (attribute.getHostId().isPresent()
124 && attribute.getHostId().get().equals(host.getHostId())
125 && attribute.getAttributeType().equals(homeDir)) {
126 accountCache.put(attribute.getValueString(), account);