Sleuth Kit Java Bindings (JNI)  4.11.1
Java bindings for using The Sleuth Kit
OsAccountRealm.java
Go to the documentation of this file.
1 /*
2  * Sleuth Kit Data Model
3  *
4  * Copyright 2020 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.ArrayList;
22 import java.util.List;
23 import java.util.Objects;
24 import java.util.Optional;
25 import java.util.ResourceBundle;
26 import org.apache.commons.lang3.StringUtils;
27 
39 public final class OsAccountRealm {
40 
41  private static final ResourceBundle bundle = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle");
42 
43  private final long id; // row id
44 
45  // a realm may have multiple names - for exmple, for a user ABCCorp\\user1 or user1@ABCcorp.com - 'ABCCorp' and 'ABCcorp.com' both refer to the same realm.
46  // currently we only support a single name, this could be expanded in future.
47  private final String realmName; // realm name
48 
49  private final String realmAddr; // realm address
50  private String signature; // either realm address or name (if address is not known), plus a scope indicator
51  private final Host host; // if the realm consists of a single host. Will be null if the realm is domain scoped.
52  private final ScopeConfidence scopeConfidence; // confidence in realm scope.
53  private final RealmDbStatus dbStatus; // Status of row in database.
54 
66  OsAccountRealm(long id, String realmName, String realmAddr, String signature, Host host, ScopeConfidence scopeConfidence, RealmDbStatus dbStatus) {
67  this.id = id;
68  this.realmName = realmName;
69  this.realmAddr = realmAddr;
70  this.signature = signature;
71  this.host = host;
72  this.scopeConfidence = scopeConfidence;
73  this.dbStatus = dbStatus;
74  }
75 
81  long getRealmId() {
82  return id;
83  }
84 
93  public List<String> getRealmNames() {
94  List<String> namesList = new ArrayList<>();
95  if (!Objects.isNull(realmName)) {
96  namesList.add(realmName);
97  }
98 
99  return namesList;
100  }
101 
107  public Optional<String> getRealmAddr() {
108  return Optional.ofNullable(realmAddr);
109  }
110 
116  String getSignature() {
117  return signature;
118  }
119 
125  public Optional<Host> getScopeHost() {
126  return Optional.ofNullable(host);
127  }
128 
135  return scopeConfidence;
136  }
137 
143  RealmDbStatus getDbStatus() {
144  return dbStatus;
145  }
146 
152  public RealmScope getScope() {
153  return getScopeHost().isPresent() ? RealmScope.LOCAL : RealmScope.DOMAIN;
154  }
155 
162  public enum RealmScope {
163  UNKNOWN(0, bundle.getString("OsAccountRealm.Unknown.text")), // realm scope is unknown.
164  LOCAL(1, bundle.getString("OsAccountRealm.Local.text")), // realm scope is a single host.
165  DOMAIN(2, bundle.getString("OsAccountRealm.Domain.text")); // realm scope is a domain.
166 
167  private final int id;
168  private final String name;
169 
170  RealmScope(int id, String name) {
171  this.id = id;
172  this.name = name;
173  }
174 
180  public int getId() {
181  return id;
182  }
183 
189  public String getName() {
190  return name;
191  }
192 
200  public static RealmScope fromID(int typeId) {
201  for (RealmScope scopeType : RealmScope.values()) {
202  if (scopeType.ordinal() == typeId) {
203  return scopeType;
204  }
205  }
206  return null;
207  }
208  }
209 
217  public enum ScopeConfidence {
218  KNOWN(0, bundle.getString("OsAccountRealm.Known.text")), // realm scope is known for sure.
219  INFERRED(1, bundle.getString("OsAccountRealm.Inferred.text")); // realm scope is inferred
220 
221  private final int id;
222  private final String name;
223 
224  ScopeConfidence(int id, String name) {
225  this.id = id;
226  this.name = name;
227  }
228 
234  public int getId() {
235  return id;
236  }
237 
243  public String getName() {
244  return name;
245  }
246 
254  public static ScopeConfidence fromID(int typeId) {
255  for (ScopeConfidence statusType : ScopeConfidence.values()) {
256  if (statusType.ordinal() == typeId) {
257  return statusType;
258  }
259  }
260  return null;
261  }
262  }
263 
272  boolean setSignature(String signature) {
273  if (StringUtils.isNotBlank(signature)) {
274  this.signature = signature;
275  return true;
276  }
277 
278  return false;
279  }
280 
281 
285  enum RealmDbStatus {
286  ACTIVE(0, "Active"),
287  MERGED(1, "Merged"),
288  DELETED(2, "Deleted");
289 
290  private final int id;
291  private final String name;
292 
293  RealmDbStatus(int id, String name) {
294  this.id = id;
295  this.name = name;
296  }
297 
298  int getId() {
299  return id;
300  }
301 
302  String getName() {
303  return name;
304  }
305 
306  static RealmDbStatus fromID(int typeId) {
307  for (RealmDbStatus type : RealmDbStatus.values()) {
308  if (type.ordinal() == typeId) {
309  return type;
310  }
311  }
312  return null;
313  }
314  }
315 
316 }

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.