From 34c72cdc3469adfcad1a19defc7d18a322548d09 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 29 Apr 2021 10:17:34 -0400 Subject: [PATCH] 7553 data model event changes --- .../casemodule/events/HostsDeletedEvent.java | 51 ++++++ .../casemodule/events/HostsUpdatedEvent.java | 41 +++++ .../events/OsAccountsAddedEvent.java | 40 +++++ .../events/OsAccountsDeletedEvent.java | 49 ++++++ .../casemodule/events/OsAccountsEvent.java | 64 +++++++ .../events/OsAccountsUpdatedEvent.java | 41 +++++ .../events/PersonsUpdatedEvent.java | 41 +++++ .../events/TskDataModelChangedEvent.java | 165 ++++++++++++++++++ 8 files changed, 492 insertions(+) create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/HostsDeletedEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/HostsUpdatedEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsAddedEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsDeletedEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsUpdatedEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsDeletedEvent.java new file mode 100755 index 0000000000..3d62b78405 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsDeletedEvent.java @@ -0,0 +1,51 @@ +/* + * 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 java.util.Collections; +import java.util.List; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.Host; +import org.sleuthkit.datamodel.SleuthkitCase; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * Event fired when hosts are deleted. + */ +public class HostsDeletedEvent extends TskDataModelChangedEvent { + + private static final long serialVersionUID = 1L; + + /** + * Main constructor. + * + * @param dataModelObjectIds The unique numeric IDs (TSK object IDs, case + * database row IDs, etc.) of the Hosts that have + * been deleted. + */ + public HostsDeletedEvent(List dataModelObjectIds) { + super(Case.Events.HOSTS_DELETED.name(), dataModelObjectIds); + } + + @Override + protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + return Collections.emptyList(); + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsUpdatedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsUpdatedEvent.java new file mode 100755 index 0000000000..6b06382c0a --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsUpdatedEvent.java @@ -0,0 +1,41 @@ +/* + * 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 java.util.List; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.Host; + +/** + * Event fired when hosts are changed. + */ +public class HostsUpdatedEvent extends HostsEvent { + + private static final long serialVersionUID = 1L; + + /** + * Main constructor. + * + * @param dataModelObjects The new values for the hosts that have been + * changed. + */ + public HostsUpdatedEvent(List dataModelObjects) { + super(Case.Events.HOSTS_CHANGED.name(), dataModelObjects); + } +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsAddedEvent.java new file mode 100755 index 0000000000..49a722062b --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsAddedEvent.java @@ -0,0 +1,40 @@ +/* + * 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 java.util.List; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.OsAccount; + +/** + * Event published when OS accounts are added to a case. + */ +public final class OsAccountsAddedEvent extends OsAccountsEvent { + + private static final long serialVersionUID = 1L; + + /** + * Constructs an event published when OS accounts are added to a case. + * @param accounts + */ + public OsAccountsAddedEvent(List accounts) { + super(Case.Events.OS_ACCOUNT_ADDED.toString(), accounts); + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsDeletedEvent.java new file mode 100755 index 0000000000..52fe8d49a8 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsDeletedEvent.java @@ -0,0 +1,49 @@ +/* + * 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 java.util.Collections; +import java.util.List; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.OsAccount; +import org.sleuthkit.datamodel.SleuthkitCase; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * An event published when OS accounts are deleted from a case. + */ +public final class OsAccountsDeletedEvent extends TskDataModelChangedEvent { + + private static final long serialVersionUID = 1L; + + /** + * Constructs an event published when OS accounts are deleted from a case. + * + * @param osAccountObjectIds The object IDs of the deleted accounts. + */ + public OsAccountsDeletedEvent(List osAccountObjectIds) { + super(Case.Events.OS_ACCOUNT_REMOVED.toString(), osAccountObjectIds); + } + + @Override + protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + return Collections.emptyList(); + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsEvent.java new file mode 100755 index 0000000000..af214776a8 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsEvent.java @@ -0,0 +1,64 @@ +/* + * 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 java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.sleuthkit.datamodel.OsAccount; +import org.sleuthkit.datamodel.SleuthkitCase; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * Parent class for specific OsAccount event classes. + */ +class OsAccountsEvent extends TskDataModelChangedEvent { + + private static final long serialVersionUID = 1L; + + /** + * Construct a new OsAccountEvent. + * + * @param eventName The name of the event. + * @param account The OsAccount the event applies to. + */ + OsAccountsEvent(String eventName, List accounts) { + super(eventName, accounts, OsAccount::getId); + } + + /** + * Returns the OsAccount that changed. + * + * @return The OsAccount that was changed. + */ + public OsAccount getOsAccount() { + List accounts = getNewValue(); + return accounts.get(0); + } + + @Override + protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + Long id = ids.get(0); + OsAccount account = caseDb.getOsAccountManager().getOsAccountByObjectId(id); + List accounts = new ArrayList<>(); + accounts.add(account); + return accounts; + } +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java new file mode 100755 index 0000000000..22ef19584b --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java @@ -0,0 +1,41 @@ +/* + * 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 java.util.List; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.OsAccount; + +/** + * Event published when OS accounts in the case have been updated. + */ +public final class OsAccountsUpdatedEvent extends OsAccountsEvent { + + private static final long serialVersionUID = 1L; + + /** + * Constructs an event published when OS accounts in the case have been + * updated. + * + * @param accounts The accounts. + */ + public OsAccountsUpdatedEvent(List accounts) { + super(Case.Events.OS_ACCOUNT_CHANGED.toString(), accounts); + } +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsUpdatedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsUpdatedEvent.java new file mode 100755 index 0000000000..cb5308d7ce --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsUpdatedEvent.java @@ -0,0 +1,41 @@ +/* + * 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 java.util.List; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.Person; + +/** + * An event fired when persons in a case are updated. + */ +public class PersonsUpdatedEvent extends PersonsEvent { + + private static final long serialVersionUID = 1L; + + /** + * Constructs an event fired when persons in a case are updated. + * + * @param persons The updated persons. + */ + public PersonsUpdatedEvent(List persons) { + super(Case.Events.PERSONS_CHANGED.name(), persons); + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java new file mode 100755 index 0000000000..68a47c35c1 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java @@ -0,0 +1,165 @@ +/* + * 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 java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; +import java.util.logging.Level; +import java.util.stream.Collectors; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.events.AutopsyEvent; +import org.sleuthkit.datamodel.SleuthkitCase; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * An abstract base class for application events published when Sleuth Kit Data + * Model objects for a case are added, updated, or deleted. + * + * @param A Sleuth Kit Data Model object type. + */ +public abstract class TskDataModelChangedEvent extends AutopsyEvent { + + private static final long serialVersionUID = 1L; + private static final Logger logger = Logger.getLogger(TskDataModelChangedEvent.class.getName()); + private final boolean isDeletionEvent; + private final List dataModelObjectIds; + private transient List dataModelObjects; + + /** + * Constructs an instance of an abstract base class for application events + * published when Sleuth Kit Data Model objects for a case are added or + * updated. The getNewValue() method of this event will return the objects + * and the getOldValue() method will return an empty list. + * + * @param eventName The event name. + * @param dataModelObjects The Sleuth Kit Data Model objects that have been + * added or updated. + * @param getIdMethod A method that can be applied to the data model + * objects to get their unique numeric IDs (TSK + * object IDs, case database row IDs, etc.). + */ + protected TskDataModelChangedEvent(String eventName, List dataModelObjects, Function getIdMethod) { + super(eventName, null, null); + isDeletionEvent = false; + this.dataModelObjectIds = new ArrayList<>(); + this.dataModelObjectIds.addAll(dataModelObjects.stream().map(o -> getIdMethod.apply(o)).collect(Collectors.toList())); + this.dataModelObjects = new ArrayList<>(); + this.dataModelObjects.addAll(dataModelObjects); + } + + /** + * Constructs an instance of an abstract base class for application events + * published when Sleuth Kit Data Model objects for a case are added or + * updated. The getOldValue() method of this event will return the object + * IDs and the getNewValue() method will return an empty list. + * + * @param eventName The event name. + * @param dataModelObjectIds The unique numeric IDs (TSK object IDs, case + * database row IDs, etc.) of the Sleuth Kit Data + * Model objects that have been deleted. + */ + protected TskDataModelChangedEvent(String eventName, List dataModelObjectIds) { + super(eventName, null, null); + isDeletionEvent = true; + this.dataModelObjectIds = new ArrayList<>(); + this.dataModelObjectIds.addAll(dataModelObjectIds); + dataModelObjects = Collections.emptyList(); + } + + /** + * Gets the the unique numeric IDs (TSK object IDs, case database row IDs, + * etc.) of the Sleuth Kit Data Model objects that were deleted. + * + * @return The unique IDs. + */ + @Override + public List getOldValue() { + if (isDeletionEvent) { + return getDataModelObjectIds(); + } else { + return Collections.emptyList(); + } + } + + /** + * Gets the Sleuth Kit Data Model objects that were added or updated. If + * this event came from another host collaborating on a multi-user case, the + * Sleuth Kit Data Model objects will be reconstructed on the current host. + * + * @return The objects. + */ + @Override + public List getNewValue() { + if (!isDeletionEvent) { + if (dataModelObjects == null) { + try { + Case currentCase = Case.getCurrentCaseThrows(); + SleuthkitCase caseDb = currentCase.getSleuthkitCase(); + dataModelObjects = getDataModelObjects(caseDb, dataModelObjectIds); + } catch (NoCurrentCaseException | TskCoreException ex) { + logger.log(Level.SEVERE, String.format("Error geting TSK Data Model objects for %s event (%s)", getPropertyName(), getSourceType()), ex); + return Collections.emptyList(); + } + } + return Collections.unmodifiableList(dataModelObjects); + } else { + return Collections.emptyList(); + } + } + + + /** + * Gets the unique numeric IDs (TSK object IDs, case database row IDs, etc.) + * of the Sleuth Kit Data Model objects associated with this application + * event. + * + * This method is provided as an optimization that allows handling of an + * event that came from another host collaborating on a multi-user case + * without reconstructing the data model objects that are the subject s of + * the event. + * + * @return The unique IDs. + */ + public final List getDataModelObjectIds() { + return Collections.unmodifiableList(dataModelObjectIds); + } + + /** + * Gets the Sleuth Kit Data Model objects associated with this application + * event. If this event came from another host collaborating on a multi-user + * case, the Sleuth Kit Data Model objects, this method will be called to + * reconstruct the objects on the current host. + * + * @param caseDb The case database. + * @param ids The unique, numeric IDs (TSK object IDs, case database row + * IDs, etc.) of the Sleuth Kit Data Model objects. + * + * @return The objects. + * + * @throws org.sleuthkit.datamodel.TskCoreException If there is an error + * getting the Sleuth Kit + * Data Model objects. + */ + abstract protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException; + +}