Autopsy  4.12.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  @Messages({"CorrelationAttributeInstance.nullName.message=Database name is null.",
280  "CorrelationAttributeInstance.invalidName.message=Invalid database table name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."})
281  public Type(int typeId, String displayName, String dbTableName, Boolean supported, Boolean enabled) throws EamDbException {
282  if (dbTableName == null) {
283  throw new EamDbException(Bundle.CorrelationAttributeInstance_nullName_message());
284  }
285  this.typeId = typeId;
286  this.displayName = displayName;
287  this.dbTableName = dbTableName;
288  this.supported = supported;
289  this.enabled = enabled;
290  if (!Pattern.matches(DB_NAMES_REGEX, dbTableName)) {
291  throw new EamDbException(Bundle.CorrelationAttributeInstance_invalidName_message()); // NON-NLS
292  }
293  }
294 
308  public Type(String displayName, String dbTableName, Boolean supported, Boolean enabled) throws EamDbException {
309  this(-1, displayName, dbTableName, supported, enabled);
310  }
311 
319  @Override
320  public boolean equals(Object that) {
321  if (this == that) {
322  return true;
323  } else if (!(that instanceof CorrelationAttributeInstance.Type)) {
324  return false;
325  } else {
326  return ((CorrelationAttributeInstance.Type) that).sameType(this);
327  }
328  }
329 
339  return this.typeId == that.getId()
340  && Objects.equals(this.supported, that.isSupported())
341  && Objects.equals(this.enabled, that.isEnabled());
342  }
343 
344  @Override
345  public int hashCode() {
346  int hash = 7;
347  hash = 67 * hash + Objects.hashCode(this.typeId);
348  hash = 67 * hash + Objects.hashCode(this.supported);
349  hash = 67 * hash + Objects.hashCode(this.enabled);
350  return hash;
351  }
352 
353  @Override
354  public String toString() {
355  StringBuilder str = new StringBuilder(55);
356  str.append("(id=")
357  .append(getId())
358  .append(", displayName=")
359  .append(getDisplayName())
360  .append(", dbTableName=")
361  .append(getDbTableName())
362  .append(", supported=")
363  .append(isSupported().toString())
364  .append(", enabled=")
365  .append(isEnabled().toString())
366  .append(')');
367  return str.toString();
368  }
369 
373  public int getId() {
374  return typeId;
375  }
376 
380  public void setId(int typeId) {
381  this.typeId = typeId;
382  }
383 
389  public Boolean isSupported() {
390  return supported;
391  }
392 
398  public void setSupported(Boolean supported) {
399  this.supported = supported;
400  }
401 
407  public Boolean isEnabled() {
408  return enabled;
409  }
410 
416  public void setEnabled(Boolean enabled) {
417  this.enabled = enabled;
418  }
419 
423  public String getDisplayName() {
424  return displayName;
425  }
426 
430  public void setDisplayName(String displayName) {
431  this.displayName = displayName;
432  }
433 
449  public String getDbTableName() {
450  return dbTableName;
451  }
452 
473  public void setDbTableName(String dbTableName) throws EamDbException {
474  if (!Pattern.matches(DB_NAMES_REGEX, dbTableName)) {
475  throw new EamDbException("Invalid database table name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."); // NON-NLS
476  }
477  this.dbTableName = dbTableName;
478  }
479  }
480 }
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: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.