Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CorrelationAttribute.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2015-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.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 
33 public class CorrelationAttribute implements Serializable {
34 
35  private static final long serialVersionUID = 1L;
36 
37  private String ID;
38  private String correlationValue;
40  private final List<CorrelationAttributeInstance> artifactInstances;
41 
42  // Type ID's for Default Correlation Types
43  public static final int FILES_TYPE_ID = 0;
44  public static final int DOMAIN_TYPE_ID = 1;
45  public static final int EMAIL_TYPE_ID = 2;
46  public static final int PHONE_TYPE_ID = 3;
47  public static final int USBID_TYPE_ID = 4;
48 
54  @Messages({"CorrelationType.FILES.displayName=Files",
55  "CorrelationType.DOMAIN.displayName=Domains",
56  "CorrelationType.EMAIL.displayName=Email Addresses",
57  "CorrelationType.PHONE.displayName=Phone Numbers",
58  "CorrelationType.USBID.displayName=USB Devices"})
59  public static List<CorrelationAttribute.Type> getDefaultCorrelationTypes() throws EamDbException {
60  List<CorrelationAttribute.Type> DEFAULT_CORRELATION_TYPES = new ArrayList<>();
61  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttribute.Type(FILES_TYPE_ID, Bundle.CorrelationType_FILES_displayName(), "file", true, true)); // NON-NLS
62  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttribute.Type(DOMAIN_TYPE_ID, Bundle.CorrelationType_DOMAIN_displayName(), "domain", true, true)); // NON-NLS
63  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttribute.Type(EMAIL_TYPE_ID, Bundle.CorrelationType_EMAIL_displayName(), "email_address", true, true)); // NON-NLS
64  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttribute.Type(PHONE_TYPE_ID, Bundle.CorrelationType_PHONE_displayName(), "phone_number", true, true)); // NON-NLS
65  DEFAULT_CORRELATION_TYPES.add(new CorrelationAttribute.Type(USBID_TYPE_ID, Bundle.CorrelationType_USBID_displayName(), "usb_devices", true, true)); // NON-NLS
66  return DEFAULT_CORRELATION_TYPES;
67  }
68 
69  public CorrelationAttribute(Type correlationType, String correlationValue) throws EamDbException {
70  if(correlationValue == null) {
71  throw new EamDbException ("Correlation value is null");
72  }
73  this.ID = "";
74  this.correlationType = correlationType;
75  // Lower-case all values to normalize and improve correlation hits, going forward make sure this makes sense for all correlation types
76  this.correlationValue = correlationValue.toLowerCase();
77  this.artifactInstances = new ArrayList<>();
78  }
79 
80  public Boolean equals(CorrelationAttribute otherArtifact) {
81  return ((this.getID().equals(otherArtifact.getID()))
82  && (this.getCorrelationType().equals(otherArtifact.getCorrelationType()))
83  && (this.getCorrelationValue().equals(otherArtifact.getCorrelationValue()))
84  && (this.getInstances().equals(otherArtifact.getInstances())));
85  }
86 
87  @Override
88  public String toString() {
89  // NOTE: This string is currently being used in IngestEventsListener to detect if we have already seen
90  // the value and type pair. Be careful if this method is changed.
91  String result = this.getID()
92  + this.getCorrelationType().toString()
93  + this.getCorrelationValue();
94  result = this.getInstances().stream().map((inst) -> inst.toString()).reduce(result, String::concat);
95  return result;
96  }
97 
101  public String getID() {
102  return ID;
103  }
104 
108  public void setID(String ID) {
109  this.ID = ID;
110  }
111 
115  public String getCorrelationValue() {
116  return correlationValue;
117  }
118 
122  public void setCorrelationValue(String correlationValue) {
123  // Lower-case all values to normalize and improve correlation hits, going forward make sure this makes sense for all correlation types
124  this.correlationValue = correlationValue.toLowerCase();
125  }
126 
131  return correlationType;
132  }
133 
137  public void setCorrelationType(Type correlationType) {
138  this.correlationType = correlationType;
139  }
140 
145  public List<CorrelationAttributeInstance> getInstances() {
146  return new ArrayList<>(artifactInstances);
147  }
148 
154  public void setInstances(List<CorrelationAttributeInstance> artifactInstances) {
155  this.artifactInstances.clear();
156  if (null != artifactInstances) {
157  this.artifactInstances.addAll(artifactInstances);
158  }
159  }
160 
166  public void addInstance(CorrelationAttributeInstance artifactInstance) {
167  this.artifactInstances.add(artifactInstance);
168  }
169 
170  public static class Type implements Serializable {
171 
172  private int id;
173  private String displayName;
174  private String dbTableName;
175  private Boolean supported;
176  private Boolean enabled;
177  private final String DB_NAMES_REGEX = "[a-z][a-z0-9_]*";
178 
189  public Type(int id, String displayName, String dbTableName, Boolean supported, Boolean enabled) throws EamDbException {
190  if(dbTableName == null) {
191  throw new EamDbException("dbTableName is null");
192  }
193  this.id = id;
194  this.displayName = displayName;
195  this.dbTableName = dbTableName;
196  this.supported = supported;
197  this.enabled = enabled;
198  if (!Pattern.matches(DB_NAMES_REGEX, dbTableName)) {
199  throw new EamDbException("Invalid database table name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."); // NON-NLS
200  }
201  }
202 
215  public Type(String displayName, String dbTableName, Boolean supported, Boolean enabled) throws EamDbException {
217  }
218 
226  @Override
227  public boolean equals(Object that) {
228  if (this == that) {
229  return true;
230  } else if (!(that instanceof CorrelationAttribute.Type)) {
231  return false;
232  } else {
233  return ((CorrelationAttribute.Type) that).sameType(this);
234  }
235  }
236 
245  private boolean sameType(CorrelationAttribute.Type that) {
246  return this.id == that.getId()
247  && Objects.equals(this.supported, that.isSupported())
248  && Objects.equals(this.enabled, that.isEnabled());
249  }
250 
251  @Override
252  public int hashCode() {
253  int hash = 7;
254  hash = 67 * hash + Objects.hashCode(this.id);
255  hash = 67 * hash + Objects.hashCode(this.supported);
256  hash = 67 * hash + Objects.hashCode(this.enabled);
257  return hash;
258  }
259 
260  @Override
261  public String toString() {
262  StringBuilder str = new StringBuilder();
263  str.append("(id=").append(getId());
264  str.append(", displayName=").append(getDisplayName());
265  str.append(", dbTableName=").append(getDbTableName());
266  str.append(", supported=").append(isSupported().toString());
267  str.append(", enabled=").append(isEnabled().toString());
268  str.append(")");
269  return str.toString();
270  }
271 
275  public int getId() {
276  return id;
277  }
278 
282  public void setId(int id) {
283  this.id = id;
284  }
285 
291  public Boolean isSupported() {
292  return supported;
293  }
294 
300  public void setSupported(Boolean supported) {
301  this.supported = supported;
302  }
303 
309  public Boolean isEnabled() {
310  return enabled;
311  }
312 
318  public void setEnabled(Boolean enabled) {
319  this.enabled = enabled;
320  }
321 
325  public String getDisplayName() {
326  return displayName;
327  }
328 
332  public void setDisplayName(String displayName) {
333  this.displayName = displayName;
334  }
335 
351  public String getDbTableName() {
352  return dbTableName;
353  }
354 
373  public void setDbTableName(String dbTableName) throws EamDbException {
374  if (!Pattern.matches(DB_NAMES_REGEX, dbTableName)) {
375  throw new EamDbException("Invalid database table name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."); // NON-NLS
376  }
377  this.dbTableName = dbTableName;
378  }
379  }
380 }
Type(int id, String displayName, String dbTableName, Boolean supported, Boolean enabled)
void setInstances(List< CorrelationAttributeInstance > artifactInstances)
void addInstance(CorrelationAttributeInstance artifactInstance)
Type(String displayName, String dbTableName, Boolean supported, Boolean enabled)

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