Sleuth Kit Java Bindings (JNI)  4.11.0
Java bindings for using The Sleuth Kit
OsAccount.java
Go to the documentation of this file.
1 /*
2  * Sleuth Kit Data Model
3  *
4  * Copyright 2020-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.Collections;
22 import java.util.List;
23 import java.util.Optional;
24 import java.util.ResourceBundle;
25 
35 public final class OsAccount extends AbstractContent {
36 
37  private static final ResourceBundle bundle = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle");
38 
39  final static Long NO_ACCOUNT = null;
40  final static String NO_OWNER_ID = null;
41 
42  private final SleuthkitCase sleuthkitCase;
43 
44  private final long osAccountObjId; // Object ID within the database
45  private final long realmId; // realm where the account exists in (could be local or domain scoped)
46  private final String loginName; // user login name - may be null
47  private final String addr; // a unique user sid/uid, may be null
48 
49  private final String signature; // This exists only to prevent duplicates.
50  // Together realm_id & signature must be unique for each account.
51  // It is either addr if addr is defined,
52  // or the login_name if login_name is defined.
53 
54  private final String fullName; // full name, may be null
55  private final OsAccountType osAccountType;
56  private final OsAccountStatus osAccountStatus;
57  private final OsAccountDbStatus osAccountDbStatus; // Status of row in the database
58  private final Long creationTime;
59 
60  private List<OsAccountAttribute> osAccountAttributes = null;
61 
66  public enum OsAccountStatus {
67  UNKNOWN(0, bundle.getString("OsAccountStatus.Unknown.text")),
68  ACTIVE(1, bundle.getString("OsAccountStatus.Active.text")),
69  DISABLED(2, bundle.getString("OsAccountStatus.Disabled.text")),
70  DELETED(3, bundle.getString("OsAccountStatus.Deleted.text"));
71 
72  private final int id;
73  private final String name;
74 
75  OsAccountStatus(int id, String name) {
76  this.id = id;
77  this.name = name;
78  }
79 
85  public int getId() {
86  return id;
87  }
88 
94  public String getName() {
95  return name;
96  }
97 
105  public static OsAccountStatus fromID(int statusId) {
106  for (OsAccountStatus statusType : OsAccountStatus.values()) {
107  if (statusType.ordinal() == statusId) {
108  return statusType;
109  }
110  }
111  return null;
112  }
113  }
114 
120  enum OsAccountDbStatus {
121  ACTIVE(0, "Active"),
122  MERGED(1, "Merged"),
123  DELETED(2, "Deleted");
124 
125  private final int id;
126  private final String name;
127 
128  OsAccountDbStatus(int id, String name) {
129  this.id = id;
130  this.name = name;
131  }
132 
133  int getId() {
134  return id;
135  }
136 
137  String getName() {
138  return name;
139  }
140 
141  static OsAccountDbStatus fromID(int typeId) {
142  for (OsAccountDbStatus type : OsAccountDbStatus.values()) {
143  if (type.ordinal() == typeId) {
144  return type;
145  }
146  }
147  return null;
148  }
149  }
150 
155  public enum OsAccountType {
156  UNKNOWN(0, bundle.getString("OsAccountType.Unknown.text")),
157  SERVICE(1, bundle.getString("OsAccountType.Service.text")),
158  INTERACTIVE(2, bundle.getString("OsAccountType.Interactive.text"));
159 
160  private final int id;
161  private final String name;
162 
163  OsAccountType(int id, String name) {
164  this.id = id;
165  this.name = name;
166  }
167 
173  public int getId() {
174  return id;
175  }
176 
182  public String getName() {
183  return name;
184  }
185 
193  public static OsAccountType fromID(int typeId) {
194  for (OsAccountType accountType : OsAccountType.values()) {
195  if (accountType.ordinal() == typeId) {
196  return accountType;
197  }
198  }
199  return null;
200  }
201  }
202 
222  OsAccount(SleuthkitCase sleuthkitCase, long osAccountobjId, long realmId, String loginName, String uniqueId, String signature,
223  String fullName, Long creationTime, OsAccountType accountType, OsAccountStatus accountStatus, OsAccountDbStatus accountDbStatus) {
224 
225  super(sleuthkitCase, osAccountobjId, signature);
226 
227  this.sleuthkitCase = sleuthkitCase;
228  this.osAccountObjId = osAccountobjId;
229  this.realmId = realmId;
230  this.loginName = loginName;
231  this.addr = uniqueId;
232  this.signature = signature;
233  this.fullName = fullName;
234  this.creationTime = creationTime;
235  this.osAccountType = accountType;
236  this.osAccountStatus = accountStatus;
237  this.osAccountDbStatus = accountDbStatus;
238  }
239 
246  synchronized void setAttributesInternal(List<OsAccountAttribute> osAccountAttributes) {
247  this.osAccountAttributes = osAccountAttributes;
248  }
249 
256  public long getId() {
257  return osAccountObjId;
258  }
259 
266  public Optional<String> getAddr() {
267  return Optional.ofNullable(addr);
268  }
269 
277  public long getRealmId() {
278  return realmId;
279  }
280 
286  public Optional<String> getLoginName() {
287  return Optional.ofNullable(loginName);
288  }
289 
295  String getSignature() {
296  return signature;
297  }
298 
304  public Optional<String> getFullName() {
305  return Optional.ofNullable(fullName);
306  }
307 
313  public Optional<Long> getCreationTime() {
314  return Optional.ofNullable(creationTime);
315  }
316 
322  public Optional<OsAccountType> getOsAccountType() {
323  return Optional.ofNullable(osAccountType);
324  }
325 
331  public Optional<OsAccountStatus> getOsAccountStatus() {
332  return Optional.ofNullable(osAccountStatus);
333  }
334 
340  public OsAccountDbStatus getOsAccountDbStatus() {
341  return osAccountDbStatus;
342  }
343 
351  public synchronized List<OsAccountAttribute> getExtendedOsAccountAttributes() throws TskCoreException {
352  if (osAccountAttributes == null) {
353  osAccountAttributes = sleuthkitCase.getOsAccountManager().getOsAccountAttributes(this);
354  }
355  return Collections.unmodifiableList(osAccountAttributes);
356  }
357 
365  public synchronized List<OsAccountInstance> getOsAccountInstances() throws TskCoreException {
366  return sleuthkitCase.getOsAccountManager().getOsAccountInstances(this);
367  }
368 
374  @Override
376  return sleuthkitCase;
377  }
378 
379  @Override
380  public int read(byte[] buf, long offset, long len) throws TskCoreException {
381  // No data to read.
382  return 0;
383  }
384 
385  @Override
386  public void close() {
387  // nothing to close
388  }
389 
390  @Override
391  public long getSize() {
392  // No data.
393  return 0;
394  }
395 
396  @Override
397  public <T> T accept(ContentVisitor<T> v) {
398 
399  throw new UnsupportedOperationException("Not supported yet.");
400  }
401 
402  @Override
403  public <T> T accept(SleuthkitItemVisitor<T> v) {
404  return v.visit(this);
405  }
406 
415  public final class OsAccountAttribute extends AbstractAttribute {
416 
417  private final long osAccountObjId; // OS account to which this attribute belongs.
418  private final Long hostId; // Host to which this attribute applies, may be null
419  private final Long sourceObjId; // Object id of the source where the attribute was discovered.
420 
433  public OsAccountAttribute(BlackboardAttribute.Type attributeType, int valueInt, OsAccount osAccount, Host host, Content sourceObj) {
434  super(attributeType, valueInt);
435 
436  this.osAccountObjId = osAccount.getId();
437  this.hostId = (host != null ? host.getHostId() : null);
438  this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null);
439  }
440 
451  public OsAccountAttribute(BlackboardAttribute.Type attributeType, long valueLong, OsAccount osAccount, Host host, Content sourceObj) {
452  super(attributeType, valueLong);
453 
454  this.osAccountObjId = osAccount.getId();
455  this.hostId = (host != null ? host.getHostId() : null);
456  this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null);
457  }
458 
469  public OsAccountAttribute(BlackboardAttribute.Type attributeType, double valueDouble, OsAccount osAccount, Host host, Content sourceObj) {
470  super(attributeType, valueDouble);
471 
472  this.osAccountObjId = osAccount.getId();
473  this.hostId = (host != null ? host.getHostId() : null);
474  this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null);
475  }
476 
487  public OsAccountAttribute(BlackboardAttribute.Type attributeType, String valueString, OsAccount osAccount, Host host, Content sourceObj) {
488  super(attributeType, valueString);
489 
490  this.osAccountObjId = osAccount.getId();
491  this.hostId = (host != null ? host.getHostId() : null);
492  this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null);
493  }
494 
505  public OsAccountAttribute(BlackboardAttribute.Type attributeType, byte[] valueBytes, OsAccount osAccount, Host host, Content sourceObj) {
506  super(attributeType, valueBytes);
507 
508  this.osAccountObjId = osAccount.getId();
509  this.hostId = (host != null ? host.getHostId() : null);
510  this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null);
511  }
512 
529  OsAccountAttribute(BlackboardAttribute.Type attributeType, int valueInt, long valueLong, double valueDouble, String valueString, byte[] valueBytes,
530  SleuthkitCase sleuthkitCase, OsAccount osAccount, Host host, Content sourceObj) {
531 
532  super(attributeType,
533  valueInt, valueLong, valueDouble, valueString, valueBytes,
534  sleuthkitCase);
535  this.osAccountObjId = osAccount.getId();
536  this.hostId = (host != null ? host.getHostId() : null);
537  this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null);
538  }
539 
545  public Optional<Long> getHostId() {
546  return Optional.ofNullable(hostId);
547  }
548 
554  public long getOsAccountObjectId() {
555  return osAccountObjId;
556  }
557 
563  public Optional<Long> getSourceObjectId() {
564  return Optional.ofNullable(sourceObjId);
565  }
566  }
567 }
Optional< String > getAddr()
Definition: OsAccount.java:266
OsAccountAttribute(BlackboardAttribute.Type attributeType, byte[] valueBytes, OsAccount osAccount, Host host, Content sourceObj)
Definition: OsAccount.java:505
static OsAccountType fromID(int typeId)
Definition: OsAccount.java:193
Optional< OsAccountType > getOsAccountType()
Definition: OsAccount.java:322
OsAccountAttribute(BlackboardAttribute.Type attributeType, String valueString, OsAccount osAccount, Host host, Content sourceObj)
Definition: OsAccount.java:487
OsAccountDbStatus getOsAccountDbStatus()
Definition: OsAccount.java:340
synchronized List< OsAccountInstance > getOsAccountInstances()
Definition: OsAccount.java:365
Optional< OsAccountStatus > getOsAccountStatus()
Definition: OsAccount.java:331
OsAccountAttribute(BlackboardAttribute.Type attributeType, long valueLong, OsAccount osAccount, Host host, Content sourceObj)
Definition: OsAccount.java:451
OsAccountAttribute(BlackboardAttribute.Type attributeType, int valueInt, OsAccount osAccount, Host host, Content sourceObj)
Definition: OsAccount.java:433
Optional< Long > getCreationTime()
Definition: OsAccount.java:313
Optional< String > getLoginName()
Definition: OsAccount.java:286
static OsAccountStatus fromID(int statusId)
Definition: OsAccount.java:105
OsAccountAttribute(BlackboardAttribute.Type attributeType, double valueDouble, OsAccount osAccount, Host host, Content sourceObj)
Definition: OsAccount.java:469
Optional< String > getFullName()
Definition: OsAccount.java:304
int read(byte[] buf, long offset, long len)
Definition: OsAccount.java:380
synchronized List< OsAccountAttribute > getExtendedOsAccountAttributes()
Definition: OsAccount.java:351

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.