Autopsy  4.11.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  private Long objectId;
52 
54  CorrelationAttributeInstance.Type correlationType,
55  String correlationValue,
56  CorrelationCase eamCase,
57  CorrelationDataSource eamDataSource,
58  String filePath,
59  String comment,
60  TskData.FileKnown knownStatus,
62  this(correlationType, correlationValue, -1, eamCase, eamDataSource, filePath, comment, knownStatus, fileObjectId);
63  }
64 
66  Type type,
67  String value,
68  int instanceId,
69  CorrelationCase eamCase,
70  CorrelationDataSource eamDataSource,
71  String filePath,
72  String comment,
73  TskData.FileKnown knownStatus,
74  Long fileObjectId
76  if (filePath == null) {
77  throw new EamDbException("file path is null");
78  }
79 
80  this.correlationType = type;
81  this.correlationValue = CorrelationAttributeNormalizer.normalize(type, value);
82  this.ID = instanceId;
83  this.correlationCase = eamCase;
84  this.correlationDataSource = eamDataSource;
85  // Lower case paths to normalize paths and improve correlation results, if this causes significant issues on case-sensitive file systems, remove
86  this.filePath = filePath.toLowerCase();
87  this.comment = comment;
88  this.knownStatus = knownStatus;
89  this.objectId = fileObjectId;
90  }
91 
92  public Boolean equals(CorrelationAttributeInstance otherInstance) {
93  return ((this.getID() == otherInstance.getID())
94  && (this.getCorrelationValue().equals(otherInstance.getCorrelationValue()))
95  && (this.getCorrelationType().equals(otherInstance.getCorrelationType()))
96  && (this.getCorrelationCase().equals(otherInstance.getCorrelationCase()))
97  && (this.getCorrelationDataSource().equals(otherInstance.getCorrelationDataSource()))
98  && (this.getFilePath().equals(otherInstance.getFilePath()))
99  && (this.getKnownStatus().equals(otherInstance.getKnownStatus()))
100  && (this.getComment().equals(otherInstance.getComment())));
101  }
102 
103  @Override
104  public String toString() {
105  return this.getID()
106  + this.getCorrelationCase().getCaseUUID()
107  + this.getCorrelationDataSource().getDeviceID()
108  + this.getFilePath()
109  + this.getCorrelationType().toString()
110  + this.getCorrelationValue()
111  + this.getKnownStatus()
112  + this.getComment();
113  }
114 
118  public String getCorrelationValue() {
119  return correlationValue;
120  }
121 
126  return correlationType;
127  }
128 
135  public boolean isDatabaseInstance() {
136  return (ID >= 0);
137  }
138 
142  public int getID() {
143  return ID;
144  }
145 
150  return correlationCase;
151  }
152 
157  return correlationDataSource;
158  }
159 
163  public String getFilePath() {
164  return filePath;
165  }
166 
170  public String getComment() {
171  return null == comment ? "" : comment;
172  }
173 
177  public void setComment(String comment) {
178  this.comment = comment;
179  }
180 
187  public TskData.FileKnown getKnownStatus() {
188  return knownStatus;
189  }
190 
198  public void setKnownStatus(TskData.FileKnown knownStatus) {
199  this.knownStatus = knownStatus;
200  }
201 
208  public Long getFileObjectId() {
209  return objectId;
210  }
211 
212  // Type ID's for Default Correlation Types
213  public static final int FILES_TYPE_ID = 0;
214  public static final int DOMAIN_TYPE_ID = 1;
215  public static final int EMAIL_TYPE_ID = 2;
216  public static final int PHONE_TYPE_ID = 3;
217  public static final int USBID_TYPE_ID = 4;
218  public static final int SSID_TYPE_ID = 5;
219  public static final int MAC_TYPE_ID = 6;
220  public static final int IMEI_TYPE_ID = 7;
221  public static final int IMSI_TYPE_ID = 8;
222  public static final int ICCID_TYPE_ID = 9;
223 
230  @Messages({"CorrelationType.FILES.displayName=Files",
231  "CorrelationType.DOMAIN.displayName=Domains",
232  "CorrelationType.EMAIL.displayName=Email Addresses",
233  "CorrelationType.PHONE.displayName=Phone Numbers",
234  "CorrelationType.USBID.displayName=USB Devices",
235  "CorrelationType.SSID.displayName=Wireless Networks",
236  "CorrelationType.MAC.displayName=MAC Addresses",
237  "CorrelationType.IMEI.displayName=IMEI Number",
238  "CorrelationType.IMSI.displayName=IMSI Number",
239  "CorrelationType.ICCID.displayName=ICCID Number"})
240  public static List<CorrelationAttributeInstance.Type> getDefaultCorrelationTypes() throws EamDbException {
241  List<CorrelationAttributeInstance.Type> DEFAULT_CORRELATION_TYPES = new ArrayList<>();
242  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(FILES_TYPE_ID, Bundle.CorrelationType_FILES_displayName(), "file", true, true)); // NON-NLS
243  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(DOMAIN_TYPE_ID, Bundle.CorrelationType_DOMAIN_displayName(), "domain", true, true)); // NON-NLS
244  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(EMAIL_TYPE_ID, Bundle.CorrelationType_EMAIL_displayName(), "email_address", true, true)); // NON-NLS
245  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(PHONE_TYPE_ID, Bundle.CorrelationType_PHONE_displayName(), "phone_number", true, true)); // NON-NLS
246  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(USBID_TYPE_ID, Bundle.CorrelationType_USBID_displayName(), "usb_devices", true, true)); // NON-NLS
247  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(SSID_TYPE_ID, Bundle.CorrelationType_SSID_displayName(), "wireless_networks", true, true)); // NON-NLS
248  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(MAC_TYPE_ID, Bundle.CorrelationType_MAC_displayName(), "mac_address", true, true)); //NON-NLS
249  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(IMEI_TYPE_ID, Bundle.CorrelationType_IMEI_displayName(), "imei_number", true, true)); //NON-NLS
250  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(IMSI_TYPE_ID, Bundle.CorrelationType_IMSI_displayName(), "imsi_number", true, true)); //NON-NLS
251  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttributeInstance.Type(ICCID_TYPE_ID, Bundle.CorrelationType_ICCID_displayName(), "iccid_number", true, true)); //NON-NLS
252  return DEFAULT_CORRELATION_TYPES;
253  }
254 
258  @SuppressWarnings("serial")
259  public static class Type implements Serializable { // NOPMD Avoid short class names like Type
260 
261  private int typeId;
262  private String displayName;
263  private String dbTableName;
264  private Boolean supported;
265  private Boolean enabled;
266  private final static String DB_NAMES_REGEX = "[a-z][a-z0-9_]*";
267 
279  public Type(int typeId, String displayName, String dbTableName, Boolean supported, Boolean enabled) throws EamDbException {
280  if (dbTableName == null) {
281  throw new EamDbException("dbTableName is null");
282  }
283  this.typeId = typeId;
284  this.displayName = displayName;
285  this.dbTableName = dbTableName;
286  this.supported = supported;
287  this.enabled = enabled;
288  if (!Pattern.matches(DB_NAMES_REGEX, dbTableName)) {
289  throw new EamDbException("Invalid database table name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."); // NON-NLS
290  }
291  }
292 
306  public Type(String displayName, String dbTableName, Boolean supported, Boolean enabled) throws EamDbException {
307  this(-1, displayName, dbTableName, supported, enabled);
308  }
309 
317  @Override
318  public boolean equals(Object that) {
319  if (this == that) {
320  return true;
321  } else if (!(that instanceof CorrelationAttributeInstance.Type)) {
322  return false;
323  } else {
324  return ((CorrelationAttributeInstance.Type) that).sameType(this);
325  }
326  }
327 
337  return this.typeId == that.getId()
338  && Objects.equals(this.supported, that.isSupported())
339  && Objects.equals(this.enabled, that.isEnabled());
340  }
341 
342  @Override
343  public int hashCode() {
344  int hash = 7;
345  hash = 67 * hash + Objects.hashCode(this.typeId);
346  hash = 67 * hash + Objects.hashCode(this.supported);
347  hash = 67 * hash + Objects.hashCode(this.enabled);
348  return hash;
349  }
350 
351  @Override
352  public String toString() {
353  StringBuilder str = new StringBuilder(55);
354  str.append("(id=")
355  .append(getId())
356  .append(", displayName=")
357  .append(getDisplayName())
358  .append(", dbTableName=")
359  .append(getDbTableName())
360  .append(", supported=")
361  .append(isSupported().toString())
362  .append(", enabled=")
363  .append(isEnabled().toString())
364  .append(')');
365  return str.toString();
366  }
367 
371  public int getId() {
372  return typeId;
373  }
374 
378  public void setId(int typeId) {
379  this.typeId = typeId;
380  }
381 
387  public Boolean isSupported() {
388  return supported;
389  }
390 
396  public void setSupported(Boolean supported) {
397  this.supported = supported;
398  }
399 
405  public Boolean isEnabled() {
406  return enabled;
407  }
408 
414  public void setEnabled(Boolean enabled) {
415  this.enabled = enabled;
416  }
417 
421  public String getDisplayName() {
422  return displayName;
423  }
424 
428  public void setDisplayName(String displayName) {
429  this.displayName = displayName;
430  }
431 
447  public String getDbTableName() {
448  return dbTableName;
449  }
450 
471  public void setDbTableName(String dbTableName) throws EamDbException {
472  if (!Pattern.matches(DB_NAMES_REGEX, dbTableName)) {
473  throw new EamDbException("Invalid database table name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."); // NON-NLS
474  }
475  this.dbTableName = dbTableName;
476  }
477  }
478 }
Type(String displayName, String dbTableName, Boolean supported, Boolean enabled)
Type(int typeId, String displayName, String dbTableName, Boolean supported, Boolean enabled)
CorrelationAttributeInstance(CorrelationAttributeInstance.Type correlationType, String correlationValue, CorrelationCase eamCase, CorrelationDataSource eamDataSource, String filePath, String comment, TskData.FileKnown knownStatus, long fileObjectId)

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