From ee85de968fd11eb2374ac15b1a82bb0309c304e4 Mon Sep 17 00:00:00 2001 From: apriestman Date: Thu, 18 Mar 2021 15:06:54 -0400 Subject: [PATCH] Handle OS account removed event --- .../sleuthkit/autopsy/casemodule/Case.java | 18 +++++++++- .../events/OsAccountRemovedEvent.java | 34 +++++++++++++++++++ .../autopsy/datamodel/OsAccounts.java | 5 +-- 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountRemovedEvent.java diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index ffd226d6d3..38f6bb0832 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -87,6 +87,7 @@ import org.sleuthkit.autopsy.casemodule.events.HostsChangedEvent; import org.sleuthkit.autopsy.casemodule.events.HostsRemovedEvent; import org.sleuthkit.autopsy.casemodule.events.OsAccountAddedEvent; import org.sleuthkit.autopsy.casemodule.events.OsAccountChangedEvent; +import org.sleuthkit.autopsy.casemodule.events.OsAccountRemovedEvent; import org.sleuthkit.autopsy.casemodule.events.PersonsAddedEvent; import org.sleuthkit.autopsy.casemodule.events.PersonsChangedEvent; import org.sleuthkit.autopsy.casemodule.events.PersonsRemovedEvent; @@ -143,8 +144,8 @@ import org.sleuthkit.datamodel.HostManager.HostsUpdateEvent; import org.sleuthkit.datamodel.HostManager.HostsDeletionEvent; import org.sleuthkit.datamodel.Image; import org.sleuthkit.datamodel.OsAccount; -import org.sleuthkit.datamodel.OsAccountManager; import org.sleuthkit.datamodel.OsAccountManager.OsAccountsCreationEvent; +import org.sleuthkit.datamodel.OsAccountManager.OsAccountsDeleteEvent; import org.sleuthkit.datamodel.OsAccountManager.OsAccountsUpdateEvent; import org.sleuthkit.datamodel.Person; import org.sleuthkit.datamodel.PersonManager.PersonsCreationEvent; @@ -442,6 +443,10 @@ public class Case { * Call getOsAccount to get the changed account; */ OS_ACCOUNT_CHANGED, + /** + * OSAccount associated with the current case has been deleted. + */ + OS_ACCOUNT_REMOVED, /** * Hosts associated with the current case added. @@ -520,6 +525,13 @@ public class Case { } } + @Subscribe + public void publishOsAccountDeletedEvent(OsAccountsDeleteEvent event) { + for(OsAccount account: event.getOsAcounts()) { + eventPublisher.publish(new OsAccountRemovedEvent(account)); + } + } + /** * Publishes an autopsy event from the sleuthkit HostCreationEvent * indicating that hosts have been created. @@ -1798,6 +1810,10 @@ public class Case { eventPublisher.publish(new OsAccountChangedEvent(account)); } + public void notifyOsAccountRemoved(OsAccount account) { + eventPublisher.publish(new OsAccountRemovedEvent(account)); + } + /** * Notify via an autopsy event that a host has been added. * @param host The host that has been added. diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountRemovedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountRemovedEvent.java new file mode 100644 index 0000000000..2dfcc1db79 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountRemovedEvent.java @@ -0,0 +1,34 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2021 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.casemodule.events; + +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.OsAccount; + +/** + * Event published when an OsAccount is deleted. + */ +public final class OsAccountRemovedEvent extends OsAccountEvent { + + private static final long serialVersionUID = 1L; + + public OsAccountRemovedEvent(OsAccount account) { + super(Case.Events.OS_ACCOUNT_REMOVED.toString(), account); + } +} diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java b/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java index df0d1968aa..94f15589a0 100755 --- a/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java @@ -114,7 +114,8 @@ public final class OsAccounts implements AutopsyVisitableItem { @Override public void propertyChange(PropertyChangeEvent evt) { String eventType = evt.getPropertyName(); - if(eventType.equals(Case.Events.OS_ACCOUNT_ADDED.toString())) { + if(eventType.equals(Case.Events.OS_ACCOUNT_ADDED.toString()) + || eventType.equals(Case.Events.OS_ACCOUNT_REMOVED.toString())) { refresh(true); } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) { // case was closed. Remove listeners so that we don't get called with a stale case handle @@ -128,7 +129,7 @@ public final class OsAccounts implements AutopsyVisitableItem { @Override protected void addNotify() { - Case.addEventTypeSubscriber(Collections.singleton(Case.Events.OS_ACCOUNT_ADDED), listener); + Case.addEventTypeSubscriber(EnumSet.of(Case.Events.OS_ACCOUNT_ADDED, Case.Events.OS_ACCOUNT_REMOVED), listener); Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), listener); }