Sleuth Kit Java Bindings (JNI)  4.12.1
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  @Deprecated
71  DELETED(3, bundle.getString("OsAccountStatus.Deleted.text")),
72  NON_EXISTENT(4, bundle.getString("OsAccountStatus.NonExistent.text"));
73 
74  private final int id;
75  private final String name;
76 
77  OsAccountStatus(int id, String name) {
78  this.id = id;
79  this.name = name;
80  }
81 
87  public int getId() {
88  return id;
89  }
90 
96  public String getName() {
97  return name;
98  }
99 
107  public static OsAccountStatus fromID(int statusId) {
108  for (OsAccountStatus statusType : OsAccountStatus.values()) {
109  if (statusType.ordinal() == statusId) {
110  return statusType;
111  }
112  }
113  return null;
114  }
115  }
116 
122  enum OsAccountDbStatus {
123  ACTIVE(0, "Active"),
124  MERGED(1, "Merged"),
125  DELETED(2, "Deleted");
126 
127  private final int id;
128  private final String name;
129 
130  OsAccountDbStatus(int id, String name) {
131  this.id = id;
132  this.name = name;
133  }
134 
135  int getId() {
136  return id;
137  }
138 
139  String getName() {
140  return name;
141  }
142 
143  static OsAccountDbStatus fromID(int typeId) {
144  for (OsAccountDbStatus type : OsAccountDbStatus.values()) {
145  if (type.ordinal() == typeId) {
146  return type;
147  }
148  }
149  return null;
150  }
151  }
152 
157  public enum OsAccountType {
158  UNKNOWN(0, bundle.getString("OsAccountType.Unknown.text")),
159  SERVICE(1, bundle.getString("OsAccountType.Service.text")),
160  INTERACTIVE(2, bundle.getString("OsAccountType.Interactive.text"));
161 
162  private final int id;
163  private final String name;
164 
165  OsAccountType(int id, String name) {
166  this.id = id;
167  this.name = name;
168  }
169 
175  public int getId() {
176  return id;
177  }
178 
184  public String getName() {
185  return name;
186  }
187 
195  public static OsAccountType fromID(int typeId) {
196  for (OsAccountType accountType : OsAccountType.values()) {
197  if (accountType.ordinal() == typeId) {
198  return accountType;
199  }
200  }
201  return null;
202  }
203  }
204 
224  OsAccount(SleuthkitCase sleuthkitCase, long osAccountobjId, long realmId, String loginName, String uniqueId, String signature,
225  String fullName, Long creationTime, OsAccountType accountType, OsAccountStatus accountStatus, OsAccountDbStatus accountDbStatus) {
226 
227  super(sleuthkitCase, osAccountobjId, signature);
228 
229  this.sleuthkitCase = sleuthkitCase;
230  this.osAccountObjId = osAccountobjId;
231  this.realmId = realmId;
232  this.loginName = loginName;
233  this.addr = uniqueId;
234  this.signature = signature;
235  this.fullName = fullName;
236  this.creationTime = creationTime;
237  this.osAccountType = accountType;
238  this.osAccountStatus = accountStatus;
239  this.osAccountDbStatus = accountDbStatus;
240  }
241 
248  synchronized void setAttributesInternal(List<OsAccountAttribute> osAccountAttributes) {
249  this.osAccountAttributes = osAccountAttributes;
250  }
251 
258  public long getId() {
259  return osAccountObjId;
260  }
261 
268  public Optional<String> getAddr() {
269  return Optional.ofNullable(addr);
270  }
271 
279  public long getRealmId() {
280  return realmId;
281  }
282 
288  public Optional<String> getLoginName() {
289  return Optional.ofNullable(loginName);
290  }
291 
297  String getSignature() {
298  return signature;
299  }
300 
306  public Optional<String> getFullName() {
307  return Optional.ofNullable(fullName);
308  }
309 
315  public Optional<Long> getCreationTime() {
316  return Optional.ofNullable(creationTime);
317  }
318 
324  public Optional<OsAccountType> getOsAccountType() {
325  return Optional.ofNullable(osAccountType);
326  }
327 
333  public Optional<OsAccountStatus> getOsAccountStatus() {
334  return Optional.ofNullable(osAccountStatus);
335  }
336 
342  public OsAccountDbStatus getOsAccountDbStatus() {
343  return osAccountDbStatus;
344  }
345 
353  public synchronized List<OsAccountAttribute> getExtendedOsAccountAttributes() throws TskCoreException {
354  if (osAccountAttributes == null) {
355  osAccountAttributes = sleuthkitCase.getOsAccountManager().getOsAccountAttributes(this);
356  }
357  return Collections.unmodifiableList(osAccountAttributes);
358  }
359 
367  public synchronized List<OsAccountInstance> getOsAccountInstances() throws TskCoreException {
368  return sleuthkitCase.getOsAccountManager().getOsAccountInstances(this);
369  }
370 
376  @Override
378  return sleuthkitCase;
379  }
380 
381  @Override
382  public int read(byte[] buf, long offset, long len) throws TskCoreException {
383  // No data to read.
384  return 0;
385  }
386 
387  @Override
388  public void close() {
389  // nothing to close
390  }
391 
392  @Override
393  public long getSize() {
394  // No data.
395  return 0;
396  }
397 
398  @Override
399  public <T> T accept(ContentVisitor<T> v) {
400 
401  throw new UnsupportedOperationException("Not supported yet.");
402  }
403 
404  @Override
405  public <T> T accept(SleuthkitItemVisitor<T> v) {
406  return v.visit(this);
407  }
408 
417  public final class OsAccountAttribute extends AbstractAttribute {
418 
419  private final long osAccountObjId; // OS account to which this attribute belongs.
420  private final Long hostId; // Host to which this attribute applies, may be null
421  private final Long sourceObjId; // Object id of the source where the attribute was discovered.
422 
435  public OsAccountAttribute(BlackboardAttribute.Type attributeType, int valueInt, OsAccount osAccount, Host host, Content sourceObj) {
436  super(attributeType, valueInt);
437 
438  this.osAccountObjId = osAccount.getId();
439  this.hostId = (host != null ? host.getHostId() : null);
440  this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null);
441  }
442 
453  public OsAccountAttribute(BlackboardAttribute.Type attributeType, long valueLong, OsAccount osAccount, Host host, Content sourceObj) {
454  super(attributeType, valueLong);
455 
456  this.osAccountObjId = osAccount.getId();
457  this.hostId = (host != null ? host.getHostId() : null);
458  this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null);
459  }
460 
471  public OsAccountAttribute(BlackboardAttribute.Type attributeType, double valueDouble, OsAccount osAccount, Host host, Content sourceObj) {
472  super(attributeType, valueDouble);
473 
474  this.osAccountObjId = osAccount.getId();
475  this.hostId = (host != null ? host.getHostId() : null);
476  this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null);
477  }
478 
489  public OsAccountAttribute(BlackboardAttribute.Type attributeType, String valueString, OsAccount osAccount, Host host, Content sourceObj) {
490  super(attributeType, valueString);
491 
492  this.osAccountObjId = osAccount.getId();
493  this.hostId = (host != null ? host.getHostId() : null);
494  this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null);
495  }
496 
507  public OsAccountAttribute(BlackboardAttribute.Type attributeType, byte[] valueBytes, OsAccount osAccount, Host host, Content sourceObj) {
508  super(attributeType, valueBytes);
509 
510  this.osAccountObjId = osAccount.getId();
511  this.hostId = (host != null ? host.getHostId() : null);
512  this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null);
513  }
514 
531  OsAccountAttribute(BlackboardAttribute.Type attributeType, int valueInt, long valueLong, double valueDouble, String valueString, byte[] valueBytes,
532  SleuthkitCase sleuthkitCase, OsAccount osAccount, Host host, Content sourceObj) {
533 
534  super(attributeType,
535  valueInt, valueLong, valueDouble, valueString, valueBytes,
536  sleuthkitCase);
537  this.osAccountObjId = osAccount.getId();
538  this.hostId = (host != null ? host.getHostId() : null);
539  this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null);
540  }
541 
547  public Optional<Long> getHostId() {
548  return Optional.ofNullable(hostId);
549  }
550 
556  public long getOsAccountObjectId() {
557  return osAccountObjId;
558  }
559 
565  public Optional<Long> getSourceObjectId() {
566  return Optional.ofNullable(sourceObjId);
567  }
568  }
569 }
Optional< String > getAddr()
Definition: OsAccount.java:268
OsAccountAttribute(BlackboardAttribute.Type attributeType, byte[] valueBytes, OsAccount osAccount, Host host, Content sourceObj)
Definition: OsAccount.java:507
static OsAccountType fromID(int typeId)
Definition: OsAccount.java:195
Optional< OsAccountType > getOsAccountType()
Definition: OsAccount.java:324
OsAccountAttribute(BlackboardAttribute.Type attributeType, String valueString, OsAccount osAccount, Host host, Content sourceObj)
Definition: OsAccount.java:489
OsAccountDbStatus getOsAccountDbStatus()
Definition: OsAccount.java:342
synchronized List< OsAccountInstance > getOsAccountInstances()
Definition: OsAccount.java:367
Optional< OsAccountStatus > getOsAccountStatus()
Definition: OsAccount.java:333
OsAccountAttribute(BlackboardAttribute.Type attributeType, long valueLong, OsAccount osAccount, Host host, Content sourceObj)
Definition: OsAccount.java:453
OsAccountAttribute(BlackboardAttribute.Type attributeType, int valueInt, OsAccount osAccount, Host host, Content sourceObj)
Definition: OsAccount.java:435
Optional< Long > getCreationTime()
Definition: OsAccount.java:315
List< OsAccountInstance > getOsAccountInstances(OsAccount account)
Optional< String > getLoginName()
Definition: OsAccount.java:288
static OsAccountStatus fromID(int statusId)
Definition: OsAccount.java:107
OsAccountAttribute(BlackboardAttribute.Type attributeType, double valueDouble, OsAccount osAccount, Host host, Content sourceObj)
Definition: OsAccount.java:471
Optional< String > getFullName()
Definition: OsAccount.java:306
int read(byte[] buf, long offset, long len)
Definition: OsAccount.java:382
synchronized List< OsAccountAttribute > getExtendedOsAccountAttributes()
Definition: OsAccount.java:353

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.