Autopsy  4.8.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CorrelationAttributeInstance.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2015-2018 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.centralrepository.datamodel;
20 
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.Objects;
25 import java.util.regex.Pattern;
26 import org.openide.util.NbBundle.Messages;
27 import org.sleuthkit.datamodel.TskData;
28 
35 @Messages({
36  "EamArtifactInstances.knownStatus.bad=Bad",
37  "EamArtifactInstances.knownStatus.known=Known",
38  "EamArtifactInstances.knownStatus.unknown=Unknown"})
39 public class CorrelationAttributeInstance implements Serializable {
40 
41  private static final long serialVersionUID = 1L;
42 
43  private int ID;
44  private String correlationValue;
48  private String filePath;
49  private String comment;
50  private TskData.FileKnown knownStatus;
51 
53  String correlationValue,
54  CorrelationAttributeInstance.Type correlationType,
55  CorrelationCase eamCase,
56  CorrelationDataSource eamDataSource,
57  String filePath
59  this(correlationType, correlationValue, -1, eamCase, eamDataSource, filePath, null, TskData.FileKnown.UNKNOWN);
60  }
61 
63  String correlationValue,
64  CorrelationAttributeInstance.Type correlationType,
65  CorrelationCase eamCase,
66  CorrelationDataSource eamDataSource,
67  String filePath,
68  String comment,
69  TskData.FileKnown knownStatus
71  this(correlationType, correlationValue, -1, eamCase, eamDataSource, filePath, comment, knownStatus);
72  }
73 
75  Type correlationType,
76  String correlationValue,
77  CorrelationCase correlationCase,
78  CorrelationDataSource fromTSKDataSource,
80  this(correlationType, correlationValue, -1, correlationCase, fromTSKDataSource, string, "", TskData.FileKnown.UNKNOWN);
81  }
82 
90  this(aType, value, -1, null, null, "", "", TskData.FileKnown.UNKNOWN);
91  }
92 
94  Type type,
95  String value,
96  int instanceId,
97  CorrelationCase eamCase,
98  CorrelationDataSource eamDataSource,
99  String filePath,
100  String comment,
101  TskData.FileKnown knownStatus
103  if (filePath == null) {
104  throw new EamDbException("file path is null");
105  }
106 
107  this.correlationType = type;
108  this.correlationValue = CorrelationAttributeNormalizer.normalize(type, value);
109  this.ID = instanceId;
110  this.correlationCase = eamCase;
111  this.correlationDataSource = eamDataSource;
112  // Lower case paths to normalize paths and improve correlation results, if this causes significant issues on case-sensitive file systems, remove
113  this.filePath = filePath.toLowerCase();
114  this.comment = comment;
115  this.knownStatus = knownStatus;
116  }
117 
118  public Boolean equals(CorrelationAttributeInstance otherInstance) {
119  return ((this.getID() == otherInstance.getID())
120  && (this.getCorrelationValue().equals(otherInstance.getCorrelationValue()))
121  && (this.getCorrelationType().equals(otherInstance.getCorrelationType()))
122  && (this.getCorrelationCase().equals(otherInstance.getCorrelationCase()))
123  && (this.getCorrelationDataSource().equals(otherInstance.getCorrelationDataSource()))
124  && (this.getFilePath().equals(otherInstance.getFilePath()))
125  && (this.getKnownStatus().equals(otherInstance.getKnownStatus()))
126  && (this.getComment().equals(otherInstance.getComment())));
127  }
128 
129  @Override
130  public String toString() {
131  return this.getID()
132  + this.getCorrelationCase().getCaseUUID()
133  + this.getCorrelationDataSource().getDeviceID()
134  + this.getFilePath()
135  + this.getCorrelationType().toString()
136  + this.getCorrelationValue()
137  + this.getKnownStatus()
138  + this.getComment();
139  }
140 
144  public String getCorrelationValue() {
145  return correlationValue;
146  }
147 
151  public void setCorrelationValue(String correlationValue) {
152  // Lower-case all values to normalize and improve correlation hits, going forward make sure this makes sense for all correlation types
153  this.correlationValue = correlationValue.toLowerCase();
154  }
155 
160  return correlationType;
161  }
162 
166  public void setCorrelationType(Type correlationType) {
167  this.correlationType = correlationType;
168  }
169 
176  public boolean isDatabaseInstance() {
177  return (ID >= 0);
178  }
179 
183  public int getID() {
184  return ID;
185  }
186 
191  return correlationCase;
192  }
193 
198  return correlationDataSource;
199  }
200 
204  public String getFilePath() {
205  return filePath;
206  }
207 
211  public String getComment() {
212  return null == comment ? "" : comment;
213  }
214 
218  public void setComment(String comment) {
219  this.comment = comment;
220  }
221 
228  public TskData.FileKnown getKnownStatus() {
229  return knownStatus;
230  }
231 
239  public void setKnownStatus(TskData.FileKnown knownStatus) {
240  this.knownStatus = knownStatus;
241  }
242 
243  // Type ID's for Default Correlation Types
244  public static final int FILES_TYPE_ID = 0;
245  public static final int DOMAIN_TYPE_ID = 1;
246  public static final int EMAIL_TYPE_ID = 2;
247  public static final int PHONE_TYPE_ID = 3;
248  public static final int USBID_TYPE_ID = 4;
249 
256  @Messages({"CorrelationType.FILES.displayName=Files",
257  "CorrelationType.DOMAIN.displayName=Domains",
258  "CorrelationType.EMAIL.displayName=Email Addresses",
259  "CorrelationType.PHONE.displayName=Phone Numbers",
260  "CorrelationType.USBID.displayName=USB Devices"})
261  public static List<CorrelationAttributeInstance.Type> getDefaultCorrelationTypes() throws EamDbException {
262  List<CorrelationAttributeInstance.Type> DEFAULT_CORRELATION_TYPES = new ArrayList<>();
263  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(FILES_TYPE_ID, Bundle.CorrelationType_FILES_displayName(), "file", true, true)); // NON-NLS
264  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(DOMAIN_TYPE_ID, Bundle.CorrelationType_DOMAIN_displayName(), "domain", true, true)); // NON-NLS
265  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(EMAIL_TYPE_ID, Bundle.CorrelationType_EMAIL_displayName(), "email_address", true, true)); // NON-NLS
266  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(PHONE_TYPE_ID, Bundle.CorrelationType_PHONE_displayName(), "phone_number", true, true)); // NON-NLS
267  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(USBID_TYPE_ID, Bundle.CorrelationType_USBID_displayName(), "usb_devices", true, true)); // NON-NLS
268  return DEFAULT_CORRELATION_TYPES;
269  }
270 
274  @SuppressWarnings("serial")
275  public static class Type implements Serializable { // NOPMD Avoid short class names like Type
276 
277  private int typeId;
278  private String displayName;
279  private String dbTableName;
280  private Boolean supported;
281  private Boolean enabled;
282  private final static String DB_NAMES_REGEX = "[a-z][a-z0-9_]*";
283 
294  public Type(int typeId, String displayName, String dbTableName, Boolean supported, Boolean enabled) throws EamDbException {
295  if (dbTableName == null) {
296  throw new EamDbException("dbTableName is null");
297  }
298  this.typeId = typeId;
299  this.displayName = displayName;
300  this.dbTableName = dbTableName;
301  this.supported = supported;
302  this.enabled = enabled;
303  if (!Pattern.matches(DB_NAMES_REGEX, dbTableName)) {
304  throw new EamDbException("Invalid database table name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."); // NON-NLS
305  }
306  }
307 
320  public Type(String displayName, String dbTableName, Boolean supported, Boolean enabled) throws EamDbException {
321  this(-1, displayName, dbTableName, supported, enabled);
322  }
323 
331  @Override
332  public boolean equals(Object that) {
333  if (this == that) {
334  return true;
335  } else if (!(that instanceof CorrelationAttributeInstance.Type)) {
336  return false;
337  } else {
338  return ((CorrelationAttributeInstance.Type) that).sameType(this);
339  }
340  }
341 
351  return this.typeId == that.getId()
352  && Objects.equals(this.supported, that.isSupported())
353  && Objects.equals(this.enabled, that.isEnabled());
354  }
355 
356  @Override
357  public int hashCode() {
358  int hash = 7;
359  hash = 67 * hash + Objects.hashCode(this.typeId);
360  hash = 67 * hash + Objects.hashCode(this.supported);
361  hash = 67 * hash + Objects.hashCode(this.enabled);
362  return hash;
363  }
364 
365  @Override
366  public String toString() {
367  StringBuilder str = new StringBuilder(55);
368  str.append("(id=")
369  .append(getId())
370  .append(", displayName=")
371  .append(getDisplayName())
372  .append(", dbTableName=")
373  .append(getDbTableName())
374  .append(", supported=")
375  .append(isSupported().toString())
376  .append(", enabled=")
377  .append(isEnabled().toString())
378  .append(')');
379  return str.toString();
380  }
381 
385  public int getId() {
386  return typeId;
387  }
388 
392  public void setId(int typeId) {
393  this.typeId = typeId;
394  }
395 
401  public Boolean isSupported() {
402  return supported;
403  }
404 
410  public void setSupported(Boolean supported) {
411  this.supported = supported;
412  }
413 
419  public Boolean isEnabled() {
420  return enabled;
421  }
422 
428  public void setEnabled(Boolean enabled) {
429  this.enabled = enabled;
430  }
431 
435  public String getDisplayName() {
436  return displayName;
437  }
438 
442  public void setDisplayName(String displayName) {
443  this.displayName = displayName;
444  }
445 
461  public String getDbTableName() {
462  return dbTableName;
463  }
464 
485  public void setDbTableName(String dbTableName) throws EamDbException {
486  if (!Pattern.matches(DB_NAMES_REGEX, dbTableName)) {
487  throw new EamDbException("Invalid database table name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."); // NON-NLS
488  }
489  this.dbTableName = dbTableName;
490  }
491  }
492 }
Type(String displayName, String dbTableName, Boolean supported, Boolean enabled)
CorrelationAttributeInstance(Type correlationType, String correlationValue, CorrelationCase correlationCase, CorrelationDataSource fromTSKDataSource, String string)
CorrelationAttributeInstance(String correlationValue, CorrelationAttributeInstance.Type correlationType, CorrelationCase eamCase, CorrelationDataSource eamDataSource, String filePath, String comment, TskData.FileKnown knownStatus)
CorrelationAttributeInstance(String correlationValue, CorrelationAttributeInstance.Type correlationType, CorrelationCase eamCase, CorrelationDataSource eamDataSource, String filePath)
Type(int typeId, String displayName, String dbTableName, Boolean supported, Boolean enabled)

Copyright © 2012-2018 Basis Technology. Generated on: Thu Oct 4 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.