2229: Part 8: Use getOpenCase() instead of getCurrentCase() in datamodule, casemodule, hashdatabase and report.

This commit is contained in:
U-BASIS\zhaohui 2018-03-02 10:55:38 -05:00
parent 5b71742271
commit 23f5b3c3da
7 changed files with 85 additions and 48 deletions

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2015 Basis Technology Corp.
* Copyright 2015-2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.casemodule.events;
import java.io.Serializable;
import javax.annotation.concurrent.Immutable;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.datamodel.ContentTag;
import org.sleuthkit.datamodel.TskCoreException;
@ -41,10 +42,10 @@ public class ContentTagAddedEvent extends TagAddedEvent<ContentTag> implements S
*
* @return ContentTag that was added
*
* @throws IllegalStateException
* @throws NoCurrentCaseException
* @throws TskCoreException
*/
ContentTag getTagByID() throws IllegalStateException, TskCoreException {
return Case.getCurrentCase().getServices().getTagsManager().getContentTagByTagID(getTagID());
ContentTag getTagByID() throws NoCurrentCaseException, TskCoreException {
return Case.getOpenCase().getServices().getTagsManager().getContentTagByTagID(getTagID());
}
}

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2015 Basis Technology Corp.
* Copyright 2015-2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.casemodule.events;
import java.io.Serializable;
import java.util.logging.Level;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.events.AutopsyEvent;
import org.sleuthkit.datamodel.Tag;
@ -84,7 +85,7 @@ abstract class TagAddedEvent<T extends Tag> extends AutopsyEvent implements Seri
try {
tag = getTagByID();
return tag;
} catch (IllegalStateException | TskCoreException ex) {
} catch (NoCurrentCaseException | TskCoreException ex) {
Logger.getLogger(TagAddedEvent.class.getName()).log(Level.SEVERE, "Error doing lazy load for remote event", ex); //NON-NLS
return null;
}
@ -98,8 +99,8 @@ abstract class TagAddedEvent<T extends Tag> extends AutopsyEvent implements Seri
*
* @return the Tag based on the saved tag id
*
* @throws IllegalStateException
* @throws NoCurrentCaseException
* @throws TskCoreException
*/
abstract T getTagByID() throws IllegalStateException, TskCoreException;
abstract T getTagByID() throws NoCurrentCaseException, TskCoreException;
}

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2017 Basis Technology Corp.
* Copyright 2011-2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -59,6 +59,7 @@ import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.util.lookup.Lookups;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent;
import org.sleuthkit.autopsy.datamodel.AutopsyItemVisitor;
import org.sleuthkit.autopsy.datamodel.AutopsyVisitableItem;
@ -240,7 +241,7 @@ final public class Accounts implements AutopsyVisitableItem {
* that is already closed.
*/
try {
Case.getCurrentCase();
Case.getOpenCase();
/**
* Even with the check above, it is still possible that
* the case will be closed in a different thread before
@ -252,7 +253,7 @@ final public class Accounts implements AutopsyVisitableItem {
&& eventData.getBlackboardArtifactType().getTypeID() == ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
reviewStatusBus.post(eventData);
}
} catch (IllegalStateException notUsed) {
} catch (NoCurrentCaseException notUsed) {
// Case is closed, do nothing.
}
} else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
@ -264,9 +265,9 @@ final public class Accounts implements AutopsyVisitableItem {
* that is already closed.
*/
try {
Case.getCurrentCase();
Case.getOpenCase();
refresh(true);
} catch (IllegalStateException notUsed) {
} catch (NoCurrentCaseException notUsed) {
// Case is closed, do nothing.
}
} else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
@ -368,7 +369,7 @@ final public class Accounts implements AutopsyVisitableItem {
* that is already closed.
*/
try {
Case.getCurrentCase();
Case.getOpenCase();
/**
* Even with the check above, it is still possible that
* the case will be closed in a different thread before
@ -380,7 +381,7 @@ final public class Accounts implements AutopsyVisitableItem {
&& eventData.getBlackboardArtifactType().getTypeID() == ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
reviewStatusBus.post(eventData);
}
} catch (IllegalStateException notUsed) {
} catch (NoCurrentCaseException notUsed) {
// Case is closed, do nothing.
}
} else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
@ -392,10 +393,10 @@ final public class Accounts implements AutopsyVisitableItem {
* that is already closed.
*/
try {
Case.getCurrentCase();
Case.getOpenCase();
refresh(true);
} catch (IllegalStateException notUsed) {
} catch (NoCurrentCaseException notUsed) {
// Case is closed, do nothing.
}
} else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
@ -517,7 +518,7 @@ final public class Accounts implements AutopsyVisitableItem {
* that is already closed.
*/
try {
Case.getCurrentCase();
Case.getOpenCase();
/**
* Even with the check above, it is still possible that
* the case will be closed in a different thread before
@ -529,7 +530,7 @@ final public class Accounts implements AutopsyVisitableItem {
&& eventData.getBlackboardArtifactType().getTypeID() == ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
reviewStatusBus.post(eventData);
}
} catch (IllegalStateException notUsed) {
} catch (NoCurrentCaseException notUsed) {
// Case is closed, do nothing.
}
} else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
@ -541,10 +542,10 @@ final public class Accounts implements AutopsyVisitableItem {
* that is already closed.
*/
try {
Case.getCurrentCase();
Case.getOpenCase();
refresh(true);
} catch (IllegalStateException notUsed) {
} catch (NoCurrentCaseException notUsed) {
// Case is closed, do nothing.
}
} else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
@ -651,7 +652,7 @@ final public class Accounts implements AutopsyVisitableItem {
* that is already closed.
*/
try {
Case.getCurrentCase();
Case.getOpenCase();
/**
* Even with the check above, it is still possible that
* the case will be closed in a different thread before
@ -663,7 +664,7 @@ final public class Accounts implements AutopsyVisitableItem {
&& eventData.getBlackboardArtifactType().getTypeID() == ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
reviewStatusBus.post(eventData);
}
} catch (IllegalStateException notUsed) {
} catch (NoCurrentCaseException notUsed) {
// Case is closed, do nothing.
}
} else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
@ -675,10 +676,10 @@ final public class Accounts implements AutopsyVisitableItem {
* that is already closed.
*/
try {
Case.getCurrentCase();
Case.getOpenCase();
refresh(true);
} catch (IllegalStateException notUsed) {
} catch (NoCurrentCaseException notUsed) {
// Case is closed, do nothing.
}
} else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
@ -862,7 +863,7 @@ final public class Accounts implements AutopsyVisitableItem {
* that is already closed.
*/
try {
Case.getCurrentCase();
Case.getOpenCase();
/**
* Even with the check above, it is still possible that
* the case will be closed in a different thread before
@ -874,7 +875,7 @@ final public class Accounts implements AutopsyVisitableItem {
&& eventData.getBlackboardArtifactType().getTypeID() == ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
reviewStatusBus.post(eventData);
}
} catch (IllegalStateException notUsed) {
} catch (NoCurrentCaseException notUsed) {
// Case is closed, do nothing.
}
} else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
@ -886,10 +887,10 @@ final public class Accounts implements AutopsyVisitableItem {
* that is already closed.
*/
try {
Case.getCurrentCase();
Case.getOpenCase();
refresh(true);
} catch (IllegalStateException notUsed) {
} catch (NoCurrentCaseException notUsed) {
// Case is closed, do nothing.
}
} else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {

View File

@ -24,6 +24,7 @@ import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CallableSystemAction;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.datamodel.ContentUtils;
import org.sleuthkit.autopsy.directorytree.HashSearchProvider;
import org.sleuthkit.datamodel.AbstractFile;
@ -118,8 +119,12 @@ public class HashDbSearchAction extends CallableSystemAction implements HashSear
* performAction.
*/
@Override
@NbBundle.Messages ({
"HashDbSearchAction.noOpenCase.errMsg=No open case available."
})
public void performAction() {
// Make sure at least 1 file has an md5 hash
try {
if (file != null && HashDbSearcher.countFilesMd5Hashed() > 0) {
doSearch();
} else {
@ -129,6 +134,12 @@ public class HashDbSearchAction extends CallableSystemAction implements HashSear
NbBundle.getMessage(this.getClass(), "HashDbSearchAction.dlgMsg.title"),
JOptionPane.ERROR_MESSAGE);
}
} catch (NoCurrentCaseException ex) {
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
Bundle.HashDbSearchAction_noOpenCase_errMsg(),
NbBundle.getMessage(this.getClass(), "HashDbSearchAction.dlgMsg.title"),
JOptionPane.ERROR_MESSAGE);
}
}
private void doSearch() {

View File

@ -32,6 +32,7 @@ import javax.swing.table.DefaultTableModel;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.ingest.IngestManager;
/**
@ -290,16 +291,27 @@ class HashDbSearchPanel extends javax.swing.JPanel implements ActionListener {
* Search through all tsk_files to find ones with the same hashes as the
* hashes given.
*/
@NbBundle.Messages ({
"HashDbSearchPanel.noOpenCase.errMsg=No open case available."
})
boolean search() {
// Check if any hashed have been entered
if (hashTable.getRowCount() != 0) {
// Make sure at least 1 file has an md5 hash
if (HashDbSearcher.countFilesMd5Hashed() > 0) {
return doSearch();
} else {
try {
if (HashDbSearcher.countFilesMd5Hashed() > 0) {
return doSearch();
} else {
JOptionPane.showMessageDialog(this,
NbBundle.getMessage(this.getClass(),
"HashDbSearchPanel.noFilesHaveMD5HashMsg"),
NbBundle.getMessage(this.getClass(), "HashDbSearchPanel.dlgMsg.title"),
JOptionPane.ERROR_MESSAGE);
return false;
}
} catch (NoCurrentCaseException ex) {
JOptionPane.showMessageDialog(this,
NbBundle.getMessage(this.getClass(),
"HashDbSearchPanel.noFilesHaveMD5HashMsg"),
Bundle.HashDbSearchPanel_noOpenCase_errMsg(),
NbBundle.getMessage(this.getClass(), "HashDbSearchPanel.dlgMsg.title"),
JOptionPane.ERROR_MESSAGE);
return false;

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011 Basis Technology Corp.
* Copyright 2011-2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -22,9 +22,12 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import javax.swing.SwingWorker;
import org.netbeans.api.progress.ProgressHandle;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.FsContent;
import org.sleuthkit.datamodel.SleuthkitCase;
@ -34,7 +37,7 @@ import org.sleuthkit.datamodel.SleuthkitCase;
* the same content.
*/
class HashDbSearcher {
private static final Logger logger = Logger.getLogger(HashDbSearcher.class.getName());
/**
* Given a string hash value, find all files with that hash.
*
@ -42,8 +45,8 @@ class HashDbSearcher {
*
* @return a List of all FsContent with the given hash
*/
static List<AbstractFile> findFilesByMd5(String md5Hash) {
final Case currentCase = Case.getCurrentCase();
static List<AbstractFile> findFilesByMd5(String md5Hash) throws NoCurrentCaseException {
final Case currentCase = Case.getOpenCase();
final SleuthkitCase skCase = currentCase.getSleuthkitCase();
return skCase.findFilesByMd5(md5Hash);
}
@ -56,7 +59,7 @@ class HashDbSearcher {
*
* @return a Map of md5 hashes mapped to the list of files hit
*/
static Map<String, List<AbstractFile>> findFilesBymd5(List<String> md5Hash) {
static Map<String, List<AbstractFile>> findFilesBymd5(List<String> md5Hash) throws NoCurrentCaseException {
Map<String, List<AbstractFile>> map = new LinkedHashMap<String, List<AbstractFile>>();
for (String md5 : md5Hash) {
List<AbstractFile> files = findFilesByMd5(md5);
@ -69,7 +72,7 @@ class HashDbSearcher {
// Same as above, but with a given ProgressHandle to accumulate and StringWorker to check if cancelled
static Map<String, List<AbstractFile>> findFilesBymd5(List<String> md5Hash, ProgressHandle progress, SwingWorker<Object, Void> worker) {
static Map<String, List<AbstractFile>> findFilesBymd5(List<String> md5Hash, ProgressHandle progress, SwingWorker<Object, Void> worker) throws NoCurrentCaseException {
Map<String, List<AbstractFile>> map = new LinkedHashMap<String, List<AbstractFile>>();
if (!worker.isCancelled()) {
progress.switchToDeterminate(md5Hash.size());
@ -101,9 +104,14 @@ class HashDbSearcher {
*/
static List<AbstractFile> findFiles(FsContent file) {
String md5;
if ((md5 = file.getMd5Hash()) != null) {
return findFilesByMd5(md5);
} else {
try {
if ((md5 = file.getMd5Hash()) != null) {
return findFilesByMd5(md5);
} else {
return Collections.<AbstractFile>emptyList();
}
} catch (NoCurrentCaseException ex) {
logger.log(Level.SEVERE, "Exception while getting open case.", ex);
return Collections.<AbstractFile>emptyList();
}
}
@ -114,8 +122,8 @@ class HashDbSearcher {
*
* @return true if the search feature is ready.
*/
static boolean allFilesMd5Hashed() {
final Case currentCase = Case.getCurrentCase();
static boolean allFilesMd5Hashed() throws NoCurrentCaseException {
final Case currentCase = Case.getOpenCase();
final SleuthkitCase skCase = currentCase.getSleuthkitCase();
return skCase.allFilesMd5Hashed();
}
@ -125,8 +133,8 @@ class HashDbSearcher {
*
* @return the number of files with an MD5
*/
static int countFilesMd5Hashed() {
final Case currentCase = Case.getCurrentCase();
static int countFilesMd5Hashed() throws NoCurrentCaseException {
final Case currentCase = Case.getOpenCase();
final SleuthkitCase skCase = currentCase.getSleuthkitCase();
return skCase.countFilesMd5Hashed();
}

View File

@ -31,6 +31,7 @@ import org.sleuthkit.autopsy.coreutils.Logger;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.TskCoreException;
@ -71,13 +72,15 @@ class FileReportText implements FileReportModule {
if (out != null) {
try {
out.close();
Case.getCurrentCase().addReport(reportPath, NbBundle.getMessage(this.getClass(),
Case.getOpenCase().addReport(reportPath, NbBundle.getMessage(this.getClass(),
"FileReportText.getName.text"), "");
} catch (IOException ex) {
logger.log(Level.WARNING, "Could not close output writer when ending report.", ex); //NON-NLS
} catch (TskCoreException ex) {
String errorMessage = String.format("Error adding %s to case as a report", reportPath); //NON-NLS
logger.log(Level.SEVERE, errorMessage, ex);
} catch (NoCurrentCaseException ex) {
logger.log(Level.SEVERE, "Exception while getting open case.", ex);
}
}
}