From 382cd4bc1eb1ac6b7d25c047bd771bbc04c0c32c Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Mon, 31 Dec 2018 14:57:43 -0500 Subject: [PATCH] Add minimla coordination service node deletion for multi-user cases --- .../sleuthkit/autopsy/casemodule/Case.java | 53 +++++++++++++++++-- .../CoordinationService.java | 2 +- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index eaaa8f9926..54ed2531e4 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2018 Basis Technology Corp. + * Copyright 2011-2019 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -57,6 +57,7 @@ import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.ThreadSafe; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; +import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; @@ -705,8 +706,8 @@ public class Case { "Case.progressIndicatorTitle.deletingCase=Deleting Case", "Case.exceptionMessage.cannotDeleteCurrentCase=Cannot delete current case, it must be closed first.", "Case.progressMessage.checkingForOtherUser=Checking to see if another user has the case open...", - "Case.exceptionMessage.cannotGetLockToDeleteCase=Cannot delete case because it is open for another user or there is a problem with the coordination service." - }) + "Case.exceptionMessage.cannotGetLockToDeleteCase=Cannot delete case because it is open for another user or there is a problem with the coordination service.", + "Case.exceptionMessage.failedToDeleteCoordinationServiceNodes=Failed to delete the coordination service nodes for the case.",}) public static void deleteCase(CaseMetadata metadata) throws CaseActionException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); @@ -751,14 +752,56 @@ public class Case { } catch (CoordinationServiceException ex) { stopWatch.stop(); logger.log(Level.INFO, String.format("Used %d s to fail to acquire case directory coordination service lock for %s (%s) in %s", stopWatch.getElapsedTimeSecs(), metadata.getCaseDisplayName(), metadata.getCaseName(), metadata.getCaseDirectory())); - throw new CaseActionException(Bundle.Case_exceptionMessage_cannotGetLockToDeleteCase(), ex); + throw new CaseActionException(Bundle.Case_exceptionMessage_failedToDeleteCoordinationServiceNodes(), ex); } } + try { + deleteCoordinationServiceNodes(metadata, progressIndicator); + } catch (CoordinationServiceException ex) { + throw new CaseActionException(Bundle.Case_creationException_couldNotAcquireDirLock()); + } } finally { progressIndicator.finish(); } } + /** + * Deletes teh coordination nodes for a multi-user case. + * + * @param metadata The metadata for the case to delete. + * @param progressIndicator The progress indicator for the deletion + * operation. + * + * @throws CoordinationServiceException If there is a problem getting the + * coordination service. + */ + @Messages({ + "Case.progressMessage.deletingCoordinationServiceNodes=Deleting coordination service nodes..." + }) + static void deleteCoordinationServiceNodes(CaseMetadata metadata, ProgressIndicator progressIndicator) throws CoordinationServiceException { + progressIndicator.progress(Bundle.Case_progressMessage_deletingCoordinationServiceNodes()); + CoordinationService coordinationService; + coordinationService = CoordinationService.getInstance(); + String resourcesLockNodePath = metadata.getCaseDirectory() + "_resources"; + try { + coordinationService.deleteNode(CategoryNode.CASES, resourcesLockNodePath); + } catch (CoordinationServiceException ex) { + /* + * Log but do not notify the user. + */ + logger.log(Level.SEVERE, String.format("Failed to delete resources lock coordination service node for %s (%s) in %s", metadata.getCaseDisplayName(), metadata.getCaseName(), metadata.getCaseDirectory()), ex); + } + String caseDirectoryLockNodePath = metadata.getCaseDirectory(); + try { + coordinationService.deleteNode(CategoryNode.CASES, caseDirectoryLockNodePath); + } catch (CoordinationServiceException ex) { + /* + * Log but do not notify the user. + */ + logger.log(Level.SEVERE, String.format("Failed to delete case directory lock coordination service node for %s (%s) in %s", metadata.getCaseDisplayName(), metadata.getCaseName(), metadata.getCaseDirectory()), ex); + } + } + /** * Opens a new or existing case as the current case. * @@ -1835,7 +1878,7 @@ public class Case { progressIndicator.progress(Bundle.Case_progressMessage_preparingToOpenCaseResources()); acquireSharedCaseDirLock(metadata.getCaseDirectory()); try (CoordinationService.Lock resourcesLock = acquireExclusiveCaseResourcesLock(metadata.getCaseDirectory())) { - assert(resourcesLock != null); // Use reference to avoid compile time warning. + assert (resourcesLock != null); // Use reference to avoid compile time warning. open(isNewCase, progressIndicator); } catch (CaseActionException ex) { releaseSharedCaseDirLock(getMetadata().getCaseDirectory()); diff --git a/Core/src/org/sleuthkit/autopsy/coordinationservice/CoordinationService.java b/Core/src/org/sleuthkit/autopsy/coordinationservice/CoordinationService.java index 36cf5a503c..ea087664b2 100644 --- a/Core/src/org/sleuthkit/autopsy/coordinationservice/CoordinationService.java +++ b/Core/src/org/sleuthkit/autopsy/coordinationservice/CoordinationService.java @@ -366,7 +366,7 @@ public final class CoordinationService { * @throws CoordinationServiceException If there is an error deleting the * node. */ - void deleteNode(CategoryNode category, String nodePath) throws CoordinationServiceException { + public void deleteNode(CategoryNode category, String nodePath) throws CoordinationServiceException { String fullNodePath = getFullyQualifiedNodePath(category, nodePath); try { curator.delete().forPath(fullNodePath);