Sleuth Kit Java Bindings (JNI)  4.11.0
Java bindings for using The Sleuth Kit
OsAccountInstance.java
Go to the documentation of this file.
1 /*
2  * Sleuth Kit Data Model
3  *
4  * Copyright 2021 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.datamodel;
20 
21 import java.util.Objects;
22 import java.util.ResourceBundle;
23 
28 public class OsAccountInstance implements Comparable<OsAccountInstance> {
29 
30  private static final ResourceBundle bundle = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle");
31 
32  private final SleuthkitCase skCase;
33  private final long instanceId;
34  private final long accountId;
35  private final long dataSourceId;
36  private final OsAccountInstanceType instanceType;
37 
38  private OsAccount account;
39  private DataSource dataSource;
40 
53  OsAccountInstance(SleuthkitCase skCase, long instanceId, OsAccount account, long dataSourceId, OsAccountInstanceType instanceType) {
54  this(skCase, instanceId, account.getId(), dataSourceId, instanceType);
55  this.account = account;
56  }
57 
69  OsAccountInstance(SleuthkitCase skCase, long instanceId, long accountObjId, long dataSourceObjId, OsAccountInstanceType instanceType) {
70  this.skCase = skCase;
71  this.instanceId = instanceId;
72  this.accountId = accountObjId;
73  this.dataSourceId = dataSourceObjId;
74  this.instanceType = instanceType;
75  }
76 
82  public long getInstanceId() {
83  return instanceId;
84  }
85 
95  if (account == null) {
96  try {
97  account = skCase.getOsAccountManager().getOsAccountByObjectId(accountId);
98  } catch (TskCoreException ex) {
99  throw new TskCoreException(String.format("Failed to get OsAccount for id %d", accountId), ex);
100  }
101  }
102 
103  return account;
104  }
105 
114  if (dataSource == null) {
115  try {
116  dataSource = skCase.getDataSource(dataSourceId);
117  } catch (TskDataException ex) {
118  throw new TskCoreException(String.format("Failed to get DataSource for id %d", dataSourceId), ex);
119  }
120  }
121 
122  return dataSource;
123  }
124 
131  return instanceType;
132  }
133 
139  private long getDataSourceId() {
140  return dataSourceId;
141  }
142 
143  @Override
144  public int compareTo(OsAccountInstance other) {
145  if (equals(other)) {
146  return 0;
147  }
148 
149  if (dataSourceId != other.getDataSourceId()) {
150  return Long.compare(dataSourceId, other.getDataSourceId());
151  }
152 
153  return Long.compare(accountId, other.accountId);
154  }
155 
156  @Override
157  public boolean equals(Object obj) {
158  if (this == obj) {
159  return true;
160  }
161  if (obj == null) {
162  return false;
163  }
164  if (getClass() != obj.getClass()) {
165  return false;
166  }
167  final OsAccountInstance other = (OsAccountInstance) obj;
168  if (this.accountId != other.accountId) {
169  return false;
170  }
171  return this.dataSourceId == other.getDataSourceId();
172  }
173 
174  @Override
175  public int hashCode() {
176  int hash = 7;
177  hash = 67 * hash + Objects.hashCode(this.dataSourceId);
178  hash = 67 * hash + Objects.hashCode(this.accountId);
179  hash = 67 * hash + Objects.hashCode(this.instanceType);
180  return hash;
181  }
182 
190  public enum OsAccountInstanceType {
191  LAUNCHED(0, bundle.getString("OsAccountInstanceType.Launched.text"), bundle.getString("OsAccountInstanceType.Launched.descr.text")), // the user launched a program on the host
192  ACCESSED(1, bundle.getString("OsAccountInstanceType.Accessed.text"), bundle.getString("OsAccountInstanceType.Accessed.descr.text")), // user accesed a resource for read/write
193  REFERENCED(2, bundle.getString("OsAccountInstanceType.Referenced.text"), bundle.getString("OsAccountInstanceType.Referenced.descr.text")); // user was referenced, e.g. in a event log.
194 
195  private final int id;
196  private final String name;
197  private final String description;
198 
199  OsAccountInstanceType(int id, String name, String description) {
200  this.id = id;
201  this.name = name;
202  this.description = description;
203  }
204 
210  public int getId() {
211  return id;
212  }
213 
219  public String getName() {
220  return name;
221  }
222 
228  public String getDescription() {
229  return description;
230  }
231 
239  public static OsAccountInstanceType fromID(int typeId) {
240  for (OsAccountInstanceType statusType : OsAccountInstanceType.values()) {
241  if (statusType.ordinal() == typeId) {
242  return statusType;
243  }
244  }
245  return null;
246  }
247  }
248 }
OsAccount getOsAccountByObjectId(long osAccountObjId)
DataSource getDataSource(long objectId)
OsAccountInstanceType(int id, String name, String description)

Copyright © 2011-2021 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.