diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index c2fd9d822f..289b94f4ad 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -81,6 +81,8 @@ import org.sleuthkit.autopsy.casemodule.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.casemodule.events.DataSourceAddedEvent; import org.sleuthkit.autopsy.casemodule.events.DataSourceDeletedEvent; import org.sleuthkit.autopsy.casemodule.events.DataSourceNameChangedEvent; +import org.sleuthkit.autopsy.casemodule.events.OsAccountAddedEvent; +import org.sleuthkit.autopsy.casemodule.events.OsAccountChangedEvent; import org.sleuthkit.autopsy.casemodule.events.ReportAddedEvent; import org.sleuthkit.autopsy.casemodule.multiusercases.CaseNodeData.CaseNodeDataException; import org.sleuthkit.autopsy.casemodule.multiusercases.CoordinationServiceUtils; @@ -128,6 +130,10 @@ import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.DataSource; import org.sleuthkit.datamodel.FileSystem; import org.sleuthkit.datamodel.Image; +import org.sleuthkit.datamodel.OsAccount; +import org.sleuthkit.datamodel.OsAccountManager; +import org.sleuthkit.datamodel.OsAccountManager.OsAccountsAddedEvent; +import org.sleuthkit.datamodel.OsAccountManager.OsAccountsChangedEvent; import org.sleuthkit.datamodel.Report; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TimelineManager; @@ -409,7 +415,17 @@ public class Case { * An item in the central repository has had its comment modified. The * old value is null, the new value is string for current comment. */ - CR_COMMENT_CHANGED; + CR_COMMENT_CHANGED, + /** + * OSAccount associated with the current case added. Call getOsAccount + * to get the added account; + */ + OS_ACCOUNT_ADDED, + /** + * OSAccount associated with the current case has changed. + * Call getOsAccount to get the changed account; + */ + OS_ACCOUNT_CHANGED; }; @@ -443,6 +459,20 @@ public class Case { event.getArtifacts(artifactType))); } } + + @Subscribe + public void publishOsAccountAddedEvent(OsAccountManager.OsAccountsAddedEvent event) { + for(OsAccount account: event.getOsAcounts()) { + eventPublisher.publish(new OsAccountAddedEvent(account)); + } + } + + @Subscribe + public void publishOsAccountAddedEvent(OsAccountManager.OsAccountsChangedEvent event) { + for(OsAccount account: event.getOsAcounts()) { + eventPublisher.publish(new OsAccountChangedEvent(account)); + } + } } /** @@ -1639,7 +1669,15 @@ public class Case { public void notifyBlackBoardArtifactTagDeleted(BlackboardArtifactTag deletedTag) { eventPublisher.publish(new BlackBoardArtifactTagDeletedEvent(deletedTag)); } + + public void notifyOsAccountAdded(OsAccount account) { + eventPublisher.publish(new OsAccountAddedEvent(account)); + } + public void notifyOsAccountChanged(OsAccount account) { + eventPublisher.publish(new OsAccountChangedEvent(account)); + } + /** * Adds a report to the case. * diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountAddedEvent.java new file mode 100755 index 0000000000..c9f89903f4 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountAddedEvent.java @@ -0,0 +1,35 @@ +/* + * 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 added to a case. + */ +public final class OsAccountAddedEvent extends OsAccountEvent { + + private static final long serialVersionUID = 1L; + + public OsAccountAddedEvent(OsAccount account) { + super(Case.Events.OS_ACCOUNT_ADDED.toString(), account); + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountChangedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountChangedEvent.java new file mode 100755 index 0000000000..237373a8b9 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountChangedEvent.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 updated. + */ +public final class OsAccountChangedEvent extends OsAccountEvent { + + private static final long serialVersionUID = 1L; + + public OsAccountChangedEvent(OsAccount account) { + super(Case.Events.OS_ACCOUNT_CHANGED.toString(), account); + } +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountEvent.java new file mode 100755 index 0000000000..22b0622ba8 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountEvent.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 OsAccountEvent extends TskDataModelChangeEvent { + + 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. + */ + OsAccountEvent(String eventName, OsAccount account) { + super(eventName, Stream.of(account.getId()).collect(Collectors.toList()), Stream.of(account).collect(Collectors.toList())); + } + + /** + * 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().getOsAccount(id); + List accounts = new ArrayList<>(); + accounts.add(account); + return accounts; + } +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangeEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangeEvent.java index 891aed0f75..1bd9fd81ac 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangeEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangeEvent.java @@ -75,8 +75,8 @@ public abstract class TskDataModelChangeEvent extends AutopsyEvent { * * @return The unique IDs. */ - public final List getDataModelObjectIds() { - return Collections.unmodifiableList(dataModelObjects); + public final List getDataModelObjectIds() { + return Collections.unmodifiableList(dataModelObjectIds); } /**