Autopsy  4.5.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
TagsManager.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.casemodule.services;
20 
21 import java.io.Closeable;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29 import java.util.logging.Level;
30 import org.openide.util.NbBundle;
33 import org.sleuthkit.datamodel.BlackboardArtifact;
34 import org.sleuthkit.datamodel.BlackboardArtifactTag;
35 import org.sleuthkit.datamodel.Content;
36 import org.sleuthkit.datamodel.ContentTag;
37 import org.sleuthkit.datamodel.SleuthkitCase;
38 import org.sleuthkit.datamodel.TagName;
39 import org.sleuthkit.datamodel.TskCoreException;
40 import org.sleuthkit.datamodel.TskData;
41 
46 public class TagsManager implements Closeable {
47 
48  private static final Logger LOGGER = Logger.getLogger(TagsManager.class.getName());
49 
50  private final SleuthkitCase caseDb;
51 
60  public static boolean containsIllegalCharacters(String tagDisplayName) {
61  return (tagDisplayName.contains("\\")
62  || tagDisplayName.contains(":")
63  || tagDisplayName.contains("*")
64  || tagDisplayName.contains("?")
65  || tagDisplayName.contains("\"")
66  || tagDisplayName.contains("<")
67  || tagDisplayName.contains(">")
68  || tagDisplayName.contains("|")
69  || tagDisplayName.contains(",")
70  || tagDisplayName.contains(";"));
71 
72  }
73  @NbBundle.Messages({"TagsManager.notableTagEnding.text= (Notable)"})
79  public static String getNotableTagLabel(){
80  return Bundle.TagsManager_notableTagEnding_text();
81  }
82 
94  public static Set<String> getTagDisplayNames() throws TskCoreException {
95  Set<String> tagDisplayNames = new HashSet<>();
96  Set<TagNameDefinition> customNames = TagNameDefinition.getTagNameDefinitions();
97  customNames.forEach((tagType) -> {
98  tagDisplayNames.add(tagType.getDisplayName());
99  });
100  try {
102  for (TagName tagName : tagsManager.getAllTagNames()) {
103  tagDisplayNames.add(tagName.getDisplayName());
104  }
105  } catch (IllegalStateException ignored) {
106  /*
107  * No current case, nothing more to add to the set.
108  */
109  }
110  return tagDisplayNames;
111  }
112 
113  public static List<String> getNotableTagDisplayNames() {
114  List<String> tagDisplayNames = new ArrayList<>();
115  for (TagNameDefinition tagDef : TagNameDefinition.getTagNameDefinitions()) {
116  if (tagDef.getKnownStatus() == TskData.FileKnown.BAD) {
117  tagDisplayNames.add(tagDef.getDisplayName());
118  }
119  }
120  return tagDisplayNames;
121  }
122 
129  TagsManager(SleuthkitCase caseDb) {
130  this.caseDb = caseDb;
131  for (TagNameDefinition tagName : TagNameDefinition.getTagNameDefinitions()) {
132  tagName.saveToCase(caseDb);
133  }
134  }
135 
143  public List<TagName> getAllTagNames() throws TskCoreException {
144  return caseDb.getAllTagNames();
145  }
146 
155  public List<TagName> getTagNamesInUse() throws TskCoreException {
156  return caseDb.getTagNamesInUse();
157  }
158 
172  public Map<String, TagName> getDisplayNamesToTagNamesMap() throws TskCoreException {
185  Map<String, TagName> tagNames = new HashMap<>();
186  Set<TagNameDefinition> customTypes = TagNameDefinition.getTagNameDefinitions();
187  for (TagNameDefinition tagType : customTypes) {
188  tagNames.put(tagType.getDisplayName(), null);
189  }
190  for (TagName tagName : caseDb.getAllTagNames()) {
191  tagNames.put(tagName.getDisplayName(), tagName);
192  }
193  return new HashMap<>(tagNames);
194  }
195 
210  public synchronized TagName addTagName(String displayName) throws TagNameAlreadyExistsException, TskCoreException {
211  return addTagName(displayName, "", TagName.HTML_COLOR.NONE, TskData.FileKnown.UNKNOWN);
212  }
213 
229  public synchronized TagName addTagName(String displayName, String description) throws TagNameAlreadyExistsException, TskCoreException {
230  return addTagName(displayName, description, TagName.HTML_COLOR.NONE, TskData.FileKnown.UNKNOWN);
231  }
232 
248  public synchronized TagName addTagName(String displayName, String description, TagName.HTML_COLOR color) throws TagNameAlreadyExistsException, TskCoreException {
249  return addTagName(displayName, description, color, TskData.FileKnown.UNKNOWN);
250  }
251 
269  public synchronized TagName addTagName(String displayName, String description, TagName.HTML_COLOR color, TskData.FileKnown knownStatus) throws TagNameAlreadyExistsException, TskCoreException {
270  try {
271  TagName tagName = caseDb.addOrUpdateTagName(displayName, description, color, knownStatus);
272  Set<TagNameDefinition> customTypes = TagNameDefinition.getTagNameDefinitions();
273  customTypes.add(new TagNameDefinition(displayName, description, color, knownStatus));
274  TagNameDefinition.setTagNameDefinitions(customTypes);
275  return tagName;
276  } catch (TskCoreException ex) {
277  List<TagName> existingTagNames = caseDb.getAllTagNames();
278  for (TagName tagName : existingTagNames) {
279  if (tagName.getDisplayName().equals(displayName)) {
280  throw new TagNameAlreadyExistsException();
281  }
282  }
283  throw ex;
284  }
285  }
286 
300  public ContentTag addContentTag(Content content, TagName tagName) throws TskCoreException {
301  return addContentTag(content, tagName, "", -1, -1);
302  }
303 
318  public ContentTag addContentTag(Content content, TagName tagName, String comment) throws TskCoreException {
319  return addContentTag(content, tagName, comment, -1, -1);
320  }
321 
338  public ContentTag addContentTag(Content content, TagName tagName, String comment, long beginByteOffset, long endByteOffset) throws TskCoreException {
339  ContentTag tag;
340  tag = caseDb.addContentTag(content, tagName, comment, beginByteOffset, endByteOffset);
341  try {
343  } catch (IllegalStateException ex) {
344  throw new TskCoreException("Added a tag to a closed case", ex);
345  }
346  return tag;
347  }
348 
357  public void deleteContentTag(ContentTag tag) throws TskCoreException {
358  caseDb.deleteContentTag(tag);
359  try {
361  } catch (IllegalStateException ex) {
362  throw new TskCoreException("Deleted a tag from a closed case", ex);
363  }
364  }
365 
374  public List<ContentTag> getAllContentTags() throws TskCoreException {
375  return caseDb.getAllContentTags();
376  }
377 
390  public long getContentTagsCountByTagName(TagName tagName) throws TskCoreException {
391  return caseDb.getContentTagsCountByTagName(tagName);
392  }
393 
404  public ContentTag getContentTagByTagID(long tagId) throws TskCoreException {
405  return caseDb.getContentTagByID(tagId);
406  }
407 
419  public List<ContentTag> getContentTagsByTagName(TagName tagName) throws TskCoreException {
420  return caseDb.getContentTagsByTagName(tagName);
421  }
422 
434  public List<ContentTag> getContentTagsByContent(Content content) throws TskCoreException {
435  return caseDb.getContentTagsByContent(content);
436  }
437 
451  public BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName) throws TskCoreException {
452  return addBlackboardArtifactTag(artifact, tagName, "");
453  }
454 
469  public BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName, String comment) throws TskCoreException {
470  BlackboardArtifactTag tag = caseDb.addBlackboardArtifactTag(artifact, tagName, comment);
471  try {
473  } catch (IllegalStateException ex) {
474  throw new TskCoreException("Added a tag to a closed case", ex);
475  }
476  return tag;
477  }
478 
487  public void deleteBlackboardArtifactTag(BlackboardArtifactTag tag) throws TskCoreException {
488  caseDb.deleteBlackboardArtifactTag(tag);
489  try {
491  } catch (IllegalStateException ex) {
492  throw new TskCoreException("Deleted a tag from a closed case", ex);
493  }
494  }
495 
504  public List<BlackboardArtifactTag> getAllBlackboardArtifactTags() throws TskCoreException {
505  return caseDb.getAllBlackboardArtifactTags();
506  }
507 
520  public long getBlackboardArtifactTagsCountByTagName(TagName tagName) throws TskCoreException {
521  return caseDb.getBlackboardArtifactTagsCountByTagName(tagName);
522  }
523 
534  public BlackboardArtifactTag getBlackboardArtifactTagByTagID(long tagId) throws TskCoreException {
535  return caseDb.getBlackboardArtifactTagByID(tagId);
536  }
537 
551  public List<BlackboardArtifactTag> getBlackboardArtifactTagsByTagName(TagName tagName) throws TskCoreException {
552  return caseDb.getBlackboardArtifactTagsByTagName(tagName);
553  }
554 
566  public List<BlackboardArtifactTag> getBlackboardArtifactTagsByArtifact(BlackboardArtifact artifact) throws TskCoreException {
567  return caseDb.getBlackboardArtifactTagsByArtifact(artifact);
568  }
569 
573  public static class TagNameAlreadyExistsException extends Exception {
574 
575  private static final long serialVersionUID = 1L;
576  }
577 
588  @Deprecated
589  public boolean tagNameExists(String tagDisplayName) {
590  try {
591  Map<String, TagName> tagNames = getDisplayNamesToTagNamesMap();
592  return tagNames.containsKey(tagDisplayName) && (tagNames.get(tagDisplayName) != null);
593  } catch (TskCoreException ex) {
594  LOGGER.log(Level.SEVERE, "Error querying case database for tag names", ex);
595  return false;
596  }
597  }
598 
605  @Deprecated
606  @Override
607  public void close() throws IOException {
608  }
609 
610 }
void notifyContentTagDeleted(ContentTag deletedTag)
Definition: Case.java:1480
void notifyBlackBoardArtifactTagDeleted(BlackboardArtifactTag deletedTag)
Definition: Case.java:1514
synchronized TagName addTagName(String displayName)
List< ContentTag > getContentTagsByContent(Content content)
BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName)
synchronized TagName addTagName(String displayName, String description, TagName.HTML_COLOR color)
static boolean containsIllegalCharacters(String tagDisplayName)
ContentTag addContentTag(Content content, TagName tagName)
void deleteBlackboardArtifactTag(BlackboardArtifactTag tag)
BlackboardArtifactTag getBlackboardArtifactTagByTagID(long tagId)
ContentTag addContentTag(Content content, TagName tagName, String comment, long beginByteOffset, long endByteOffset)
synchronized TagName addTagName(String displayName, String description)
List< BlackboardArtifactTag > getAllBlackboardArtifactTags()
void notifyBlackBoardArtifactTagAdded(BlackboardArtifactTag newTag)
Definition: Case.java:1503
List< BlackboardArtifactTag > getBlackboardArtifactTagsByTagName(TagName tagName)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161
void notifyContentTagAdded(ContentTag newTag)
Definition: Case.java:1469
List< ContentTag > getContentTagsByTagName(TagName tagName)
synchronized TagName addTagName(String displayName, String description, TagName.HTML_COLOR color, TskData.FileKnown knownStatus)
ContentTag addContentTag(Content content, TagName tagName, String comment)
BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName, String comment)
List< BlackboardArtifactTag > getBlackboardArtifactTagsByArtifact(BlackboardArtifact artifact)

Copyright © 2012-2016 Basis Technology. Generated on: Sun Jan 21 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.