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 javax.swing.Action;
 
   33 import org.apache.commons.lang3.tuple.Pair;
 
   34 import org.openide.nodes.ChildFactory;
 
   35 import org.openide.nodes.Children;
 
   36 import org.openide.nodes.Node;
 
   37 import org.openide.nodes.Sheet;
 
   38 import org.openide.util.Exceptions;
 
   39 import org.openide.util.NbBundle.Messages;
 
   40 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");
 
   76         this.filteringDSObjId = objId;
 
   81         return visitor.
visit(
this);
 
   85         "OsAccount_listNode_name=OS Accounts" 
   97             setName(Bundle.OsAccount_listNode_name());
 
   98             setDisplayName(Bundle.OsAccount_listNode_name());
 
   99             setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/os-account.png");
 
  104             return visitor.
visit(
this);
 
  114             return getClass().getName();
 
  124         private final PropertyChangeListener 
listener = 
new PropertyChangeListener() {
 
  126             public void propertyChange(PropertyChangeEvent evt) {
 
  127                 String eventType = evt.getPropertyName();
 
  133                     if (evt.getNewValue() == null) {
 
  141         private final PropertyChangeListener 
weakPcl = WeakListeners.propertyChange(listener, null);
 
  158             if (skCase != null) {
 
  160                     if (filteringDSObjId == 0) {
 
  161                         list.addAll(skCase.getOsAccountManager().getOsAccounts());
 
  163                         Host host = skCase.getHostManager().getHostByDataSource(skCase.getDataSource(filteringDSObjId));
 
  164                         list.addAll(skCase.getOsAccountManager().getOsAccounts(host));
 
  166                 } 
catch (TskCoreException | TskDataException ex) {
 
  167                     logger.log(Level.SEVERE, 
"Unable to retrieve list of OsAccounts for case", ex);
 
  187         private final PropertyChangeListener listener = 
new PropertyChangeListener() {
 
  189             public void propertyChange(PropertyChangeEvent evt) {
 
  192                     for (OsAccount acct : updateEvent.getOsAccounts()) {
 
  193                         if (acct.getId() == account.getId()) {
 
  199                 } 
else if (evt.getPropertyName().equals(REALM_DATA_AVAILABLE_EVENT)) {
 
  200                     OsAccountRealm realm = (OsAccountRealm) evt.getNewValue();
 
  204                     List<String> realmNames = realm.getRealmNames();
 
  205                     if (!realmNames.isEmpty()) {
 
  207                                 Bundle.OsAccounts_accountRealmNameProperty_name(),
 
  208                                 Bundle.OsAccounts_accountRealmNameProperty_displayName(),
 
  209                                 Bundle.OsAccounts_accountRealmNameProperty_desc(),
 
  216         private final PropertyChangeListener 
weakListener = WeakListeners.propertyChange(listener, null);
 
  228             setDisplayName(account.getName());
 
  229             setIconBaseWithExtension(ICON_PATH);
 
  236             return visitor.
visit(
this);
 
  246             return getClass().getName();
 
  254         OsAccount getOsAccount() {
 
  259             "OsAccounts_accountNameProperty_name=Name",
 
  260             "OsAccounts_accountNameProperty_displayName=Name",
 
  261             "OsAccounts_accountNameProperty_desc=Os Account name",
 
  262             "OsAccounts_accountRealmNameProperty_name=RealmName",
 
  263             "OsAccounts_accountRealmNameProperty_displayName=Realm Name",
 
  264             "OsAccounts_accountRealmNameProperty_desc=OS Account Realm Name",
 
  265             "OsAccounts_createdTimeProperty_name=creationTime",
 
  266             "OsAccounts_createdTimeProperty_displayName=Creation Time",
 
  267             "OsAccounts_createdTimeProperty_desc=OS Account Creation Time",
 
  268             "OsAccounts_loginNameProperty_name=loginName",
 
  269             "OsAccounts_loginNameProperty_displayName=Login Name",
 
  270             "OsAccounts_loginNameProperty_desc=Os Account login name" 
  282             Sheet sheet = super.createSheet();
 
  283             Sheet.Set propertiesSet = sheet.get(Sheet.PROPERTIES);
 
  284             if (propertiesSet == null) {
 
  285                 propertiesSet = Sheet.createPropertiesSet();
 
  286                 sheet.put(propertiesSet);
 
  290                     Bundle.OsAccounts_accountNameProperty_name(),
 
  291                     Bundle.OsAccounts_accountNameProperty_displayName(),
 
  292                     Bundle.OsAccounts_accountNameProperty_desc(),
 
  293                     account.getName() != null ? account.getName() : 
""));
 
  295             Optional<String> optional = account.getLoginName();
 
  297                     Bundle.OsAccounts_loginNameProperty_name(),
 
  298                     Bundle.OsAccounts_loginNameProperty_displayName(),
 
  299                     Bundle.OsAccounts_loginNameProperty_desc(),
 
  300                     optional.isPresent() ? optional.get() : 
""));
 
  302             String realmName = 
"";
 
  304                     Bundle.OsAccounts_accountRealmNameProperty_name(),
 
  305                     Bundle.OsAccounts_accountRealmNameProperty_displayName(),
 
  306                     Bundle.OsAccounts_accountRealmNameProperty_desc(),
 
  309             Optional<Long> creationTimeValue = account.getCreationTime();
 
  310             String timeDisplayStr
 
  314                     Bundle.OsAccounts_createdTimeProperty_name(),
 
  315                     Bundle.OsAccounts_createdTimeProperty_displayName(),
 
  316                     Bundle.OsAccounts_createdTimeProperty_desc(),
 
  319             backgroundTasksPool.submit(
new GetOsAccountRealmTask(
new WeakReference<>(
this), weakListener));
 
  326             List<Action> actionsList = 
new ArrayList<>();
 
  327             actionsList.addAll(Arrays.asList(super.getActions(popup)));
 
  330             return actionsList.toArray(
new Action[actionsList.size()]);
 
  335             throw new UnsupportedOperationException(
"Not supported yet."); 
 
  354         public <T> T accept(ContentNodeVisitor<T> visitor) {
 
  355             return visitor.visit(
this);
 
  361         static class GetOsAccountRealmTask 
implements Runnable {
 
  363             private final WeakReference<OsAccountNode> weakNodeRef;
 
  364             private final PropertyChangeListener 
listener;
 
  372             GetOsAccountRealmTask(WeakReference<OsAccountNode> weakContentRef, PropertyChangeListener listener) {
 
  373                 this.weakNodeRef = weakContentRef;
 
  379                 OsAccountNode node = weakNodeRef.get();
 
  385                     long realmId = node.getOsAccount().getRealmId();
 
  386                     OsAccountRealm realm = Case.getCurrentCase().getSleuthkitCase().getOsAccountRealmManager().getRealmByRealmId(realmId);
 
  388                     if (listener != null && realm != null) {
 
  389                         listener.propertyChange(
new PropertyChangeEvent(
 
  390                                 AutopsyEvent.SourceType.LOCAL.toString(),
 
  395                 } 
catch (TskCoreException ex) {
 
  396                     Exceptions.printStackTrace(ex);
 
Pair< Long, String > getCountPropertyAndDescription(CorrelationAttributeInstance.Type attributeType, String attributeValue, String defaultDescription)
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
DataResultViewerTable.HasCommentStatus getCommentProperty(List< Tag > tags, CorrelationAttributeInstance attribute)
final PropertyChangeListener weakListener
boolean createKeys(List< OsAccount > list)
CorrelationAttributeInstance getCorrelationAttributeInstance()
static final Logger logger
static final String REALM_DATA_AVAILABLE_EVENT
final long filteringDSObjId
T visit(DataSourceFilesNode in)
final PropertyChangeListener listener
final PropertyChangeListener weakPcl
static final String ICON_PATH
synchronized static Logger getLogger(String name)
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
OsAccounts(SleuthkitCase skCase)