From 860f939da3ec2452aed02627aaff6ba32e8fe988 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Fri, 26 Jun 2020 19:43:31 -0400 Subject: [PATCH 1/2] 6567 TagName serialization fix --- .../autopsy/actions/AddTagAction.java | 4 +- .../actions/GetTagNameAndCommentDialog.java | 8 +-- .../autopsy/actions/ReplaceTagAction.java | 4 +- .../casemodule/services/TagsManager.java | 57 ++++++++++++------- .../org/sleuthkit/autopsy/tags/TagUtils.java | 10 +++- 5 files changed, 49 insertions(+), 34 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/actions/AddTagAction.java b/Core/src/org/sleuthkit/autopsy/actions/AddTagAction.java index 53cf076c2e..9c059205f5 100644 --- a/Core/src/org/sleuthkit/autopsy/actions/AddTagAction.java +++ b/Core/src/org/sleuthkit/autopsy/actions/AddTagAction.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2019 Basis Technology Corp. + * Copyright 2013-2020 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -139,7 +139,7 @@ abstract class AddTagAction extends AbstractAction implements Presenter.Popup { if (!tagNamesMap.isEmpty()) { for (Map.Entry entry : tagNamesMap.entrySet()) { TagName tagName = entry.getValue(); - TagSet tagSet = tagName.getTagSet(); + TagSet tagSet = tagsManager.getTagSet(tagName); // Show custom tags before predefined tags in the menu if (tagSet != null) { diff --git a/Core/src/org/sleuthkit/autopsy/actions/GetTagNameAndCommentDialog.java b/Core/src/org/sleuthkit/autopsy/actions/GetTagNameAndCommentDialog.java index ba586c7b22..a0c3b1c5c0 100644 --- a/Core/src/org/sleuthkit/autopsy/actions/GetTagNameAndCommentDialog.java +++ b/Core/src/org/sleuthkit/autopsy/actions/GetTagNameAndCommentDialog.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2018 Basis Technology Corp. + * Copyright 2013-2020 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,6 @@ import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.util.ArrayList; -import java.util.HashMap; import java.util.logging.Level; import java.util.List; import java.util.Map; @@ -36,7 +35,6 @@ import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JList; import javax.swing.KeyStroke; -import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.casemodule.Case; @@ -150,7 +148,7 @@ public class GetTagNameAndCommentDialog extends JDialog { } ); - try { + try { TagsManager tagsManager = Case.getCurrentCaseThrows().getServices().getTagsManager(); List standardTagNames = TagsManager.getStandardTagNames(); Map tagNamesMap = new TreeMap<>(tagsManager.getDisplayNamesToTagNamesMap()); @@ -161,7 +159,7 @@ public class GetTagNameAndCommentDialog extends JDialog { tagNamesMap.entrySet().stream().map((entry) -> entry.getValue()).forEachOrdered((tagName) -> { TagSet tagSet = null; try { - tagSet = tagName.getTagSet(); + tagSet = tagsManager.getTagSet(tagName); } catch (TskCoreException ex) { Logger.getLogger(GetTagNameAndCommentDialog.class .getName()).log(Level.SEVERE, "Failed to get tag set", ex); //NON-NLS diff --git a/Core/src/org/sleuthkit/autopsy/actions/ReplaceTagAction.java b/Core/src/org/sleuthkit/autopsy/actions/ReplaceTagAction.java index 91929db577..34ed836e3e 100644 --- a/Core/src/org/sleuthkit/autopsy/actions/ReplaceTagAction.java +++ b/Core/src/org/sleuthkit/autopsy/actions/ReplaceTagAction.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2018 Basis Technology Corp. + * Copyright 2018-2020 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -131,7 +131,7 @@ abstract class ReplaceTagAction extends AbstractAction implements if (!tagNamesMap.isEmpty()) { for (Map.Entry entry : tagNamesMap.entrySet()) { TagName tagName = entry.getValue(); - TagSet tagSet = tagName.getTagSet(); + TagSet tagSet = tagsManager.getTagSet(tagName); // Show custom tags before predefined tags in the menu if (tagSet != null) { diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java index 746bac478c..96040821e4 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2020 Basis Technology Corp. + * Copyright 2013-2020 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -56,7 +56,7 @@ public class TagsManager implements Closeable { private final SleuthkitCase caseDb; private static String DEFAULT_TAG_SET_NAME = "Project VIC"; - + private static final Object lock = new Object(); static { @@ -235,16 +235,16 @@ public class TagsManager implements Closeable { public static String getNotableTagDisplayName() { return TagNameDefinition.getNotableTagDisplayName(); } - + /** * Creates a new TagSetDefinition file. - * + * * @param tagSetDef The tag set definition. - * - * @throws IOException + * + * @throws IOException */ public static void addTagSetDefinition(TagSetDefinition tagSetDef) throws IOException { - synchronized(lock) { + synchronized (lock) { TagSetDefinition.writeTagSetDefinition(tagSetDef); } } @@ -267,20 +267,20 @@ public class TagsManager implements Closeable { caseDb.addOrUpdateTagName(def.getDisplayName(), def.getDescription(), def.getColor(), def.getKnownStatus()); } //Assume new case and add tag sets - for(TagSetDefinition setDef: TagSetDefinition.readTagSetDefinitions()) { + for (TagSetDefinition setDef : TagSetDefinition.readTagSetDefinitions()) { List tagNameList = new ArrayList<>(); - for(TagNameDefinition tagNameDef: setDef.getTagNameDefinitions()) { + for (TagNameDefinition tagNameDef : setDef.getTagNameDefinitions()) { tagNameList.add(caseDb.addOrUpdateTagName(tagNameDef.getDisplayName(), tagNameDef.getDescription(), tagNameDef.getColor(), tagNameDef.getKnownStatus())); } - - if(!tagNameList.isEmpty()) { + + if (!tagNameList.isEmpty()) { taggingMgr.addTagSet(setDef.getName(), tagNameList); } } } } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Error updating standard tag name and tag set definitions", ex); - } catch(IOException ex) { + } catch (IOException ex) { LOGGER.log(Level.SEVERE, "Error loading tag set JSON files", ex); } @@ -288,28 +288,41 @@ public class TagsManager implements Closeable { tagName.saveToCase(caseDb); } } - + /** * Get a list of all tag sets currently in the case database. - * + * * @return A list, possibly empty, of TagSet objects. - * + * * @throws TskCoreException */ public List getAllTagSets() throws TskCoreException { return caseDb.getTaggingManager().getTagSets(); } - + + /** + * Gets the tag set a tag name (tag definition) belongs to, if any. + * + * @param tagName The tag name. + * + * @return A TagSet object or null. + * + * @throws TskCoreException If there is an error querying the case database. + */ + public TagSet getTagSet(TagName tagName) throws TskCoreException { + return caseDb.getTaggingManager().getTagSetForTagName(tagName); + } + /** * Add a new TagSet to the case database. Tags will be ranked in the order * which they are passed to this method. - * - * @param name Tag set name. + * + * @param name Tag set name. * @param tagNameList List of TagName in rank order. - * + * * @return A new TagSet object. - * - * @throws TskCoreException + * + * @throws TskCoreException */ public TagSet addTagSet(String name, List tagNameList) throws TskCoreException { return caseDb.getTaggingManager().addTagSet(name, tagNameList); @@ -501,7 +514,7 @@ public class TagsManager implements Closeable { * name to the case database. */ public TagName addTagName(String displayName, String description, TagName.HTML_COLOR color, TskData.FileKnown knownStatus) throws TagNameAlreadyExistsException, TskCoreException { - synchronized(lock) { + synchronized (lock) { try { TagName tagName = caseDb.addOrUpdateTagName(displayName, description, color, knownStatus); Set customTypes = TagNameDefinition.getTagNameDefinitions(); diff --git a/Core/src/org/sleuthkit/autopsy/tags/TagUtils.java b/Core/src/org/sleuthkit/autopsy/tags/TagUtils.java index 3b63168a07..de93bed26e 100755 --- a/Core/src/org/sleuthkit/autopsy/tags/TagUtils.java +++ b/Core/src/org/sleuthkit/autopsy/tags/TagUtils.java @@ -19,6 +19,9 @@ package org.sleuthkit.autopsy.tags; import java.util.logging.Level; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TagSet; @@ -52,12 +55,13 @@ public final class TagUtils { public static String getDecoratedTagDisplayName(TagName tagName) { String displayName = tagName.getDisplayName(); try { - TagSet tagSet = tagName.getTagSet(); + TagsManager tagsManager = Case.getCurrentCaseThrows().getServices().getTagsManager(); + TagSet tagSet = tagsManager.getTagSet(tagName); if (tagSet != null) { displayName = tagSet.getName() + ": " + displayName; } - } catch (TskCoreException ex) { - logger.log(Level.WARNING, String.format("Failed to get TagSet for TagName (%d)", tagName.getId())); + } catch (NoCurrentCaseException | TskCoreException ex) { + logger.log(Level.SEVERE, String.format("Failed to get TagSet for TagName '%s' (ID=%d)", tagName.getDisplayName(), tagName.getId())); } if (tagName.getKnownStatus() == TskData.FileKnown.BAD) { From 0408755a7950972f5e9995962332694966ea8ce3 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Fri, 26 Jun 2020 19:44:32 -0400 Subject: [PATCH 2/2] 6567 TagName serialization fix --- .../org/sleuthkit/autopsy/casemodule/services/TagsManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java index 96040821e4..1a9b2e792d 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java @@ -310,7 +310,7 @@ public class TagsManager implements Closeable { * @throws TskCoreException If there is an error querying the case database. */ public TagSet getTagSet(TagName tagName) throws TskCoreException { - return caseDb.getTaggingManager().getTagSetForTagName(tagName); + return caseDb.getTaggingManager().getTagSet(tagName); } /**