19 package org.sleuthkit.autopsy.datamodel;
 
   21 import java.beans.PropertyChangeEvent;
 
   22 import java.beans.PropertyChangeListener;
 
   23 import java.lang.ref.WeakReference;
 
   24 import java.text.SimpleDateFormat;
 
   25 import java.util.ArrayList;
 
   26 import java.util.Arrays;
 
   27 import java.util.Collections;
 
   28 import java.util.EnumSet;
 
   29 import java.util.List;
 
   30 import java.util.Optional;
 
   31 import java.util.logging.Level;
 
   32 import java.util.stream.Collectors;
 
   33 import javax.swing.Action;
 
   34 import javax.swing.SwingUtilities;
 
   35 import org.apache.commons.lang3.StringUtils;
 
   36 import org.openide.nodes.ChildFactory;
 
   37 import org.openide.nodes.Children;
 
   38 import org.openide.nodes.Node;
 
   39 import org.openide.nodes.Sheet;
 
   40 import org.openide.util.Exceptions;
 
   41 import org.openide.util.NbBundle.Messages;
 
   42 import org.openide.util.WeakListeners;
 
   63     private static final String 
ICON_PATH = 
"org/sleuthkit/autopsy/images/os-account.png";
 
   64     private static final SimpleDateFormat 
DATE_FORMATTER = 
new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss z");
 
   66     private static final String 
LIST_NAME = Bundle.OsAccount_listNode_name();
 
   86         this.filteringDSObjId = objId;
 
   91         return visitor.
visit(
this);
 
   95         "OsAccount_listNode_name=OS Accounts" 
  108             setDisplayName(LIST_NAME);
 
  109             setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/os-account.png");
 
  114             return visitor.
visit(
this);
 
  124             return getClass().getName();
 
  134         private final PropertyChangeListener 
listener = 
new PropertyChangeListener() {
 
  136             public void propertyChange(PropertyChangeEvent evt) {
 
  137                 String eventType = evt.getPropertyName();
 
  143                     if (evt.getNewValue() == null) {
 
  151         private final PropertyChangeListener 
weakPcl = WeakListeners.propertyChange(listener, null);
 
  168             if (skCase != null) {
 
  170                     if (filteringDSObjId == 0) {
 
  171                         list.addAll(skCase.getOsAccountManager().getOsAccounts());
 
  173                         Host host = skCase.getHostManager().getHostByDataSource(skCase.getDataSource(filteringDSObjId));
 
  174                         list.addAll(skCase.getOsAccountManager().getOsAccounts(host));
 
  176                 } 
catch (TskCoreException | TskDataException ex) {
 
  177                     logger.log(Level.SEVERE, 
"Unable to retrieve list of OsAccounts for case", ex);
 
  197         private final PropertyChangeListener listener = 
new PropertyChangeListener() {
 
  199             public void propertyChange(PropertyChangeEvent evt) {
 
  202                     for (OsAccount acct : updateEvent.getOsAccounts()) {
 
  203                         if (acct.getId() == account.getId()) {
 
  209                 } 
else if (evt.getPropertyName().equals(OS_ACCOUNT_DATA_AVAILABLE_EVENT)
 
  211                         && ((
AsynchOsAcctData) evt.getNewValue()).getOsAccountId() == account.getId()) {
 
  213                     List<NodeProperty<?>> propertiesToUpdate = 
new ArrayList<>();
 
  217                     List<String> realmNames = osAcctData.getOsAcctRealm().getRealmNames();
 
  218                     if (!realmNames.isEmpty()) {
 
  219                         String realmNamesStr = realmNames.stream()
 
  222                                 .sorted((a, b) -> a.compareToIgnoreCase(b))
 
  223                                 .collect(Collectors.joining(
", "));
 
  226                                 Bundle.OsAccounts_accountRealmNameProperty_name(),
 
  227                                 Bundle.OsAccounts_accountRealmNameProperty_displayName(),
 
  228                                 Bundle.OsAccounts_accountRealmNameProperty_desc(),
 
  232                     String scopeName = osAcctData.getOsAcctRealm().getScope().getName();
 
  233                     if (StringUtils.isNotBlank(scopeName)) {
 
  235                                 Bundle.OsAccounts_accountScopeNameProperty_name(),
 
  236                                 Bundle.OsAccounts_accountScopeNameProperty_displayName(),
 
  237                                 Bundle.OsAccounts_accountScopeNameProperty_desc(),
 
  241                     List<Host> hosts = osAcctData.getHosts();
 
  242                     if (!hosts.isEmpty()) {
 
  243                         String hostsString = hosts.stream()
 
  244                                 .map(h -> h.getName().trim())
 
  246                                 .sorted((a, b) -> a.compareToIgnoreCase(b))
 
  247                                 .collect(Collectors.joining(
", "));
 
  250                                 Bundle.OsAccounts_accountHostNameProperty_name(),
 
  251                                 Bundle.OsAccounts_accountHostNameProperty_displayName(),
 
  252                                 Bundle.OsAccounts_accountHostNameProperty_desc(),
 
  256                     SwingUtilities.invokeLater(() -> 
 
  257                             updateSheet(propertiesToUpdate.toArray(
new NodeProperty<?>[propertiesToUpdate.size()])));
 
  262         private final PropertyChangeListener 
weakListener = WeakListeners.propertyChange(listener, null);
 
  274             setDisplayName(account.getName());
 
  275             setIconBaseWithExtension(ICON_PATH);
 
  282             return visitor.
visit(
this);
 
  292             return getClass().getName();
 
  300         OsAccount getOsAccount() {
 
  305             "OsAccounts_accountNameProperty_name=Name",
 
  306             "OsAccounts_accountNameProperty_displayName=Name",
 
  307             "OsAccounts_accountNameProperty_desc=Os Account name",
 
  308             "OsAccounts_accountRealmNameProperty_name=RealmName",
 
  309             "OsAccounts_accountRealmNameProperty_displayName=Realm Name",
 
  310             "OsAccounts_accountRealmNameProperty_desc=OS Account Realm Name",
 
  311             "OsAccounts_accountHostNameProperty_name=HostName",
 
  312             "OsAccounts_accountHostNameProperty_displayName=Host",
 
  313             "OsAccounts_accountHostNameProperty_desc=OS Account Host Name",
 
  314             "OsAccounts_accountScopeNameProperty_name=ScopeName",
 
  315             "OsAccounts_accountScopeNameProperty_displayName=Scope",
 
  316             "OsAccounts_accountScopeNameProperty_desc=OS Account Scope Name",
 
  317             "OsAccounts_createdTimeProperty_name=creationTime",
 
  318             "OsAccounts_createdTimeProperty_displayName=Creation Time",
 
  319             "OsAccounts_createdTimeProperty_desc=OS Account Creation Time",
 
  320             "OsAccounts_loginNameProperty_name=loginName",
 
  321             "OsAccounts_loginNameProperty_displayName=Login Name",
 
  322             "OsAccounts_loginNameProperty_desc=Os Account login name" 
  334             Sheet sheet = super.createSheet();
 
  335             Sheet.Set propertiesSet = sheet.get(Sheet.PROPERTIES);
 
  336             if (propertiesSet == null) {
 
  337                 propertiesSet = Sheet.createPropertiesSet();
 
  338                 sheet.put(propertiesSet);
 
  342                     Bundle.OsAccounts_accountNameProperty_name(),
 
  343                     Bundle.OsAccounts_accountNameProperty_displayName(),
 
  344                     Bundle.OsAccounts_accountNameProperty_desc(),
 
  345                     account.getName() != null ? account.getName() : 
""));
 
  347             Optional<String> optional = account.getLoginName();
 
  349                     Bundle.OsAccounts_loginNameProperty_name(),
 
  350                     Bundle.OsAccounts_loginNameProperty_displayName(),
 
  351                     Bundle.OsAccounts_loginNameProperty_desc(),
 
  352                     optional.isPresent() ? optional.get() : 
""));
 
  356                     Bundle.OsAccounts_accountHostNameProperty_name(),
 
  357                     Bundle.OsAccounts_accountHostNameProperty_displayName(),
 
  358                     Bundle.OsAccounts_accountHostNameProperty_desc(),
 
  362                     Bundle.OsAccounts_accountScopeNameProperty_name(),
 
  363                     Bundle.OsAccounts_accountScopeNameProperty_displayName(),
 
  364                     Bundle.OsAccounts_accountScopeNameProperty_desc(),
 
  368                     Bundle.OsAccounts_accountRealmNameProperty_name(),
 
  369                     Bundle.OsAccounts_accountRealmNameProperty_displayName(),
 
  370                     Bundle.OsAccounts_accountRealmNameProperty_desc(),
 
  373             Optional<Long> creationTimeValue = account.getCreationTime();
 
  374             String timeDisplayStr
 
  378                     Bundle.OsAccounts_createdTimeProperty_name(),
 
  379                     Bundle.OsAccounts_createdTimeProperty_displayName(),
 
  380                     Bundle.OsAccounts_createdTimeProperty_desc(),
 
  383             backgroundTasksPool.submit(
new GetOsAccountRealmTask(
new WeakReference<>(
this), weakListener));
 
  390             List<Action> actionsList = 
new ArrayList<>();
 
  391             actionsList.addAll(Arrays.asList(super.getActions(popup)));
 
  394             return actionsList.toArray(
new Action[actionsList.size()]);
 
  399             throw new UnsupportedOperationException(
"Not supported yet."); 
 
  403         public <T> T accept(ContentNodeVisitor<T> visitor) {
 
  404             return visitor.visit(
this);
 
  410         static class GetOsAccountRealmTask 
implements Runnable {
 
  412             private final WeakReference<OsAccountNode> weakNodeRef;
 
  413             private final PropertyChangeListener 
listener;
 
  421             GetOsAccountRealmTask(WeakReference<OsAccountNode> weakContentRef, PropertyChangeListener listener) {
 
  422                 this.weakNodeRef = weakContentRef;
 
  428                 OsAccountNode node = weakNodeRef.get();
 
  434                     SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();
 
  435                     OsAccount osAcct = node.getOsAccount();
 
  436                     long realmId = osAcct.getRealmId();
 
  437                     OsAccountRealm realm = skCase.getOsAccountRealmManager().getRealmByRealmId(realmId);
 
  439                     List<Host> hosts = skCase.getOsAccountManager().getHosts(osAcct);
 
  441                     AsynchOsAcctData evtData = 
new AsynchOsAcctData(osAcct.getId(), realm, hosts);
 
  443                     if (listener != null && realm != null) {
 
  444                         listener.propertyChange(
new PropertyChangeEvent(
 
  445                                 AutopsyEvent.SourceType.LOCAL.toString(),
 
  450                 } 
catch (TskCoreException ex) {
 
  451                     Exceptions.printStackTrace(ex);
 
  473             AsynchOsAcctData(
long osAccountId, OsAccountRealm osAcctRealm, List<Host> hosts) {
 
  482             long getOsAccountId() {
 
  489             OsAccountRealm getOsAcctRealm() {
 
  496             List<Host> getHosts() {
 
static final String OS_ACCOUNT_DATA_AVAILABLE_EVENT
 
Action[] getActions(boolean popup)
 
List< Tag > getAllTagsFromDatabase()
 
void setName(String name)
 
Node createNodeForKey(OsAccount key)
 
static List< Action > getActions(File file, boolean isArtifactSource)
 
final PropertyChangeListener listener
 
OsAccounts(SleuthkitCase skCase, long objId)
 
static String getFormattedTime(long epochTime)
 
static final SimpleDateFormat DATE_FORMATTER
 
static final String LIST_NAME
 
final PropertyChangeListener weakListener
 
boolean createKeys(List< OsAccount > list)
 
static final Logger logger
 
final long filteringDSObjId
 
T visit(DataSourceFilesNode in)
 
final PropertyChangeListener listener
 
final PropertyChangeListener weakPcl
 
static final String ICON_PATH
 
static String getListName()
 
synchronized static Logger getLogger(String name)
 
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
 
final OsAccountRealm osAcctRealm
 
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
 
OsAccounts(SleuthkitCase skCase)