diff --git a/bindings/java/src/org/sleuthkit/datamodel/AbstractContent.java b/bindings/java/src/org/sleuthkit/datamodel/AbstractContent.java index 2a95b7b39fef08d32336fcaaa8b2d4f159055809..c37a5463a5e17605367f89457dc3b661d714a4e4 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/AbstractContent.java +++ b/bindings/java/src/org/sleuthkit/datamodel/AbstractContent.java @@ -348,7 +348,7 @@ public DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collec DataArtifact artifact = db.getBlackboard().newDataArtifact(artifactType, objId, this.getDataSource().getId(), attributesList, osAccount); if(osAccount != null) { - db.getOsAccountManager().createOsAccountInstance(osAccount, (DataSource)getDataSource(), OsAccountInstance.OsAccountInstanceType.LAUNCHED); + db.getOsAccountManager().newOsAccountInstance(osAccount, (DataSource)getDataSource(), OsAccountInstance.OsAccountInstanceType.LAUNCHED); } return artifact; } diff --git a/bindings/java/src/org/sleuthkit/datamodel/Host.java b/bindings/java/src/org/sleuthkit/datamodel/Host.java index 22a785e7c0a182683b5e808c2ed8138bfca0c244..3be378369c1ca93f77c4c12f4101ed19960e5a60 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Host.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Host.java @@ -27,8 +27,8 @@ public final class Host { private final long id; - private String name; - private HostDbStatus status; + private final String name; + private final HostDbStatus status; Host(long id, String name) { this(id, name, HostDbStatus.ACTIVE); @@ -57,33 +57,15 @@ public long getHostId() { public String getName() { return name; } - - /** - * Sets the name for the host. - * @param newName The new name. - */ - public void setName(String newName) { - this.name = newName; - } - /** * Gets the status for the host. * * @return Host status. */ - public HostDbStatus getStatus() { + HostDbStatus getStatus() { return status; } - - /** - * Sets the status for the host. - * - * @param status Host status. - */ - public void setStatus(HostDbStatus status) { - this.status = status; - } @Override public int hashCode() { diff --git a/bindings/java/src/org/sleuthkit/datamodel/HostAddressManager.java b/bindings/java/src/org/sleuthkit/datamodel/HostAddressManager.java index c0554672401b2df0fd6c24b1dd0f3b67273e5209..307fafa0977210a1d354c3ecaf0fb979c18ef61e 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/HostAddressManager.java +++ b/bindings/java/src/org/sleuthkit/datamodel/HostAddressManager.java @@ -141,10 +141,10 @@ private Optional<HostAddress> getHostAddress(HostAddress.HostAddressType type, S * * @throws TskCoreException */ - public HostAddress createHostAddress(HostAddress.HostAddressType type, String address) throws TskCoreException { + public HostAddress newHostAddress(HostAddress.HostAddressType type, String address) throws TskCoreException { CaseDbConnection connection = this.db.getConnection(); try { - return HostAddressManager.this.createHostAddress(type, address, connection); + return HostAddressManager.this.newHostAddress(type, address, connection); } catch (TskCoreException ex) { // The insert may have failed because the HostAddress already exists, so // try loading it from the database. @@ -169,7 +169,7 @@ public HostAddress createHostAddress(HostAddress.HostAddressType type, String ad * * @throws TskCoreException */ - private HostAddress createHostAddress(HostAddress.HostAddressType type, String address, CaseDbConnection connection) throws TskCoreException { + private HostAddress newHostAddress(HostAddress.HostAddressType type, String address, CaseDbConnection connection) throws TskCoreException { HostAddress.HostAddressType addressType = type; if (type.equals(HostAddress.HostAddressType.DNS_AUTO)) { addressType = getDNSType(address); diff --git a/bindings/java/src/org/sleuthkit/datamodel/HostManager.java b/bindings/java/src/org/sleuthkit/datamodel/HostManager.java index 0a89578fb2fa5d4e49eb01e9d619017c59459c6a..40ad7529bc9269dfdc917e8ab1cf7f7c2650e023 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/HostManager.java +++ b/bindings/java/src/org/sleuthkit/datamodel/HostManager.java @@ -51,21 +51,6 @@ public final class HostManager { this.db = skCase; } - /** - * Get or create host with specified name. - * - * TODO: This should be deleted before release - * - * @param name Host name. - * - * @return Host with the specified name. - * - * @throws TskCoreException - */ - public Host getOrCreateHost(String name) throws TskCoreException { - return createHost(name); - } - /** * Create a host with specified name. If a host already exists with the * given name, it returns the existing host. @@ -76,10 +61,10 @@ public Host getOrCreateHost(String name) throws TskCoreException { * * @throws TskCoreException */ - public Host createHost(String name) throws TskCoreException { + public Host newHost(String name) throws TskCoreException { CaseDbTransaction transaction = db.beginTransaction(); try { - Host host = createHost(name, transaction); + Host host = newHost(name, transaction); transaction.commit(); transaction = null; return host; @@ -114,7 +99,7 @@ public Host createHost(String name) throws TskCoreException { * * @throws TskCoreException */ - Host createHost(String name, CaseDbTransaction trans) throws TskCoreException { + Host newHost(String name, CaseDbTransaction trans) throws TskCoreException { // must have a name if (Strings.isNullOrEmpty(name)) { throw new TskCoreException("Illegal argument passed to createHost: Host name is required."); @@ -157,7 +142,7 @@ Host createHost(String name, CaseDbTransaction trans) throws TskCoreException { } // It may be the case that the host already exists, so try to get it. - Optional<Host> optHost = getHost(name, connection); + Optional<Host> optHost = getHostByName(name, connection); if (optHost.isPresent()) { return optHost.get(); } @@ -166,21 +151,23 @@ Host createHost(String name, CaseDbTransaction trans) throws TskCoreException { } /** - * Updates host in database based on the host object provided. + * Updates the name of the provided host. * - * @param newHost The host to be updated. + * @param host The host to be updated. + * @param newName The new name of the host. * - * @return The newly returned host. + * @return The updated host. * * @throws TskCoreException */ - public Host updateHost(Host newHost) throws TskCoreException { - if (newHost == null) { + public Host updateHostName(Host host, String newName) throws TskCoreException { + if (host == null) { throw new TskCoreException("Illegal argument passed to updateHost: No host argument provided."); - } else if (newHost.getName() == null) { - throw new TskCoreException(String.format("Illegal argument passed to updateHost: Host with id %d has no name", newHost.getHostId())); + } else if (newName == null) { + throw new TskCoreException(String.format("Illegal argument passed to updateHost: Host with id %d has no name", host.getHostId())); } + long hostId = host.getHostId(); Host updatedHost = null; db.acquireSingleUserCaseWriteLock(); try (CaseDbConnection connection = db.getConnection()) { @@ -193,16 +180,16 @@ public Host updateHost(Host newHost) throws TskCoreException { PreparedStatement preparedStatement = connection.getPreparedStatement(hostInsertSQL, Statement.RETURN_GENERATED_KEYS); preparedStatement.clearParameters(); - preparedStatement.setString(1, newHost.getName()); - preparedStatement.setLong(2, newHost.getHostId()); + preparedStatement.setString(1, newName); + preparedStatement.setLong(2, hostId); connection.executeUpdate(preparedStatement); - updatedHost = getHost(newHost.getHostId(), connection).orElseThrow(() + updatedHost = getHostById(hostId, connection).orElseThrow(() -> new TskCoreException((String.format("Error while fetching newly updated host with id: %d, ")))); } catch (SQLException ex) { - throw new TskCoreException(String.format("Error updating host with name = %s", newHost.getName()), ex); + throw new TskCoreException(String.format("Error updating host with name = %s", newName), ex); } finally { db.releaseSingleUserCaseWriteLock(); } @@ -322,9 +309,9 @@ public List<DataSource> getDataSourcesForHost(Host host) throws TskCoreException * * @throws TskCoreException */ - public Optional<Host> getHost(String name) throws TskCoreException { + public Optional<Host> getHostByName(String name) throws TskCoreException { try (CaseDbConnection connection = db.getConnection()) { - return getHost(name, connection); + return getHostByName(name, connection); } } @@ -338,7 +325,7 @@ public Optional<Host> getHost(String name) throws TskCoreException { * * @throws TskCoreException */ - private Optional<Host> getHost(String name, CaseDbConnection connection) throws TskCoreException { + private Optional<Host> getHostByName(String name, CaseDbConnection connection) throws TskCoreException { String queryString = "SELECT * FROM tsk_hosts" + " WHERE LOWER(name) = LOWER(?)" @@ -373,9 +360,9 @@ private Optional<Host> getHost(String name, CaseDbConnection connection) throws * * @throws TskCoreException */ - public Optional<Host> getHost(long id) throws TskCoreException { + public Optional<Host> getHostById(long id) throws TskCoreException { try (CaseDbConnection connection = db.getConnection()) { - return getHost(id, connection); + return getHostById(id, connection); } } @@ -389,7 +376,7 @@ public Optional<Host> getHost(long id) throws TskCoreException { * * @throws TskCoreException */ - private Optional<Host> getHost(long id, CaseDbConnection connection) throws TskCoreException { + private Optional<Host> getHostById(long id, CaseDbConnection connection) throws TskCoreException { String queryString = "SELECT * FROM tsk_hosts WHERE id = " + id; @@ -416,7 +403,7 @@ private Optional<Host> getHost(long id, CaseDbConnection connection) throws TskC * * @throws TskCoreException */ - public List<Host> getHosts() throws TskCoreException { + public List<Host> getAllHosts() throws TskCoreException { String queryString = "SELECT * FROM tsk_hosts WHERE db_status = " + HostDbStatus.ACTIVE.getId(); List<Host> hosts = new ArrayList<>(); @@ -446,7 +433,7 @@ public List<Host> getHosts() throws TskCoreException { * * @throws TskCoreException if no host is found or an error occurs. */ - public Host getHost(DataSource dataSource) throws TskCoreException { + public Host getHostByDataSource(DataSource dataSource) throws TskCoreException { String queryString = "SELECT tsk_hosts.id AS hostId, tsk_hosts.name AS name, tsk_hosts.db_status AS db_status FROM \n" + "tsk_hosts INNER JOIN data_source_info \n" diff --git a/bindings/java/src/org/sleuthkit/datamodel/Image.java b/bindings/java/src/org/sleuthkit/datamodel/Image.java index 57284faf6fa85312c4d4f9d829f44186ae2acdf8..7e2d793a29e1749b0d4b4aa192334d73fa4def6b 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Image.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Image.java @@ -611,7 +611,7 @@ public Host getHost() throws TskCoreException { // This is a check-then-act race condition that may occasionally result // in additional processing but is safer than using locks. if (host == null) { - host = getSleuthkitCase().getHostManager().getHost(this); + host = getSleuthkitCase().getHostManager().getHostByDataSource(this); } return host; } diff --git a/bindings/java/src/org/sleuthkit/datamodel/LocalFilesDataSource.java b/bindings/java/src/org/sleuthkit/datamodel/LocalFilesDataSource.java index f85c55c4d5a62c75ca7c4b23e83df24bd2bac376..fbf5449a8c61b52be375fffc28166219b9c02136 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/LocalFilesDataSource.java +++ b/bindings/java/src/org/sleuthkit/datamodel/LocalFilesDataSource.java @@ -268,7 +268,7 @@ public Host getHost() throws TskCoreException { // This is a check-then-act race condition that may occasionally result // in additional processing but is safer than using locks. if (host == null) { - host = getSleuthkitCase().getHostManager().getHost(this); + host = getSleuthkitCase().getHostManager().getHostByDataSource(this); } return host; } diff --git a/bindings/java/src/org/sleuthkit/datamodel/OsAccount.java b/bindings/java/src/org/sleuthkit/datamodel/OsAccount.java index d8ff03b42b9576b476c601837cbd8d9bc69c8c56..a2c77045c3402d7f5917fa5247c9c84819fceff3 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/OsAccount.java +++ b/bindings/java/src/org/sleuthkit/datamodel/OsAccount.java @@ -62,7 +62,6 @@ public final class OsAccount extends AbstractContent { private List<OsAccountAttribute> osAccountAttributes = null; private List<OsAccountInstance> osAccountInstances = null; - /** * Encapsulates status of an account - whether is it active or disabled or * deleted. @@ -242,10 +241,10 @@ public static OsAccountType fromID(int typeId) { } /** - * This function is used by OsAccountManger to update the list of - * OsAccount attributes. - * - * @param osAccountAttribute The osAccount Attribute that is to be added. + * This function is used by OsAccountManger to update the list of OsAccount + * attributes. + * + * @param osAccountAttribute The osAccount Attribute that is to be added. */ void setAttributesInternal(List<OsAccountAttribute> osAccountAttributes) { this.osAccountAttributes = osAccountAttributes; @@ -272,7 +271,7 @@ public Optional<String> getAddr() { /** * Get the ID for the account realm. Get the Realm via - * OsAccountRealmManager.getRealmById() NOTE: The realm may get updated as + * OsAccountRealmManager.getRealmByRealmId() NOTE: The realm may get updated as * more data is parsed, so listen for events to update as needed. * * @return @@ -351,7 +350,7 @@ public OsAccountDbStatus getOsAccountDbStatus() { * * @throws TskCoreException */ - public synchronized List<OsAccountAttribute> getOsAccountAttributes() throws TskCoreException { + public List<OsAccountAttribute> getExtendedOsAccountAttributes() throws TskCoreException { if (osAccountAttributes == null) { osAccountAttributes = sleuthkitCase.getOsAccountManager().getOsAccountAttributes(this); } @@ -420,4 +419,164 @@ public <T> T accept(ContentVisitor<T> v) { public <T> T accept(SleuthkitItemVisitor<T> v) { return v.visit(this); } + + /** + * Abstracts attributes of an OS account. An attribute may be specific to a + * host, or applicable across all hosts. + * + * As an example, last login time is host specific, whereas last password + * reset date is independent of a host. + * + */ + public final class OsAccountAttribute extends AbstractAttribute { + + private final long osAccountObjId; // OS account to which this attribute belongs. + private final Long hostId; // Host to which this attribute applies, may be null + private final Long sourceObjId; // Object id of the source where the attribute was discovered. + + /** + * Creates an os account attribute with int value. + * + * @param attributeType Attribute type. + * @param valueInt Int value. + * @param osAccount Account which the attribute pertains to. + * @param host Host on which the attribute applies to. Pass + * Null if the attribute applies to all the hosts in + * the realm. + * @param sourceObj Source where the attribute was found, may be null. + */ + public OsAccountAttribute(BlackboardAttribute.Type attributeType, int valueInt, OsAccount osAccount, Host host, Content sourceObj) { + super(attributeType, valueInt); + + this.osAccountObjId = osAccount.getId(); + this.hostId = (host != null ? host.getHostId() : null); + this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null); + } + + /** + * Creates an os account attribute with long value. + * + * @param attributeType Attribute type. + * @param valueLong Long value. + * @param osAccount Account which the attribute pertains to. + * @param host Host on which the attribute applies to. Pass + * Null if it applies across hosts. + * @param sourceObj Source where the attribute was found. + */ + public OsAccountAttribute(BlackboardAttribute.Type attributeType, long valueLong, OsAccount osAccount, Host host, Content sourceObj) { + super(attributeType, valueLong); + + this.osAccountObjId = osAccount.getId(); + this.hostId = (host != null ? host.getHostId() : null); + this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null); + } + + /** + * Creates an os account attribute with double value. + * + * @param attributeType Attribute type. + * @param valueDouble Double value. + * @param osAccount Account which the attribute pertains to. + * @param host Host on which the attribute applies to. Pass + * Null if it applies across hosts. + * @param sourceObj Source where the attribute was found. + */ + public OsAccountAttribute(BlackboardAttribute.Type attributeType, double valueDouble, OsAccount osAccount, Host host, Content sourceObj) { + super(attributeType, valueDouble); + + this.osAccountObjId = osAccount.getId(); + this.hostId = (host != null ? host.getHostId() : null); + this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null); + } + + /** + * Creates an os account attribute with string value. + * + * @param attributeType Attribute type. + * @param valueString String value. + * @param osAccount Account which the attribute pertains to. + * @param host Host on which the attribute applies to. Pass + * Null if applies across hosts. + * @param sourceObj Source where the attribute was found. + */ + public OsAccountAttribute(BlackboardAttribute.Type attributeType, String valueString, OsAccount osAccount, Host host, Content sourceObj) { + super(attributeType, valueString); + + this.osAccountObjId = osAccount.getId(); + this.hostId = (host != null ? host.getHostId() : null); + this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null); + } + + /** + * Creates an os account attribute with byte-array value. + * + * @param attributeType Attribute type. + * @param valueBytes Bytes value. + * @param osAccount Account which the attribute pertains to. + * @param host Host on which the attribute applies to. Pass + * Null if it applies across hosts. + * @param sourceObj Source where the attribute was found. + */ + public OsAccountAttribute(BlackboardAttribute.Type attributeType, byte[] valueBytes, OsAccount osAccount, Host host, Content sourceObj) { + super(attributeType, valueBytes); + + this.osAccountObjId = osAccount.getId(); + this.hostId = (host != null ? host.getHostId() : null); + this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null); + } + + /** + * Constructor to be used when creating an attribute after reading the + * data from the table. + * + * @param attributeType Attribute type. + * @param valueInt Int value. + * @param valueLong Long value. + * @param valueDouble Double value. + * @param valueString String value. + * @param valueBytes Bytes value. + * @param sleuthkitCase Sleuthkit case. + * @param osAccount Account which the attribute pertains to. + * @param host Host on which the attribute applies to. Pass + * Null if it applies across hosts. + * @param sourceObj Source where the attribute was found. + */ + OsAccountAttribute(BlackboardAttribute.Type attributeType, int valueInt, long valueLong, double valueDouble, String valueString, byte[] valueBytes, + SleuthkitCase sleuthkitCase, OsAccount osAccount, Host host, Content sourceObj) { + + super(attributeType, + valueInt, valueLong, valueDouble, valueString, valueBytes, + sleuthkitCase); + this.osAccountObjId = osAccount.getId(); + this.hostId = (host != null ? host.getHostId() : null); + this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null); + } + + /** + * Get the host id for the account attribute. + * + * @return Optional with Host id. + */ + public Optional<Long> getHostId() { + return Optional.ofNullable(hostId); + } + + /** + * Get the object id of account to which this attribute applies. + * + * @return Account row id. + */ + public long getOsAccountObjectId() { + return osAccountObjId; + } + + /** + * Get the object id of the source where the attribute was found. + * + * @return Object id of source. + */ + public Optional<Long> getSourceObjectId() { + return Optional.ofNullable(sourceObjId); + } + } } diff --git a/bindings/java/src/org/sleuthkit/datamodel/OsAccountAttribute.java b/bindings/java/src/org/sleuthkit/datamodel/OsAccountAttribute.java deleted file mode 100644 index 7463ae74da810451fc7a358c5c74d3d2986be7c1..0000000000000000000000000000000000000000 --- a/bindings/java/src/org/sleuthkit/datamodel/OsAccountAttribute.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Sleuth Kit Data Model - * - * Copyright 2020-2021 Basis Technology Corp. - * Contact: carrier <at> sleuthkit <dot> org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.datamodel; - -import java.util.Optional; -import org.sleuthkit.datamodel.BlackboardAttribute.Type; - -/** - * Abstracts host specific attributes of an OS account. As an example, last - * login on a specific host. - * - */ -public final class OsAccountAttribute extends AbstractAttribute { - - private final long osAccountObjId; // OS account to which this attribute belongs. - private final Long hostId; // Host to which this attribute applies, may be null - private final Long sourceObjId; // Object id of the source where the attribute was discovered. - - /** - * Creates an os account attribute with int value. - * - * @param attributeType Attribute type. - * @param valueInt Int value. - * @param osAccount Account which the attribute pertains to. - * @param host Host on which the attribute applies to. Pass Null if - * @param sourceObj Source where the attribute was found. - */ - public OsAccountAttribute(BlackboardAttribute.Type attributeType, int valueInt, OsAccount osAccount, Host host, Content sourceObj) { - super(attributeType, valueInt); - - this.osAccountObjId = osAccount.getId(); - this.hostId = (host != null ? host.getHostId() : null); - this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null); - } - - /** - * Creates an os account attribute with long value. - * - * @param attributeType Attribute type. - * @param valueLong Long value. - * @param osAccount Account which the attribute pertains to. - * @param host Host on which the attribute applies to. Pass Null if - * it applies across hosts. - * @param sourceObj Source where the attribute was found. - */ - public OsAccountAttribute(BlackboardAttribute.Type attributeType, long valueLong, OsAccount osAccount, Host host, Content sourceObj) { - super(attributeType, valueLong); - - this.osAccountObjId = osAccount.getId(); - this.hostId = (host != null ? host.getHostId() : null); - this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null); - } - - /** - * Creates an os account attribute with double value. - * - * @param attributeType Attribute type. - * @param valueDouble Double value. - * @param osAccount Account which the attribute pertains to. - * @param host Host on which the attribute applies to. Pass Null if - * it applies across hosts. - * @param sourceObj Source where the attribute was found. - */ - public OsAccountAttribute(BlackboardAttribute.Type attributeType, double valueDouble, OsAccount osAccount, Host host, Content sourceObj) { - super(attributeType, valueDouble); - - this.osAccountObjId = osAccount.getId(); - this.hostId = (host != null ? host.getHostId() : null); - this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null); - } - - /** - * Creates an os account attribute with string value. - * - * @param attributeType Attribute type. - * @param valueString String value. - * @param osAccount Account which the attribute pertains to. - * @param host Host on which the attribute applies to. Pass Null if - * applies across hosts. - * @param sourceObj Source where the attribute was found. - */ - public OsAccountAttribute(BlackboardAttribute.Type attributeType, String valueString, OsAccount osAccount, Host host, Content sourceObj) { - super(attributeType, valueString); - - this.osAccountObjId = osAccount.getId(); - this.hostId = (host != null ? host.getHostId() : null); - this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null); - } - - /** - * Creates an os account attribute with byte-array value. - * - * @param attributeType Attribute type. - * @param valueBytes Bytes value. - * @param osAccount Account which the attribute pertains to. - * @param host Host on which the attribute applies to. Pass Null if - * it applies across hosts. - * @param sourceObj Source where the attribute was found. - */ - public OsAccountAttribute(Type attributeType, byte[] valueBytes, OsAccount osAccount, Host host, Content sourceObj) { - super(attributeType, valueBytes); - - this.osAccountObjId = osAccount.getId(); - this.hostId = (host != null ? host.getHostId() : null); - this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null); - } - - /** - * Constructor to be used when creating an attribute after reading the data - * from the table. - * - * @param attributeType Attribute type. - * @param valueInt Int value. - * @param valueLong Long value. - * @param valueDouble Double value. - * @param valueString String value. - * @param valueBytes Bytes value. - * @param sleuthkitCase Sleuthkit case. - * @param osAccount Account which the attribute pertains to. - * @param host Host on which the attribute applies to. Pass Null if - * it applies across hosts. - * @param sourceObj Source where the attribute was found. - */ - OsAccountAttribute(BlackboardAttribute.Type attributeType, int valueInt, long valueLong, double valueDouble, String valueString, byte[] valueBytes, - SleuthkitCase sleuthkitCase, OsAccount osAccount, Host host, Content sourceObj) { - - super(attributeType, - valueInt, valueLong, valueDouble, valueString, valueBytes, - sleuthkitCase); - this.osAccountObjId = osAccount.getId(); - this.hostId = (host != null ? host.getHostId() : null); - this.sourceObjId = (sourceObj != null ? sourceObj.getId() : null); - } - - /** - * Get the host id for the account attribute. - * - * @return Optional with Host id. - */ - public Optional<Long> getHostId() { - return Optional.ofNullable(hostId); - } - - /** - * Get the object id of account to which this attribute applies. - * - * @return Account row id. - */ - public long getOsAccountObjectId() { - return osAccountObjId; - } - - /** - * Get the object id of the source where the attribute was found. - * - * @return Object id of source. - */ - public Optional<Long> getSourceObjectId() { - return Optional.ofNullable(sourceObjId); - } -} diff --git a/bindings/java/src/org/sleuthkit/datamodel/OsAccountManager.java b/bindings/java/src/org/sleuthkit/datamodel/OsAccountManager.java index bda9fdd2295aa8a971f0e1b55b56aa7f2f1e8cfa..45660617238713bb3182875b91c6ebf752adb967 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/OsAccountManager.java +++ b/bindings/java/src/org/sleuthkit/datamodel/OsAccountManager.java @@ -37,6 +37,7 @@ import org.sleuthkit.datamodel.BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE; import org.sleuthkit.datamodel.OsAccount.OsAccountStatus; import org.sleuthkit.datamodel.OsAccount.OsAccountType; +import org.sleuthkit.datamodel.OsAccount.OsAccountAttribute; import org.sleuthkit.datamodel.SleuthkitCase.CaseDbConnection; import org.sleuthkit.datamodel.SleuthkitCase.CaseDbTransaction; @@ -74,7 +75,7 @@ public final class OsAccountManager { * @throws TskCoreException If there is an error in creating the OSAccount. * */ - OsAccount createOsAccount(String uniqueAccountId, OsAccountRealm realm) throws TskCoreException { + OsAccount newOsAccount(String uniqueAccountId, OsAccountRealm realm) throws TskCoreException { // ensure unique id is provided if (Strings.isNullOrEmpty(uniqueAccountId)) { @@ -90,7 +91,7 @@ OsAccount createOsAccount(String uniqueAccountId, OsAccountRealm realm) throws T // try to create account try { - OsAccount account = createOsAccount(uniqueAccountId, null, realm, OsAccount.OsAccountStatus.UNKNOWN, trans); + OsAccount account = newOsAccount(uniqueAccountId, null, realm, OsAccount.OsAccountStatus.UNKNOWN, trans); trans.commit(); trans = null; return account; @@ -139,7 +140,7 @@ OsAccount createOsAccount(String uniqueAccountId, OsAccountRealm realm) throws T * user SID. * */ - public OsAccount createWindowsOsAccount(String sid, String loginName, String realmName, Host referringHost, OsAccountRealm.RealmScope realmScope) throws TskCoreException, NotUserSIDException { + public OsAccount newWindowsOsAccount(String sid, String loginName, String realmName, Host referringHost, OsAccountRealm.RealmScope realmScope) throws TskCoreException, NotUserSIDException { if (realmScope == null) { throw new TskCoreException("RealmScope cannot be null. Use UNKNOWN if scope is not known."); @@ -171,14 +172,14 @@ public OsAccount createWindowsOsAccount(String sid, String loginName, String rea realm = realmOptional.get(); } else { // realm was not found, create it. - realm = db.getOsAccountRealmManager().createWindowsRealm(sid, realmName, referringHost, realmScope); + realm = db.getOsAccountRealmManager().newWindowsRealm(sid, realmName, referringHost, realmScope); } CaseDbTransaction trans = db.beginTransaction(); try { // try to create account try { - OsAccount account = createOsAccount(sid, loginName, realm, OsAccount.OsAccountStatus.UNKNOWN, trans); + OsAccount account = newOsAccount(sid, loginName, realm, OsAccount.OsAccountStatus.UNKNOWN, trans); trans.commit(); trans = null; return account; @@ -232,7 +233,7 @@ public OsAccount createWindowsOsAccount(String sid, String loginName, String rea * * @throws TskCoreException If there is an error creating the account. */ - private OsAccount createOsAccount(String uniqueId, String loginName, OsAccountRealm realm, OsAccount.OsAccountStatus accountStatus, CaseDbTransaction trans) throws TskCoreException, SQLException { + private OsAccount newOsAccount(String uniqueId, String loginName, OsAccountRealm realm, OsAccount.OsAccountStatus accountStatus, CaseDbTransaction trans) throws TskCoreException, SQLException { if (Objects.isNull(realm)) { throw new TskCoreException("Cannot create an OS Account, realm is NULL."); @@ -513,7 +514,7 @@ private Optional<Long> getOsAccountInstanceId(OsAccount osAccount, DataSource da * @throws TskCoreException If there is an error creating the account * instance. */ - public void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccountInstance.OsAccountInstanceType instanceType) throws TskCoreException { + public void newOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccountInstance.OsAccountInstanceType instanceType) throws TskCoreException { if (osAccount == null) { throw new TskCoreException("Cannot create account instance with null account."); } @@ -528,7 +529,7 @@ public void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, } try (CaseDbConnection connection = this.db.getConnection()) { - createOsAccountInstance(osAccount, dataSource, instanceType, connection); + newOsAccountInstance(osAccount, dataSource, instanceType, connection); } } @@ -544,7 +545,7 @@ public void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, * @throws TskCoreException If there is an error creating the account * instance. */ - void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccountInstance.OsAccountInstanceType instanceType, CaseDbConnection connection) throws TskCoreException { + void newOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccountInstance.OsAccountInstanceType instanceType, CaseDbConnection connection) throws TskCoreException { if (osAccount == null) { throw new TskCoreException("Cannot create account instance with null account."); @@ -553,7 +554,7 @@ void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccou throw new TskCoreException("Cannot create account instance with null data source."); } - createOsAccountInstance(osAccount, dataSource.getId(), instanceType, connection); + newOsAccountInstance(osAccount, dataSource.getId(), instanceType, connection); } /** @@ -568,7 +569,7 @@ void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccou * @throws TskCoreException If there is an error creating the account * instance. */ - void createOsAccountInstance(OsAccount osAccount, long dataSourceObjId, OsAccountInstance.OsAccountInstanceType instanceType, CaseDbConnection connection) throws TskCoreException { + void newOsAccountInstance(OsAccount osAccount, long dataSourceObjId, OsAccountInstance.OsAccountInstanceType instanceType, CaseDbConnection connection) throws TskCoreException { if (osAccount == null) { throw new TskCoreException("Cannot create account instance with null account."); @@ -837,9 +838,9 @@ private OsAccount mergeOsAccountObjectsAndUpdateDestAccount(OsAccount sourceAcc } // update the dest account core - AccountUpdateStatus updateStatus = this.updateOsAccountCore(destAccount, destAddr, destLoginName, trans); + OsAccountUpdateResult updateStatus = this.updateOsAccountCore(destAccount, destAddr, destLoginName, trans); - if (updateStatus.getUpdateStatusCode() == AccountUpdateStatusEnum.UPDATED && updateStatus.getUpdatedAccount().isPresent()) { + if (updateStatus.getUpdateStatusCode() == OsAccountUpdateStatus.UPDATED && updateStatus.getUpdatedAccount().isPresent()) { mergedDestAccount = updateStatus.getUpdatedAccount().get(); } @@ -854,9 +855,9 @@ private OsAccount mergeOsAccountObjectsAndUpdateDestAccount(OsAccount sourceAcc } // update the dest account properties - updateStatus = this.updateOsAccountProperties(destAccount, destFullName, null, null, destCreationTime, trans); + updateStatus = this.updateStandardOsAccountAttributes(destAccount, destFullName, null, null, destCreationTime, trans); - if (updateStatus.getUpdateStatusCode() == AccountUpdateStatusEnum.UPDATED && updateStatus.getUpdatedAccount().isPresent()) { + if (updateStatus.getUpdateStatusCode() == OsAccountUpdateStatus.UPDATED && updateStatus.getUpdatedAccount().isPresent()) { mergedDestAccount = updateStatus.getUpdatedAccount().get(); } @@ -976,7 +977,7 @@ public Optional<OsAccount> getWindowsOsAccount(String sid, String loginName, Str * * @throws TskCoreException */ - public void addOsAccountAttributes(OsAccount account, List<OsAccountAttribute> accountAttributes) throws TskCoreException { + public void addExtendedOsAccountAttributes(OsAccount account, List<OsAccountAttribute> accountAttributes) throws TskCoreException { synchronized (account) { // synchronized to prevent multiple threads trying to add osAccount attributes concurrently to the same osAccount. db.acquireSingleUserCaseWriteLock(); @@ -1090,7 +1091,7 @@ List<OsAccountAttribute> getOsAccountAttributes(OsAccount account) throws TskCor sourceContent = this.db.getContentById(sourceObjId); } BlackboardAttribute.Type attributeType = db.getAttributeType(rs.getInt("attribute_type_id")); - OsAccountAttribute attribute = new OsAccountAttribute(attributeType, rs.getInt("value_int32"), rs.getLong("value_int64"), + OsAccountAttribute attribute = account.new OsAccountAttribute(attributeType, rs.getInt("value_int32"), rs.getLong("value_int64"), rs.getDouble("value_double"), rs.getString("value_text"), rs.getBytes("value_byte"), db, account, host, sourceContent); @@ -1150,16 +1151,16 @@ List<OsAccountInstance> getOsAccountInstances(OsAccount account) throws TskCoreE * @param accountStatus Account status, may be null. * @param creationTime Creation time, may be null. * - * @return AccountUpdateStatus Account update status, and updated account. + * @return OsAccountUpdateResult Account update status, and updated account. * * @throws TskCoreException If there is a database error or if the updated * information conflicts with an existing account. */ - public AccountUpdateStatus updateOsAccountProperties(OsAccount osAccount, String fullName, OsAccountType accountType, OsAccountStatus accountStatus, Long creationTime) throws TskCoreException { + public OsAccountUpdateResult updateStandardOsAccountAttributes(OsAccount osAccount, String fullName, OsAccountType accountType, OsAccountStatus accountStatus, Long creationTime) throws TskCoreException { CaseDbTransaction trans = db.beginTransaction(); try { - AccountUpdateStatus updateStatus = updateOsAccountProperties(osAccount, fullName, accountType, accountStatus, creationTime, trans); + OsAccountUpdateResult updateStatus = updateStandardOsAccountAttributes(osAccount, fullName, accountType, accountStatus, creationTime, trans); trans.commit(); trans = null; @@ -1185,42 +1186,41 @@ public AccountUpdateStatus updateOsAccountProperties(OsAccount osAccount, String * @param creationTime Creation time, may be null. * @param trans Transaction to use for database operation. * - * @return AccountUpdateStatus Account update status, and updated account. + * @return OsAccountUpdateResult Account update status, and updated account. * * @throws TskCoreException If there is a database error or if the updated * information conflicts with an existing account. */ - AccountUpdateStatus updateOsAccountProperties(OsAccount osAccount, String fullName, OsAccountType accountType, OsAccountStatus accountStatus, Long creationTime, CaseDbTransaction trans) throws TskCoreException { + OsAccountUpdateResult updateStandardOsAccountAttributes(OsAccount osAccount, String fullName, OsAccountType accountType, OsAccountStatus accountStatus, Long creationTime, CaseDbTransaction trans) throws TskCoreException { - AccountUpdateStatusEnum updateStatusCode = AccountUpdateStatusEnum.NO_CHANGE; + OsAccountUpdateStatus updateStatusCode = OsAccountUpdateStatus.NO_CHANGE; try { CaseDbConnection connection = trans.getConnection(); if (!StringUtils.isBlank(fullName)) { updateAccountColumn(osAccount.getId(), "full_name", fullName, connection); - updateStatusCode = AccountUpdateStatusEnum.UPDATED; + updateStatusCode = OsAccountUpdateStatus.UPDATED; } if (Objects.nonNull(accountType)) { updateAccountColumn(osAccount.getId(), "type", accountType, connection); - updateStatusCode = AccountUpdateStatusEnum.UPDATED; + updateStatusCode = OsAccountUpdateStatus.UPDATED; } if (Objects.nonNull(accountStatus)) { updateAccountColumn(osAccount.getId(), "status", accountStatus, connection); - updateStatusCode = AccountUpdateStatusEnum.UPDATED; + updateStatusCode = OsAccountUpdateStatus.UPDATED; } if (Objects.nonNull(creationTime)) { - //newCreationTime = creationTime; updateAccountColumn(osAccount.getId(), "created_date", creationTime, connection); - updateStatusCode = AccountUpdateStatusEnum.UPDATED; + updateStatusCode = OsAccountUpdateStatus.UPDATED; } // if nothing has been changed, return - if (updateStatusCode == AccountUpdateStatusEnum.NO_CHANGE) { - return new AccountUpdateStatus(updateStatusCode, null); + if (updateStatusCode == OsAccountUpdateStatus.NO_CHANGE) { + return new OsAccountUpdateResult(updateStatusCode, null); } // get the updated account from database @@ -1229,7 +1229,7 @@ AccountUpdateStatus updateOsAccountProperties(OsAccount osAccount, String fullNa // register the updated account with the transaction to fire off an event trans.registerChangedOsAccount(updatedAccount); - return new AccountUpdateStatus(updateStatusCode, updatedAccount); + return new OsAccountUpdateResult(updateStatusCode, updatedAccount); } catch (SQLException ex) { throw new TskCoreException(String.format("Error updating account with addr = %s, account id = %d", osAccount.getAddr().orElse("Unknown"), osAccount.getId()), ex); @@ -1253,7 +1253,7 @@ private <T> void updateAccountColumn(long accountObjId, String colName, T colVal String updateSQL = "UPDATE tsk_os_accounts " + " SET " + colName + " = ? " - + " WHERE os_account_obj_id = ?"; // 5 + + " WHERE os_account_obj_id = ?"; PreparedStatement preparedStatement = connection.getPreparedStatement(updateSQL, Statement.NO_GENERATED_KEYS); preparedStatement.clearParameters(); @@ -1277,6 +1277,32 @@ private <T> void updateAccountColumn(long accountObjId, String colName, T colVal connection.executeUpdate(preparedStatement); } + /** + * Updates the signature of the specified account, if the db status of the + * account is active. + * + * @param accountObjId Object id of the account to be updated. + * @param signature New signature. + * @param connection Database connection to use. + * + * @throws SQLException If there is an error updating the database. + */ + private void updateAccountSignature(long accountObjId, String signature, CaseDbConnection connection) throws SQLException { + + String updateSQL = "UPDATE tsk_os_accounts SET " + + " signature = " + + " CASE WHEN db_status = " + OsAccount.OsAccountDbStatus.ACTIVE.getId() + " THEN ? ELSE signature END " + + " WHERE os_account_obj_id = ?"; // 8 + + PreparedStatement preparedStatement = connection.getPreparedStatement(updateSQL, Statement.NO_GENERATED_KEYS); + preparedStatement.clearParameters(); + + preparedStatement.setString(1, signature); + preparedStatement.setLong(2, accountObjId); + + connection.executeUpdate(preparedStatement); + } + /** * Update the address and/or login name for the specified account in the * database. Also update the realm addr/name if needed. @@ -1291,16 +1317,16 @@ private <T> void updateAccountColumn(long accountObjId, String colName, T colVal * @param realmName Realm name for the account. * @param referringHost Host. * - * @return AccountUpdateStatus Account update status, and the updated - * account. + * @return OsAccountUpdateResult Account update status, and the updated + account. * * @throws TskCoreException If there is a database error or if the updated * information conflicts with an existing account. */ - public AccountUpdateStatus updateWindowsOsAccountCore(OsAccount osAccount, String accountSid, String loginName, String realmName, Host referringHost) throws TskCoreException, NotUserSIDException { + public OsAccountUpdateResult updateCoreWindowsOsAccountAttributes(OsAccount osAccount, String accountSid, String loginName, String realmName, Host referringHost) throws TskCoreException, NotUserSIDException { CaseDbTransaction trans = db.beginTransaction(); try { - AccountUpdateStatus updateStatus = this.updateWindowsOsAccountCore(osAccount, accountSid, loginName, realmName, referringHost, trans); + OsAccountUpdateResult updateStatus = this.updateCoreWindowsOsAccountAttributes(osAccount, accountSid, loginName, realmName, referringHost, trans); trans.commit(); trans = null; @@ -1326,13 +1352,13 @@ public AccountUpdateStatus updateWindowsOsAccountCore(OsAccount osAccount, Strin * @param loginName Login name, may be null. * @param realmName Account realm name. May be null if accountSid is not null. * - * @return AccountUpdateStatus Account update status, and the updated - * account. + * @return OsAccountUpdateResult Account update status, and the updated + account. * * @throws TskCoreException If there is a database error or if the updated * information conflicts with an existing account. */ - private AccountUpdateStatus updateWindowsOsAccountCore(OsAccount osAccount, String accountSid, String loginName, String realmName, Host referringHost, CaseDbTransaction trans) throws TskCoreException, NotUserSIDException { + private OsAccountUpdateResult updateCoreWindowsOsAccountAttributes(OsAccount osAccount, String accountSid, String loginName, String realmName, Host referringHost, CaseDbTransaction trans) throws TskCoreException, NotUserSIDException { // first get and update the realm - if we have the info to find the realm if ( !StringUtils.isBlank(accountSid) || !StringUtils.isBlank(realmName) ) { @@ -1340,7 +1366,7 @@ private AccountUpdateStatus updateWindowsOsAccountCore(OsAccount osAccount, Str } // now update the account core data - AccountUpdateStatus updateStatus = this.updateOsAccountCore(osAccount, accountSid, loginName, trans); + OsAccountUpdateResult updateStatus = this.updateOsAccountCore(osAccount, accountSid, loginName, trans); return updateStatus; } @@ -1362,15 +1388,15 @@ private AccountUpdateStatus updateWindowsOsAccountCore(OsAccount osAccount, Str * @param address Account address, may be null. * @param loginName Login name, may be null. * - * @return AccountUpdateStatus Account update status, and the updated - * account. + * @return OsAccountUpdateResult Account update status, and the updated + account. * * @throws TskCoreException If there is a database error or if the updated * information conflicts with an existing account. */ - private AccountUpdateStatus updateOsAccountCore(OsAccount osAccount, String address, String loginName, CaseDbTransaction trans) throws TskCoreException { + private OsAccountUpdateResult updateOsAccountCore(OsAccount osAccount, String address, String loginName, CaseDbTransaction trans) throws TskCoreException { - AccountUpdateStatusEnum updateStatusCode = AccountUpdateStatusEnum.NO_CHANGE; + OsAccountUpdateStatus updateStatusCode = OsAccountUpdateStatus.NO_CHANGE; OsAccount updatedAccount; try { @@ -1388,23 +1414,23 @@ private AccountUpdateStatus updateOsAccountCore(OsAccount osAccount, String addr if (StringUtils.isBlank(osAccount.getAddr().orElse(null)) && !StringUtils.isBlank(address)) { updateAccountColumn(osAccount.getId(), "addr", address, connection); - updateStatusCode = AccountUpdateStatusEnum.UPDATED; + updateStatusCode = OsAccountUpdateStatus.UPDATED; } if (StringUtils.isBlank(osAccount.getLoginName().orElse(null)) && !StringUtils.isBlank(loginName)) { updateAccountColumn(osAccount.getId(), "login_name", loginName, connection); - updateStatusCode = AccountUpdateStatusEnum.UPDATED; + updateStatusCode = OsAccountUpdateStatus.UPDATED; } - // update signature if needed, only for active acounts - if (updateStatusCode == AccountUpdateStatusEnum.UPDATED && osAccount.getOsAccountDbStatus() == OsAccount.OsAccountDbStatus.ACTIVE) { + // update signature if needed + if (updateStatusCode == OsAccountUpdateStatus.UPDATED) { String newSignature = getOsAccountSignature(address, loginName); - updateAccountColumn(osAccount.getId(), "signature", newSignature, connection); + updateAccountSignature(osAccount.getId(), newSignature, connection); } // if nothing is changed, return - if (updateStatusCode == AccountUpdateStatusEnum.NO_CHANGE) { - return new AccountUpdateStatus(updateStatusCode, null); + if (updateStatusCode == OsAccountUpdateStatus.NO_CHANGE) { + return new OsAccountUpdateResult(updateStatusCode, osAccount); } // get the updated account from database updatedAccount = getOsAccountByObjectId(osAccount.getId(), connection); @@ -1412,7 +1438,7 @@ private AccountUpdateStatus updateOsAccountCore(OsAccount osAccount, String addr // register the updated account with the transaction to fire off an event trans.registerChangedOsAccount(updatedAccount); - return new AccountUpdateStatus(updateStatusCode, updatedAccount); + return new OsAccountUpdateResult(updateStatusCode, updatedAccount); } catch (SQLException ex) { throw new TskCoreException(String.format("Error updating account with unique id = %s, account id = %d", osAccount.getAddr().orElse("Unknown"), osAccount.getId()), ex); @@ -1661,7 +1687,7 @@ public NotUserSIDException(String msg, Exception ex) { /** * Status of an account update. */ - public enum AccountUpdateStatusEnum { + public enum OsAccountUpdateStatus { NO_CHANGE, /// no change was made to account. UPDATED, /// account was updated @@ -1671,18 +1697,18 @@ public enum AccountUpdateStatusEnum { /** * Container that encapsulates the account update status and the updated account. */ - public final static class AccountUpdateStatus { + public final static class OsAccountUpdateResult { - private final AccountUpdateStatusEnum updateStatusCode; + private final OsAccountUpdateStatus updateStatus; private final OsAccount updatedAccount; - AccountUpdateStatus(AccountUpdateStatusEnum updateStatusEnum, OsAccount updatedAccount) { - this.updateStatusCode = updateStatusEnum; + OsAccountUpdateResult(OsAccountUpdateStatus updateStatus, OsAccount updatedAccount) { + this.updateStatus = updateStatus; this.updatedAccount = updatedAccount; } - public AccountUpdateStatusEnum getUpdateStatusCode() { - return updateStatusCode; + public OsAccountUpdateStatus getUpdateStatusCode() { + return updateStatus; } public Optional<OsAccount> getUpdatedAccount() { diff --git a/bindings/java/src/org/sleuthkit/datamodel/OsAccountRealmManager.java b/bindings/java/src/org/sleuthkit/datamodel/OsAccountRealmManager.java index 6f1cb08cee01860276ac608630032c8c8a891fa3..c9ebe104eb3b02a50ea099822e1a590233a0bea0 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/OsAccountRealmManager.java +++ b/bindings/java/src/org/sleuthkit/datamodel/OsAccountRealmManager.java @@ -72,7 +72,7 @@ public final class OsAccountRealmManager { * @throws OsAccountManager.NotUserSIDException If the SID is not a user * SID. */ - public OsAccountRealm createWindowsRealm(String accountSid, String realmName, Host referringHost, OsAccountRealm.RealmScope realmScope) throws TskCoreException, OsAccountManager.NotUserSIDException { + public OsAccountRealm newWindowsRealm(String accountSid, String realmName, Host referringHost, OsAccountRealm.RealmScope realmScope) throws TskCoreException, OsAccountManager.NotUserSIDException { if (realmScope == null) { throw new TskCoreException("RealmScope cannot be null. Use UNKNOWN if scope is not known."); @@ -132,7 +132,7 @@ public OsAccountRealm createWindowsRealm(String accountSid, String realmName, Ho String signature = makeRealmSignature(realmAddr, realmName, scopeHost); // create a realm - return createRealm(realmName, realmAddr, signature, scopeHost, scopeConfidence); + return newRealm(realmName, realmAddr, signature, scopeHost, scopeConfidence); } /** @@ -226,7 +226,7 @@ Optional<OsAccountRealm> getWindowsRealm(String accountSid, String realmName, Ho * is an user/group account SID. The domain SID is extracted from this * incoming SID. * - * If a realm is found but is missing either the addr or the realmName, then + * If a realm is found but is missing either the SID or the realmName, then * the realm is updated. * * @param accountSid Account SID, may be null. @@ -248,11 +248,11 @@ Optional<OsAccountRealm> getAndUpdateWindowsRealm(String accountSid, String real // if found, update it if needed if (realmOptional.isPresent()) { String realmAddr = StringUtils.isNotBlank(accountSid) ? WindowsAccountUtils.getWindowsRealmAddress(accountSid) : null; - RealmUpdateStatus realmUpdateStatus = updateRealm(realmOptional.get(), realmAddr, realmName); + OsRealmUpdateResult realmUpdateResult = updateRealm(realmOptional.get(), realmAddr, realmName, connection); // if realm was updated, return the updated realm - if (realmUpdateStatus.getUpdateStatusCode() == RealmUpdateStatusEnum.UPDATED) { - return realmUpdateStatus.getUpdatedRealm(); + if (realmUpdateResult.getUpdateStatus() == OsRealmUpdateStatus.UPDATED) { + return realmUpdateResult.getUpdatedRealm(); } } @@ -261,8 +261,6 @@ Optional<OsAccountRealm> getAndUpdateWindowsRealm(String accountSid, String real /** - * Updates the address and/or name of specified realm in the database. - * * Updates the realm address and/or name, if a non blank address/name is * specified and the current address/name is blank. * @@ -277,12 +275,12 @@ Optional<OsAccountRealm> getAndUpdateWindowsRealm(String accountSid, String real * @param realmName Realm name, may be null if the name doesn't need to be * updated. * - * @return RealmUpdateStatus Update status and updated realm. + * @return OsRealmUpdateResult Update status and updated realm. * * @throws TskCoreException If there is a database error or if a realm * already exists with that information. */ - public RealmUpdateStatus updateRealm(OsAccountRealm realm, String realmAddr, String realmName) throws TskCoreException { + public OsRealmUpdateResult updateRealm(OsAccountRealm realm, String realmAddr, String realmName) throws TskCoreException { try (CaseDbConnection connection = db.getConnection()) { return updateRealm(realm, realmAddr, realmName, connection); @@ -290,8 +288,6 @@ public RealmUpdateStatus updateRealm(OsAccountRealm realm, String realmAddr, Str } /** - * Updates the address and/or name of specified realm in the database. - * * Updates the realm address and/or name, if a non blank address/name is * specified and the current address/name is blank. * @@ -302,19 +298,19 @@ public RealmUpdateStatus updateRealm(OsAccountRealm realm, String realmAddr, Str * updated. * @param connection Current database connection. * - * @return RealmUpdateStatus Update status and updated realm. + * @return OsRealmUpdateResult Update status and updated realm. * * @throws TskCoreException If there is a database error or if a realm * already exists with that information. */ - private RealmUpdateStatus updateRealm(OsAccountRealm realm, String realmAddr, String realmName, CaseDbConnection connection) throws TskCoreException { + private OsRealmUpdateResult updateRealm(OsAccountRealm realm, String realmAddr, String realmName, CaseDbConnection connection) throws TskCoreException { // need at least one of the two if (StringUtils.isBlank(realmAddr) && StringUtils.isBlank(realmName)) { throw new TskCoreException("Realm address or name is required to update realm."); } - RealmUpdateStatusEnum updateStatusCode = RealmUpdateStatusEnum.NO_CHANGE; + OsRealmUpdateStatus updateStatusCode = OsRealmUpdateStatus.NO_CHANGE; OsAccountRealm updatedRealm = null; List<String> realmNames = realm.getRealmNames(); @@ -326,7 +322,7 @@ private RealmUpdateStatus updateRealm(OsAccountRealm realm, String realmAddr, St String newRealmAddr; if ( (StringUtils.isBlank(currRealmAddr) && StringUtils.isNotBlank(realmAddr))) { newRealmAddr = realmAddr; - updateStatusCode = RealmUpdateStatusEnum.UPDATED; + updateStatusCode = OsRealmUpdateStatus.UPDATED; } else { newRealmAddr = currRealmAddr; } @@ -334,7 +330,7 @@ private RealmUpdateStatus updateRealm(OsAccountRealm realm, String realmAddr, St String newRealmName; if (StringUtils.isBlank(currRealmName) && StringUtils.isNotBlank(realmName)) { newRealmName = realmName; - updateStatusCode = RealmUpdateStatusEnum.UPDATED; + updateStatusCode = OsRealmUpdateStatus.UPDATED; } else { newRealmName = currRealmName; } @@ -343,8 +339,8 @@ private RealmUpdateStatus updateRealm(OsAccountRealm realm, String realmAddr, St String newSignature = makeRealmSignature(newRealmAddr, newRealmName, realm.getScopeHost().orElse(null)); // if nothing is to be changed, return - if ( updateStatusCode == RealmUpdateStatusEnum.NO_CHANGE) { - return new RealmUpdateStatus(updateStatusCode, null); + if ( updateStatusCode == OsRealmUpdateStatus.NO_CHANGE) { + return new OsRealmUpdateResult(updateStatusCode, realm); } @@ -366,9 +362,9 @@ private RealmUpdateStatus updateRealm(OsAccountRealm realm, String realmAddr, St connection.executeUpdate(preparedStatement); // read the updated realm - updatedRealm = this.getRealmById(realm.getRealmId(), connection); + updatedRealm = this.getRealmByRealmId(realm.getRealmId(), connection); - return new RealmUpdateStatus(updateStatusCode, updatedRealm); + return new OsRealmUpdateResult(updateStatusCode, updatedRealm); } catch (SQLException ex) { throw new TskCoreException(String.format("Error updating realm with id = %d, name = %s, addr = %s", realm.getRealmId(), realmName != null ? realmName : "Null", realm.getRealmAddr().orElse("Null") ), ex); } finally { @@ -393,9 +389,9 @@ private RealmUpdateStatus updateRealm(OsAccountRealm realm, String realmAddr, St * @throws TskCoreException on error */ - public OsAccountRealm getRealmById(long id) throws TskCoreException { + public OsAccountRealm getRealmByRealmId(long id) throws TskCoreException { try (CaseDbConnection connection = this.db.getConnection()) { - return getRealmById(id, connection); + return getRealmByRealmId(id, connection); } } @@ -408,7 +404,7 @@ public OsAccountRealm getRealmById(long id) throws TskCoreException { * @return Realm. * @throws TskCoreException */ - OsAccountRealm getRealmById(long id, CaseDbConnection connection) throws TskCoreException { + OsAccountRealm getRealmByRealmId(long id, CaseDbConnection connection) throws TskCoreException { String queryString = REALM_QUERY_STRING + " WHERE realms.id = " + id; @@ -652,7 +648,7 @@ private OsAccountRealm resultSetToAccountRealm(ResultSet rs) throws SQLException * * @throws TskCoreException If there is an internal error. */ - private OsAccountRealm createRealm(String realmName, String realmAddr, String signature, Host host, OsAccountRealm.ScopeConfidence scopeConfidence) throws TskCoreException { + private OsAccountRealm newRealm(String realmName, String realmAddr, String signature, Host host, OsAccountRealm.ScopeConfidence scopeConfidence) throws TskCoreException { db.acquireSingleUserCaseWriteLock(); try (CaseDbConnection connection = this.db.getConnection()) { @@ -789,7 +785,7 @@ void moveOrMergeRealm(OsAccountRealm sourceRealm, Host destHost, CaseDbTransacti // Merge the realm with the matching name into the realm with the matching address. // Reload from database afterward to make sure everything is up-to-date. mergeRealms(optDestRealmName.get(), optDestRealmAddr.get(), trans); - destRealm = getRealmById(optDestRealmAddr.get().getRealmId(), trans.getConnection()); + destRealm = getRealmByRealmId(optDestRealmAddr.get().getRealmId(), trans.getConnection()); } } } else if (optDestRealmAddr.isPresent()) { @@ -900,7 +896,7 @@ List<OsAccountRealm> getRealmsByHost(Host host, CaseDbConnection connection) thr /** * Status of a realm update. */ - public enum RealmUpdateStatusEnum { + public enum OsRealmUpdateStatus { NO_CHANGE, /// no change was made to account. UPDATED, /// account was updated @@ -911,18 +907,18 @@ public enum RealmUpdateStatusEnum { * Container to encapsulate the status returned by the realm update api, and * the updated realm. */ - public final static class RealmUpdateStatus { + public final static class OsRealmUpdateResult { - private final RealmUpdateStatusEnum updateStatusCode; - private final OsAccountRealm updatedRealm; // may be null if there is no update. + private final OsRealmUpdateStatus updateStatus; + private final OsAccountRealm updatedRealm; - RealmUpdateStatus(RealmUpdateStatusEnum updateStatusEnum, OsAccountRealm updatedRealm) { - this.updateStatusCode = updateStatusEnum; + OsRealmUpdateResult(OsRealmUpdateStatus updateStatus, OsAccountRealm updatedRealm) { + this.updateStatus = updateStatus; this.updatedRealm = updatedRealm; } - public RealmUpdateStatusEnum getUpdateStatusCode() { - return updateStatusCode; + public OsRealmUpdateStatus getUpdateStatus() { + return updateStatus; } public Optional<OsAccountRealm> getUpdatedRealm() { diff --git a/bindings/java/src/org/sleuthkit/datamodel/PersonManager.java b/bindings/java/src/org/sleuthkit/datamodel/PersonManager.java index 1956b4fdf2cf6e377b149151108ee08fb1fd48c3..2f60210216f5f22c468beccfc7c59314c29b27f6 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/PersonManager.java +++ b/bindings/java/src/org/sleuthkit/datamodel/PersonManager.java @@ -205,7 +205,7 @@ public Optional<Person> getPerson(long id) throws TskCoreException { * * @throws TskCoreException */ - public Person createPerson(String name) throws TskCoreException { + public Person newPerson(String name) throws TskCoreException { // Must have a name if (Strings.isNullOrEmpty(name)) { diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java index ad2d2de91d1e6c25b6a47b61ffd99dd6b6044f3a..ddc96594ca05efdccc7c23ef8da740f780d31d88 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java @@ -6499,7 +6499,7 @@ public LocalFilesDataSource addLocalFilesDataSource(String deviceId, String root // If no host was supplied, make one if (host == null) { - host = getHostManager().createHost("LogicalFileSet_" + newObjId + " Host", transaction); + host = getHostManager().newHost("LogicalFileSet_" + newObjId + " Host", transaction); } // Insert a row for the virtual directory of the data source into @@ -6656,9 +6656,9 @@ public Image addImage(TskData.TSK_IMG_TYPE_ENUM type, long sectorSize, long size // Create a host if needed if (host == null) { if (name.isEmpty()) { - host = getHostManager().createHost("Image_" + newObjId + " Host", transaction); + host = getHostManager().newHost("Image_" + newObjId + " Host", transaction); } else { - host = getHostManager().createHost(name + "_" + newObjId + " Host", transaction); + host = getHostManager().newHost(name + "_" + newObjId + " Host", transaction); } } @@ -7052,7 +7052,7 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId, } if(osAccount != null) { - osAccountManager.createOsAccountInstance(osAccount, dataSourceObjId, OsAccountInstance.OsAccountInstanceType.LAUNCHED, connection); + osAccountManager.newOsAccountInstance(osAccount, dataSourceObjId, OsAccountInstance.OsAccountInstanceType.LAUNCHED, connection); } return new org.sleuthkit.datamodel.File(this, objectId, dataSourceObjId, fsObjId, diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java index 41ba5f41174603c729d98e141f43d2ba3cb9af1b..1e847df0c96e8c957c11b758b5907c211476ceed 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitJNI.java @@ -449,7 +449,7 @@ long addImageInfo(long deviceObjId, List<String> imageFilePaths, String timeZone } else { hostName = "Image_" + deviceObjId + " Host"; } - host = skCase.getHostManager().createHost(hostName); + host = skCase.getHostManager().newHost(hostName); } TskCaseDbBridge dbHelper = new TskCaseDbBridge(skCase, new DefaultAddDataSourceCallbacks(), host); long tskAutoDbPointer = initializeAddImgNat(dbHelper, timezoneLongToShort(timeZone), false, false, false); diff --git a/bindings/java/src/org/sleuthkit/datamodel/TskCaseDbBridge.java b/bindings/java/src/org/sleuthkit/datamodel/TskCaseDbBridge.java index 3c02bc59a24e9e093faec2ddaf75242aca960122..ab761bf00ecff600be3e6a5d05d40a367ff927eb 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/TskCaseDbBridge.java +++ b/bindings/java/src/org/sleuthkit/datamodel/TskCaseDbBridge.java @@ -384,7 +384,7 @@ private long addBatchedFilesToDb() { } else { // account not found in the database, create the account and add to map // Currently we expect only NTFS systems to provide a windows style SID as owner id. - OsAccount newAccount = caseDb.getOsAccountManager().createWindowsOsAccount(ownerUid, null, null, imageHost, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount newAccount = caseDb.getOsAccountManager().newWindowsOsAccount(ownerUid, null, null, imageHost, OsAccountRealm.RealmScope.UNKNOWN); ownerIdToAccountMap.put(ownerUid, newAccount); } } catch (NotUserSIDException ex) { diff --git a/bindings/java/test/org/sleuthkit/datamodel/ArtifactTest.java b/bindings/java/test/org/sleuthkit/datamodel/ArtifactTest.java index 06da37bb59a6f235eff96c907c4bf17e7b5e2a09..26c3fa00380b3f255f474781ad11a56c6d04e2cd 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/ArtifactTest.java +++ b/bindings/java/test/org/sleuthkit/datamodel/ArtifactTest.java @@ -165,13 +165,13 @@ public void artifactTests() throws TskCoreException, Blackboard.BlackboardExcept String realmName1 = "realm1"; String ownerUid1 = "S-1-5-21-111111111-222222222-3333333333-0001"; - Host host1 = caseDB.getHostManager().createHost(hostname1); - OsAccountRealm localRealm1 = caseDB.getOsAccountRealmManager().createWindowsRealm(ownerUid1, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); - OsAccount osAccount1 = caseDB.getOsAccountManager().createWindowsOsAccount(ownerUid1, null, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); + Host host1 = caseDB.getHostManager().newHost(hostname1); + OsAccountRealm localRealm1 = caseDB.getOsAccountRealmManager().newWindowsRealm(ownerUid1, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccount osAccount1 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerUid1, null, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); // create a 2nd account on the same host String ownerUid2 = "S-1-5-21-111111111-222222222-3333333333-0009"; - OsAccount osAccount2 = caseDB.getOsAccountManager().createWindowsOsAccount(ownerUid2, null, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccount osAccount2 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerUid2, null, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); // now find the file abc.text diff --git a/bindings/java/test/org/sleuthkit/datamodel/OsAccountTest.java b/bindings/java/test/org/sleuthkit/datamodel/OsAccountTest.java index d5997f6ba27255f0403a67125c2a982ad5d9eb96..eeb5d566e5c381dc38112b6787574e8f8c1ad34c 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/OsAccountTest.java +++ b/bindings/java/test/org/sleuthkit/datamodel/OsAccountTest.java @@ -34,8 +34,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.sleuthkit.datamodel.OsAccountManager.AccountUpdateStatus; -import org.sleuthkit.datamodel.OsAccountRealmManager.RealmUpdateStatus; +import org.sleuthkit.datamodel.OsAccount.OsAccountAttribute; +import org.sleuthkit.datamodel.OsAccountManager.OsAccountUpdateResult; +import org.sleuthkit.datamodel.OsAccountRealmManager.OsRealmUpdateResult; /** * @@ -113,33 +114,33 @@ public void hostTests() throws TskCoreException { String HOSTNAME1 = "host11"; // Test: create a host - Host host1 = caseDB.getHostManager().createHost(HOSTNAME1); + Host host1 = caseDB.getHostManager().newHost(HOSTNAME1); assertEquals(host1.getName().equalsIgnoreCase(HOSTNAME1), true ); // Test: get a host we just created. - Optional<Host> optionalhost1 = caseDB.getHostManager().getHost(HOSTNAME1); + Optional<Host> optionalhost1 = caseDB.getHostManager().getHostByName(HOSTNAME1); assertEquals(optionalhost1.isPresent(), true ); String HOSTNAME2 = "host22"; // Get a host not yet created - Optional<Host> optionalhost2 = caseDB.getHostManager().getHost(HOSTNAME2); + Optional<Host> optionalhost2 = caseDB.getHostManager().getHostByName(HOSTNAME2); assertEquals(optionalhost2.isPresent(), false ); // now create the second host - Host host2 = caseDB.getHostManager().createHost(HOSTNAME2); + Host host2 = caseDB.getHostManager().newHost(HOSTNAME2); assertEquals(host2.getName().equalsIgnoreCase(HOSTNAME2), true ); // now get it again, should be found this time - optionalhost2 = caseDB.getHostManager().getHost(HOSTNAME2); + optionalhost2 = caseDB.getHostManager().getHostByName(HOSTNAME2); assertEquals(optionalhost2.isPresent(), true); // create a host that already exists - should transperently return the existting host. - Host host2_2 = caseDB.getHostManager().createHost(HOSTNAME2); + Host host2_2 = caseDB.getHostManager().newHost(HOSTNAME2); assertEquals(host2_2.getName().equalsIgnoreCase(HOSTNAME2), true ); } @@ -156,7 +157,7 @@ public void personTests() throws TskCoreException { org.sleuthkit.datamodel.PersonManager pm = caseDB.getPersonManager(); - Person p1 = pm.createPerson(personName1); + Person p1 = pm.newPerson(personName1); assertEquals(personName1.equals(p1.getName()), true); Optional<Person> p1opt = pm.getPerson(personName1.toLowerCase()); @@ -180,8 +181,8 @@ public void mergeHostTests() throws TskCoreException, OsAccountManager.NotUserSI // Host 1 will be merged into Host 2 String host1Name = "host1forHostMergeTest"; String host2Name = "host2forHostMergeTest"; - Host host1 = caseDB.getHostManager().createHost(host1Name); - Host host2 = caseDB.getHostManager().createHost(host2Name); + Host host1 = caseDB.getHostManager().newHost(host1Name); + Host host2 = caseDB.getHostManager().newHost(host2Name); // Data source is originally associated with host1 org.sleuthkit.datamodel.SleuthkitCase.CaseDbTransaction trans = caseDB.beginTransaction(); @@ -210,40 +211,40 @@ public void mergeHostTests() throws TskCoreException, OsAccountManager.NotUserSI OsAccountRealmManager realmManager = caseDB.getOsAccountRealmManager(); // 1 - Should get moved - OsAccountRealm realm1 = realmManager.createWindowsRealm(null, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm1 = realmManager.newWindowsRealm(null, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); // 2 - Should be merged into 5 - OsAccountRealm realm2 = realmManager.createWindowsRealm(null, realmName2, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm2 = realmManager.newWindowsRealm(null, realmName2, host1, OsAccountRealm.RealmScope.LOCAL); // 3 - Should be merged into 5 - OsAccountRealm realm3 = realmManager.createWindowsRealm(sid3, null, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm3 = realmManager.newWindowsRealm(sid3, null, host1, OsAccountRealm.RealmScope.LOCAL); // 4 - Should get moved - not merged into 6 since addrs are different - OsAccountRealm realm4 = realmManager.createWindowsRealm(sid4, realmName4, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm4 = realmManager.newWindowsRealm(sid4, realmName4, host1, OsAccountRealm.RealmScope.LOCAL); // 5 - 2 and 3 should get merged in - OsAccountRealm realm5 = realmManager.createWindowsRealm(sid3, realmName2, host2, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm5 = realmManager.newWindowsRealm(sid3, realmName2, host2, OsAccountRealm.RealmScope.LOCAL); // 6 - Should not get merged with 4 - OsAccountRealm realm6 = realmManager.createWindowsRealm(sid5, realmName4, host2, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm6 = realmManager.newWindowsRealm(sid5, realmName4, host2, OsAccountRealm.RealmScope.LOCAL); // 7 - Should be unchanged - OsAccountRealm realm7 = realmManager.createWindowsRealm(null, realmName5, host2, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm7 = realmManager.newWindowsRealm(null, realmName5, host2, OsAccountRealm.RealmScope.LOCAL); // 8, 9, 10 - 8 should be merged into 9 and then 10 should be merged into 9 - OsAccountRealm realm8 = realmManager.createWindowsRealm(null, realmName6, host2, OsAccountRealm.RealmScope.LOCAL); - OsAccount realm8acct = caseDB.getOsAccountManager().createWindowsOsAccount(null, realm8AcctName, realmName6, host2, OsAccountRealm.RealmScope.LOCAL); - OsAccountRealm realm9 = realmManager.createWindowsRealm(sid6, null, host2, OsAccountRealm.RealmScope.LOCAL); - OsAccountRealm realm10 = realmManager.createWindowsRealm(sid6, realmName6, host1, OsAccountRealm.RealmScope.LOCAL); - OsAccount realm10acct = caseDB.getOsAccountManager().createWindowsOsAccount(null, realm10AcctName, realmName6, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm8 = realmManager.newWindowsRealm(null, realmName6, host2, OsAccountRealm.RealmScope.LOCAL); + OsAccount realm8acct = caseDB.getOsAccountManager().newWindowsOsAccount(null, realm8AcctName, realmName6, host2, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm9 = realmManager.newWindowsRealm(sid6, null, host2, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm10 = realmManager.newWindowsRealm(sid6, realmName6, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccount realm10acct = caseDB.getOsAccountManager().newWindowsOsAccount(null, realm10AcctName, realmName6, host1, OsAccountRealm.RealmScope.LOCAL); // 11, 12 - 11 should get merged into 12, adding the addr "sid8" to 12 - OsAccountRealm realm11 = realmManager.createWindowsRealm(sid8, realmName7, host1, OsAccountRealm.RealmScope.LOCAL); - OsAccountRealm realm12 = realmManager.createWindowsRealm(null, realmName7, host2, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm11 = realmManager.newWindowsRealm(sid8, realmName7, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm12 = realmManager.newWindowsRealm(null, realmName7, host2, OsAccountRealm.RealmScope.LOCAL); // 13,14 - 13 should get merged into 14, name for 14 should not change - OsAccountRealm realm13 = realmManager.createWindowsRealm(sid7, "notRealm8", host1, OsAccountRealm.RealmScope.LOCAL); - OsAccountRealm realm14 = realmManager.createWindowsRealm(sid7, realmName8, host2, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm13 = realmManager.newWindowsRealm(sid7, "notRealm8", host1, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm14 = realmManager.newWindowsRealm(sid7, realmName8, host2, OsAccountRealm.RealmScope.LOCAL); // Do the merge caseDB.getHostManager().mergeHosts(host1, host2); @@ -288,15 +289,15 @@ public void mergeHostTests() throws TskCoreException, OsAccountManager.NotUserSI } // The data source should now reference host2 - Host host = caseDB.getHostManager().getHost(ds); + Host host = caseDB.getHostManager().getHostByDataSource(ds); assertEquals(host.getHostId() == host2.getHostId(), true); // We should get no results on a search for host1 - Optional<Host> optHost = caseDB.getHostManager().getHost(host1Name); + Optional<Host> optHost = caseDB.getHostManager().getHostByName(host1Name); assertEquals(optHost.isPresent(), false); // If we attempt to make a new host with the same name host1 had, we should get a new object Id - host = caseDB.getHostManager().createHost(host1Name); + host = caseDB.getHostManager().newHost(host1Name); assertEquals(host.getHostId() != host1.getHostId(), true); } @@ -307,7 +308,7 @@ public void mergeHostTests() throws TskCoreException, OsAccountManager.NotUserSI private void testUpdatedRealm(OsAccountRealm origRealm, OsAccountRealm.RealmDbStatus expectedStatus, Optional<String> expectedAddr, List<String> expectedNames, Optional<Host> expectedHost, org.sleuthkit.datamodel.SleuthkitCase.CaseDbConnection connection) throws TskCoreException { - OsAccountRealm realm = caseDB.getOsAccountRealmManager().getRealmById(origRealm.getRealmId(), connection); + OsAccountRealm realm = caseDB.getOsAccountRealmManager().getRealmByRealmId(origRealm.getRealmId(), connection); assertEquals(realm.getDbStatus().equals(expectedStatus), true); if (expectedAddr != null) { assertEquals(realm.getRealmAddr().equals(expectedAddr), true); @@ -323,7 +324,7 @@ private void testUpdatedRealm(OsAccountRealm origRealm, OsAccountRealm.RealmDbSt @Test public void mergeRealmsTests() throws TskCoreException, OsAccountManager.NotUserSIDException { - Host host = caseDB.getHostManager().createHost("mergeTestHost"); + Host host = caseDB.getHostManager().newHost("mergeTestHost"); String destRealmName = "mergeTestDestRealm"; String srcRealmName = "mergeTestSourceRealm"; @@ -336,26 +337,26 @@ public void mergeRealmsTests() throws TskCoreException, OsAccountManager.NotUser String fullName1 = "FullName1"; long creationTime1 = 555; - OsAccountRealm srcRealm = caseDB.getOsAccountRealmManager().createWindowsRealm(null, srcRealmName, host, OsAccountRealm.RealmScope.LOCAL); - OsAccountRealm destRealm = caseDB.getOsAccountRealmManager().createWindowsRealm(null, destRealmName, host, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm srcRealm = caseDB.getOsAccountRealmManager().newWindowsRealm(null, srcRealmName, host, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm destRealm = caseDB.getOsAccountRealmManager().newWindowsRealm(null, destRealmName, host, OsAccountRealm.RealmScope.LOCAL); - OsAccount account1 = caseDB.getOsAccountManager().createWindowsOsAccount(null, "uniqueRealm1Account", destRealmName, host, OsAccountRealm.RealmScope.LOCAL); - OsAccount account2 = caseDB.getOsAccountManager().createWindowsOsAccount(null, matchingName, destRealmName, host, OsAccountRealm.RealmScope.LOCAL); - OsAccount account3 = caseDB.getOsAccountManager().createWindowsOsAccount(null, uniqueRealm2Name, srcRealmName, host, OsAccountRealm.RealmScope.LOCAL); - OsAccount account4 = caseDB.getOsAccountManager().createWindowsOsAccount(null, matchingName, srcRealmName, host, OsAccountRealm.RealmScope.LOCAL); + OsAccount account1 = caseDB.getOsAccountManager().newWindowsOsAccount(null, "uniqueRealm1Account", destRealmName, host, OsAccountRealm.RealmScope.LOCAL); + OsAccount account2 = caseDB.getOsAccountManager().newWindowsOsAccount(null, matchingName, destRealmName, host, OsAccountRealm.RealmScope.LOCAL); + OsAccount account3 = caseDB.getOsAccountManager().newWindowsOsAccount(null, uniqueRealm2Name, srcRealmName, host, OsAccountRealm.RealmScope.LOCAL); + OsAccount account4 = caseDB.getOsAccountManager().newWindowsOsAccount(null, matchingName, srcRealmName, host, OsAccountRealm.RealmScope.LOCAL); - AccountUpdateStatus updateStatus = caseDB.getOsAccountManager().updateOsAccountProperties(account4, fullName1, null, null, creationTime1); - assertEquals(updateStatus.getUpdateStatusCode(), OsAccountManager.AccountUpdateStatusEnum.UPDATED); - assertEquals(updateStatus.getUpdatedAccount().isPresent(), true); - account4 = updateStatus.getUpdatedAccount().orElseThrow(() -> new TskCoreException("Updated account not found.")); + OsAccountUpdateResult updateResult = caseDB.getOsAccountManager().updateStandardOsAccountAttributes(account4, fullName1, null, null, creationTime1); + assertEquals(updateResult.getUpdateStatusCode(), OsAccountManager.OsAccountUpdateStatus.UPDATED); + assertEquals(updateResult.getUpdatedAccount().isPresent(), true); + account4 = updateResult.getUpdatedAccount().orElseThrow(() -> new TskCoreException("Updated account not found.")); - OsAccount account5 = caseDB.getOsAccountManager().createWindowsOsAccount(sid1, null, destRealmName, host, OsAccountRealm.RealmScope.LOCAL); - OsAccount account6 = caseDB.getOsAccountManager().createWindowsOsAccount(sid1, null, srcRealmName, host, OsAccountRealm.RealmScope.LOCAL); - OsAccount account7 = caseDB.getOsAccountManager().createWindowsOsAccount(sid2, null, destRealmName, host, OsAccountRealm.RealmScope.LOCAL); - OsAccount account8 = caseDB.getOsAccountManager().createWindowsOsAccount(null, "nameForCombining", destRealmName, host, OsAccountRealm.RealmScope.LOCAL); - OsAccount account9 = caseDB.getOsAccountManager().createWindowsOsAccount(sid2, "nameForCombining", srcRealmName, host, OsAccountRealm.RealmScope.LOCAL); + OsAccount account5 = caseDB.getOsAccountManager().newWindowsOsAccount(sid1, null, destRealmName, host, OsAccountRealm.RealmScope.LOCAL); + OsAccount account6 = caseDB.getOsAccountManager().newWindowsOsAccount(sid1, null, srcRealmName, host, OsAccountRealm.RealmScope.LOCAL); + OsAccount account7 = caseDB.getOsAccountManager().newWindowsOsAccount(sid2, null, destRealmName, host, OsAccountRealm.RealmScope.LOCAL); + OsAccount account8 = caseDB.getOsAccountManager().newWindowsOsAccount(null, "nameForCombining", destRealmName, host, OsAccountRealm.RealmScope.LOCAL); + OsAccount account9 = caseDB.getOsAccountManager().newWindowsOsAccount(sid2, "nameForCombining", srcRealmName, host, OsAccountRealm.RealmScope.LOCAL); // Test that we can currently get the source realm by name Optional<OsAccountRealm> optRealm = caseDB.getOsAccountRealmManager().getWindowsRealm(null, srcRealmName, host); @@ -428,14 +429,14 @@ public void hostAddressTests() throws TskCoreException { String hostnameStr = "basis.com"; // Test creation - HostAddress ipv4addr = caseDB.getHostAddressManager().createHostAddress(HostAddress.HostAddressType.IPV4, ipv4Str); + HostAddress ipv4addr = caseDB.getHostAddressManager().newHostAddress(HostAddress.HostAddressType.IPV4, ipv4Str); assertEquals(ipv4addr.getAddress().equalsIgnoreCase(ipv4Str), true); - HostAddress addr2 = caseDB.getHostAddressManager().createHostAddress(HostAddress.HostAddressType.DNS_AUTO, ipv6Str); + HostAddress addr2 = caseDB.getHostAddressManager().newHostAddress(HostAddress.HostAddressType.DNS_AUTO, ipv6Str); assertEquals(addr2.getAddress().equalsIgnoreCase(ipv6Str), true); assertEquals(HostAddress.HostAddressType.IPV6.equals(addr2.getAddressType()), true); - HostAddress hostAddr = caseDB.getHostAddressManager().createHostAddress(HostAddress.HostAddressType.DNS_AUTO, hostnameStr); + HostAddress hostAddr = caseDB.getHostAddressManager().newHostAddress(HostAddress.HostAddressType.DNS_AUTO, hostnameStr); assertEquals(hostAddr.getAddress().equalsIgnoreCase(hostnameStr), true); assertEquals(HostAddress.HostAddressType.HOSTNAME.equals(hostAddr.getAddressType()), true); @@ -444,7 +445,7 @@ public void hostAddressTests() throws TskCoreException { assertEquals(addr4opt.isPresent(), true); // Test host map - Host host = caseDB.getHostManager().createHost("TestHostAddress"); + Host host = caseDB.getHostManager().newHost("TestHostAddress"); trans = caseDB.beginTransaction(); DataSource ds = caseDB.addLocalFilesDataSource("devId", "pathToFiles", "EST", null, trans); @@ -486,13 +487,13 @@ public void osAccountRealmTests() throws TskCoreException, OsAccountManager.NotU // TEST: create a DOMAIN realm String HOSTNAME1 = "host1"; - Host host1 = caseDB.getHostManager().createHost(HOSTNAME1); + Host host1 = caseDB.getHostManager().newHost(HOSTNAME1); String realmName1 = "basis"; String realmSID1 = "S-1-5-21-1111111111-2222222222-3333333333"; String realmAddr1 = "S-1-5-21-1111111111-2222222222"; - OsAccountRealm domainRealm1 = caseDB.getOsAccountRealmManager().createWindowsRealm(realmSID1, realmName1, host1, OsAccountRealm.RealmScope.DOMAIN); + OsAccountRealm domainRealm1 = caseDB.getOsAccountRealmManager().newWindowsRealm(realmSID1, realmName1, host1, OsAccountRealm.RealmScope.DOMAIN); assertEquals(domainRealm1.getRealmNames().get(0).equalsIgnoreCase(realmName1), true ); assertEquals(domainRealm1.getScopeConfidence(), OsAccountRealm.ScopeConfidence.KNOWN); @@ -505,17 +506,17 @@ public void osAccountRealmTests() throws TskCoreException, OsAccountManager.NotU String realmName2 = "win-raman-abcd"; String hostName2 = "host2"; - Host host2 = caseDB.getHostManager().createHost(hostName2); - OsAccountRealm localRealm2 = caseDB.getOsAccountRealmManager().createWindowsRealm(realmSID2, null, host2, OsAccountRealm.RealmScope.LOCAL); + Host host2 = caseDB.getHostManager().newHost(hostName2); + OsAccountRealm localRealm2 = caseDB.getOsAccountRealmManager().newWindowsRealm(realmSID2, null, host2, OsAccountRealm.RealmScope.LOCAL); assertEquals(localRealm2.getRealmAddr().orElse("").equalsIgnoreCase(realmAddr2), true ); assertEquals(localRealm2.getScopeHost().orElse(null).getName().equalsIgnoreCase(hostName2), true); // update the a realm name on a existing realm. - RealmUpdateStatus realmUpdateStatus = caseDB.getOsAccountRealmManager().updateRealm(localRealm2, null, realmName2 ); - assertEquals(realmUpdateStatus.getUpdateStatusCode(), OsAccountRealmManager.RealmUpdateStatusEnum.UPDATED ); - assertTrue(realmUpdateStatus.getUpdatedRealm().isPresent()); + OsRealmUpdateResult realmUpdateResult = caseDB.getOsAccountRealmManager().updateRealm(localRealm2, null, realmName2 ); + assertEquals(realmUpdateResult.getUpdateStatus(), OsAccountRealmManager.OsRealmUpdateStatus.UPDATED ); + assertTrue(realmUpdateResult.getUpdatedRealm().isPresent()); - OsAccountRealm updatedRealm2 = realmUpdateStatus.getUpdatedRealm().get(); + OsAccountRealm updatedRealm2 = realmUpdateResult.getUpdatedRealm().get(); assertTrue(updatedRealm2.getRealmAddr().orElse("").equalsIgnoreCase(realmAddr2)); assertTrue(updatedRealm2.getRealmNames().get(0).equalsIgnoreCase(realmName2)); @@ -525,7 +526,7 @@ public void osAccountRealmTests() throws TskCoreException, OsAccountManager.NotU String realmSID3 = realmAddr1 + "-88888888"; String hostName3 = "host3"; - Host host3 = caseDB.getHostManager().createHost(hostName3); + Host host3 = caseDB.getHostManager().newHost(hostName3); // expect this to return realm1 Optional<OsAccountRealm> existingRealm3 = caseDB.getOsAccountRealmManager().getWindowsRealm(realmSID3, null, host3); @@ -536,7 +537,7 @@ public void osAccountRealmTests() throws TskCoreException, OsAccountManager.NotU // TEST get a existing LOCAL realm by addr, BUT on a new referring host. String hostName4 = "host4"; - Host host4 = caseDB.getHostManager().createHost(hostName4); + Host host4 = caseDB.getHostManager().newHost(hostName4); // Although the realm exists with this addr, it should NOT match since the host is different from what the realm was created with Optional<OsAccountRealm> realm4 = caseDB.getOsAccountRealmManager().getWindowsRealm(realmSID2, null, host4); @@ -564,22 +565,22 @@ public void basicOsAccountTests() throws TskCoreException, OsAccountManager.NotU String realmName1 = "local"; String hostname1 = "host1"; - Host host1 = caseDB.getHostManager().createHost(hostname1); + Host host1 = caseDB.getHostManager().newHost(hostname1); - //OsAccountRealm localRealm1 = caseDB.getOsAccountRealmManager().createWindowsRealm(ownerUid1, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); - OsAccount osAccount1 = caseDB.getOsAccountManager().createWindowsOsAccount(ownerUid1, loginName1, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); + //OsAccountRealm localRealm1 = caseDB.getOsAccountRealmManager().newWindowsRealm(ownerUid1, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccount osAccount1 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerUid1, loginName1, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); assertEquals(osAccount1.getAddr().orElse("").equalsIgnoreCase(ownerUid1), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(osAccount1.getRealmId()).getRealmNames().get(0).equalsIgnoreCase(realmName1), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount1.getRealmId()).getRealmNames().get(0).equalsIgnoreCase(realmName1), true); // Create another account - with same SID on the same host - should return the existing account String loginName11 = "BlueJay"; String realmName11 = "DESKTOP-9TO5"; - OsAccount osAccount11 = caseDB.getOsAccountManager().createWindowsOsAccount(ownerUid1, loginName11, realmName11, host1, OsAccountRealm.RealmScope.DOMAIN); + OsAccount osAccount11 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerUid1, loginName11, realmName11, host1, OsAccountRealm.RealmScope.DOMAIN); // account should be the same as osAccount1 assertEquals(osAccount11.getAddr().orElse("").equalsIgnoreCase(ownerUid1), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(osAccount11.getRealmId()).getRealmNames().get(0).equalsIgnoreCase(realmName1), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount11.getRealmId()).getRealmNames().get(0).equalsIgnoreCase(realmName1), true); assertEquals(osAccount11.getLoginName().orElse("").equalsIgnoreCase(loginName1), true); @@ -588,21 +589,21 @@ public void basicOsAccountTests() throws TskCoreException, OsAccountManager.NotU Long creationTime1 = 1611858618L; - AccountUpdateStatus updateStatus = caseDB.getOsAccountManager().updateOsAccountProperties(osAccount1, fullName1, null, null, creationTime1 ); - assertEquals(updateStatus.getUpdateStatusCode(), OsAccountManager.AccountUpdateStatusEnum.UPDATED); - assertTrue(updateStatus.getUpdatedAccount().isPresent()); + OsAccountUpdateResult updateResult = caseDB.getOsAccountManager().updateStandardOsAccountAttributes(osAccount1, fullName1, null, null, creationTime1 ); + assertEquals(updateResult.getUpdateStatusCode(), OsAccountManager.OsAccountUpdateStatus.UPDATED); + assertTrue(updateResult.getUpdatedAccount().isPresent()); - osAccount1 = updateStatus.getUpdatedAccount().orElseThrow(() -> new TskCoreException("Updated account not found")); + osAccount1 = updateResult.getUpdatedAccount().orElseThrow(() -> new TskCoreException("Updated account not found")); assertEquals(osAccount1.getCreationTime().orElse(null), creationTime1); assertEquals(osAccount1.getFullName().orElse(null).equalsIgnoreCase(fullName1), true ); // now try and create osAccount1 again - it should return the existing account - OsAccount osAccount1_copy1 = caseDB.getOsAccountManager().createWindowsOsAccount(ownerUid1, null, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccount osAccount1_copy1 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerUid1, null, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); assertEquals(osAccount1_copy1.getAddr().orElse("").equalsIgnoreCase(ownerUid1), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(osAccount1_copy1.getRealmId()).getRealmNames().get(0).equalsIgnoreCase(realmName1), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount1_copy1.getRealmId()).getRealmNames().get(0).equalsIgnoreCase(realmName1), true); assertEquals(osAccount1_copy1.getFullName().orElse("").equalsIgnoreCase(fullName1), true); @@ -626,21 +627,21 @@ public void basicOsAccountTests() throws TskCoreException, OsAccountManager.NotU String hostname2 = "host2"; String hostname3 = "host3"; - Host host2 = caseDB.getHostManager().createHost(hostname2); - Host host3 = caseDB.getHostManager().createHost(hostname3); + Host host2 = caseDB.getHostManager().newHost(hostname2); + Host host3 = caseDB.getHostManager().newHost(hostname3); - OsAccountRealm domainRealm1 = caseDB.getOsAccountRealmManager().createWindowsRealm(ownerUid2, realmName2, host2, OsAccountRealm.RealmScope.DOMAIN); + OsAccountRealm domainRealm1 = caseDB.getOsAccountRealmManager().newWindowsRealm(ownerUid2, realmName2, host2, OsAccountRealm.RealmScope.DOMAIN); // create accounts in this domain scoped realm - OsAccount osAccount2 = caseDB.getOsAccountManager().createWindowsOsAccount(ownerUid2, null, realmName2, host2, OsAccountRealm.RealmScope.DOMAIN); - OsAccount osAccount3 = caseDB.getOsAccountManager().createWindowsOsAccount(ownerUid3, null, realmName2, host3, OsAccountRealm.RealmScope.DOMAIN); + OsAccount osAccount2 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerUid2, null, realmName2, host2, OsAccountRealm.RealmScope.DOMAIN); + OsAccount osAccount3 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerUid3, null, realmName2, host3, OsAccountRealm.RealmScope.DOMAIN); assertEquals(osAccount2.getAddr().orElse("").equalsIgnoreCase(ownerUid2), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(osAccount2.getRealmId()).getRealmNames().get(0).equalsIgnoreCase(realmName2), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount2.getRealmId()).getRealmNames().get(0).equalsIgnoreCase(realmName2), true); assertEquals(osAccount3.getAddr().orElse("").equalsIgnoreCase(ownerUid3), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(osAccount3.getRealmId()).getRealmNames().get(0).equalsIgnoreCase(realmName2), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount3.getRealmId()).getRealmNames().get(0).equalsIgnoreCase(realmName2), true); } @@ -662,50 +663,50 @@ public void windowsSpecialAccountTests() throws TskCoreException, OsAccountManag // TEST create accounts with special SIDs on host2 { String hostname2 = "host222"; - Host host2 = caseDB.getHostManager().createHost(hostname2); + Host host2 = caseDB.getHostManager().newHost(hostname2); String specialSid1 = "S-1-5-18"; String specialSid2 = "S-1-5-19"; String specialSid3 = "S-1-5-20"; - OsAccount specialAccount1 = caseDB.getOsAccountManager().createWindowsOsAccount(specialSid1, null, null, host2, OsAccountRealm.RealmScope.UNKNOWN); - OsAccount specialAccount2 = caseDB.getOsAccountManager().createWindowsOsAccount(specialSid2, null, null, host2, OsAccountRealm.RealmScope.UNKNOWN); - OsAccount specialAccount3 = caseDB.getOsAccountManager().createWindowsOsAccount(specialSid3, null, null, host2, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount specialAccount1 = caseDB.getOsAccountManager().newWindowsOsAccount(specialSid1, null, null, host2, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount specialAccount2 = caseDB.getOsAccountManager().newWindowsOsAccount(specialSid2, null, null, host2, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount specialAccount3 = caseDB.getOsAccountManager().newWindowsOsAccount(specialSid3, null, null, host2, OsAccountRealm.RealmScope.UNKNOWN); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount1.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount2.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount3.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount1.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount2.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount3.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); } // TEST create accounts with special SIDs on host3 - should create their own realm { String hostname3 = "host333"; - Host host3 = caseDB.getHostManager().createHost(hostname3); + Host host3 = caseDB.getHostManager().newHost(hostname3); String specialSid1 = "S-1-5-18"; String specialSid2 = "S-1-5-19"; String specialSid3 = "S-1-5-20"; - OsAccount specialAccount1 = caseDB.getOsAccountManager().createWindowsOsAccount(specialSid1, null, null, host3, OsAccountRealm.RealmScope.UNKNOWN); - OsAccount specialAccount2 = caseDB.getOsAccountManager().createWindowsOsAccount(specialSid2, null, null, host3, OsAccountRealm.RealmScope.UNKNOWN); - OsAccount specialAccount3 = caseDB.getOsAccountManager().createWindowsOsAccount(specialSid3, null, null, host3, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount specialAccount1 = caseDB.getOsAccountManager().newWindowsOsAccount(specialSid1, null, null, host3, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount specialAccount2 = caseDB.getOsAccountManager().newWindowsOsAccount(specialSid2, null, null, host3, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount specialAccount3 = caseDB.getOsAccountManager().newWindowsOsAccount(specialSid3, null, null, host3, OsAccountRealm.RealmScope.UNKNOWN); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount1.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount2.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount3.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount1.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount2.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount3.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); // verify a new local realm with host3 was created for these account even they've been seen previously on another host - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount1.getRealmId()).getScopeHost().orElse(null).getName().equalsIgnoreCase(hostname3), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount1.getRealmId()).getScopeHost().orElse(null).getName().equalsIgnoreCase(hostname3), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount1.getRealmId()).getScopeHost().orElse(null).getName().equalsIgnoreCase(hostname3), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount1.getRealmId()).getScopeHost().orElse(null).getName().equalsIgnoreCase(hostname3), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount1.getRealmId()).getScopeHost().orElse(null).getName().equalsIgnoreCase(hostname3), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount1.getRealmId()).getScopeHost().orElse(null).getName().equalsIgnoreCase(hostname3), true); } // Test some other special account. { String hostname4 = "host444"; - Host host4 = caseDB.getHostManager().createHost(hostname4); + Host host4 = caseDB.getHostManager().newHost(hostname4); String specialSid1 = "S-1-5-80-3696737894-3623014651-202832235-645492566-13622391"; String specialSid2 = "S-1-5-82-4003674586-223046494-4022293810-2417516693-151509167"; @@ -713,16 +714,16 @@ public void windowsSpecialAccountTests() throws TskCoreException, OsAccountManag String specialSid4 = "S-1-5-96-0-3"; - OsAccount specialAccount1 = caseDB.getOsAccountManager().createWindowsOsAccount(specialSid1, null, null, host4, OsAccountRealm.RealmScope.UNKNOWN); - OsAccount specialAccount2 = caseDB.getOsAccountManager().createWindowsOsAccount(specialSid2, null, null, host4, OsAccountRealm.RealmScope.UNKNOWN); - OsAccount specialAccount3 = caseDB.getOsAccountManager().createWindowsOsAccount(specialSid3, null, null, host4, OsAccountRealm.RealmScope.UNKNOWN); - OsAccount specialAccount4 = caseDB.getOsAccountManager().createWindowsOsAccount(specialSid4, null, null, host4, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount specialAccount1 = caseDB.getOsAccountManager().newWindowsOsAccount(specialSid1, null, null, host4, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount specialAccount2 = caseDB.getOsAccountManager().newWindowsOsAccount(specialSid2, null, null, host4, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount specialAccount3 = caseDB.getOsAccountManager().newWindowsOsAccount(specialSid3, null, null, host4, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount specialAccount4 = caseDB.getOsAccountManager().newWindowsOsAccount(specialSid4, null, null, host4, OsAccountRealm.RealmScope.UNKNOWN); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount1.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount2.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount3.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); - assertEquals(caseDB.getOsAccountRealmManager().getRealmById(specialAccount4.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount1.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount2.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount3.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); + assertEquals(caseDB.getOsAccountRealmManager().getRealmByRealmId(specialAccount4.getRealmId()).getRealmAddr().orElse("").equalsIgnoreCase(SPECIAL_WINDOWS_REALM_ADDR), true); } @@ -731,11 +732,11 @@ public void windowsSpecialAccountTests() throws TskCoreException, OsAccountManag { String hostname5 = "host555"; String realmName5 = "realmName555"; - Host host5 = caseDB.getHostManager().createHost(hostname5); + Host host5 = caseDB.getHostManager().newHost(hostname5); try { String sid1 = "S-1-5-32-544"; // builtin Administrators - OsAccount osAccount1 = caseDB.getOsAccountManager().createWindowsOsAccount(sid1, null, realmName5, host5, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount osAccount1 = caseDB.getOsAccountManager().newWindowsOsAccount(sid1, null, realmName5, host5, OsAccountRealm.RealmScope.UNKNOWN); // above should raise an exception assertEquals(true, false); @@ -746,7 +747,7 @@ public void windowsSpecialAccountTests() throws TskCoreException, OsAccountManag try { String sid2 = "S-1-5-21-725345543-854245398-1060284298-512"; // domain admins group - OsAccount osAccount2 = caseDB.getOsAccountManager().createWindowsOsAccount(sid2, null, realmName5, host5, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount osAccount2 = caseDB.getOsAccountManager().newWindowsOsAccount(sid2, null, realmName5, host5, OsAccountRealm.RealmScope.UNKNOWN); // above should raise an exception assertEquals(true, false); @@ -757,7 +758,7 @@ public void windowsSpecialAccountTests() throws TskCoreException, OsAccountManag try { String sid3 = "S-1-1-0"; // Everyone - OsAccount osAccount3 = caseDB.getOsAccountManager().createWindowsOsAccount(sid3, null, realmName5, host5, OsAccountRealm.RealmScope.UNKNOWN); + OsAccount osAccount3 = caseDB.getOsAccountManager().newWindowsOsAccount(sid3, null, realmName5, host5, OsAccountRealm.RealmScope.UNKNOWN); // above should raise an exception assertEquals(true, false); @@ -783,21 +784,21 @@ public void osAccountInstanceTests() throws TskCoreException, OsAccountManager.N String realmName1 = "realm1111"; String hostname1 = "host1111"; - Host host1 = caseDB.getHostManager().createHost(hostname1); + Host host1 = caseDB.getHostManager().newHost(hostname1); - OsAccountRealm localRealm1 = caseDB.getOsAccountRealmManager().createWindowsRealm(ownerUid1, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); - OsAccount osAccount1 = caseDB.getOsAccountManager().createWindowsOsAccount(ownerUid1, null, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm localRealm1 = caseDB.getOsAccountRealmManager().newWindowsRealm(ownerUid1, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccount osAccount1 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerUid1, null, realmName1, host1, OsAccountRealm.RealmScope.LOCAL); // Test: add an instance - caseDB.getOsAccountManager().createOsAccountInstance(osAccount1, image, OsAccountInstance.OsAccountInstanceType.LAUNCHED); + caseDB.getOsAccountManager().newOsAccountInstance(osAccount1, image, OsAccountInstance.OsAccountInstanceType.LAUNCHED); // Test: add an existing instance - should be a no-op. - caseDB.getOsAccountManager().createOsAccountInstance(osAccount1, image, OsAccountInstance.OsAccountInstanceType.LAUNCHED); + caseDB.getOsAccountManager().newOsAccountInstance(osAccount1, image, OsAccountInstance.OsAccountInstanceType.LAUNCHED); // Test: create account instance on a new host String hostname2 = "host2222"; - Host host2 = caseDB.getHostManager().createHost(hostname2); - caseDB.getOsAccountManager().createOsAccountInstance(osAccount1, image, OsAccountInstance.OsAccountInstanceType.LAUNCHED); + Host host2 = caseDB.getHostManager().newHost(hostname2); + caseDB.getOsAccountManager().newOsAccountInstance(osAccount1, image, OsAccountInstance.OsAccountInstanceType.LAUNCHED); List<OsAccountAttribute> accountAttributes = new ArrayList<>(); @@ -805,19 +806,19 @@ public void osAccountInstanceTests() throws TskCoreException, OsAccountManager.N // TBD: perhaps add some files to the case and then use one of the files as the source of attributes. - OsAccountAttribute attrib1 = new OsAccountAttribute(caseDB.getAttributeType(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_PASSWORD_RESET.getTypeID()), resetTime1, osAccount1, null, image); + OsAccountAttribute attrib1 = osAccount1.new OsAccountAttribute(caseDB.getAttributeType(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_PASSWORD_RESET.getTypeID()), resetTime1, osAccount1, null, image); accountAttributes.add(attrib1); String hint = "HINT"; - OsAccountAttribute attrib2 = new OsAccountAttribute(caseDB.getAttributeType(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PASSWORD_HINT.getTypeID()), hint, osAccount1, host2, image); + OsAccountAttribute attrib2 = osAccount1.new OsAccountAttribute(caseDB.getAttributeType(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PASSWORD_HINT.getTypeID()), hint, osAccount1, host2, image); accountAttributes.add(attrib2); // add attributes to account. - caseDB.getOsAccountManager().addOsAccountAttributes(osAccount1, accountAttributes); + caseDB.getOsAccountManager().addExtendedOsAccountAttributes(osAccount1, accountAttributes); // now get the account with same sid, and get its attribuites and verify. - Optional<OsAccount> existingAccount1 = caseDB.getOsAccountManager().getOsAccountByAddr(osAccount1.getAddr().get(), caseDB.getOsAccountRealmManager().getRealmById(osAccount1.getRealmId())); - List<OsAccountAttribute> existingAccountAttribs = existingAccount1.get().getOsAccountAttributes(); + Optional<OsAccount> existingAccount1 = caseDB.getOsAccountManager().getOsAccountByAddr(osAccount1.getAddr().get(), caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount1.getRealmId())); + List<OsAccountAttribute> existingAccountAttribs = existingAccount1.get().getExtendedOsAccountAttributes(); assertEquals(existingAccountAttribs.size(), 2); @@ -842,15 +843,15 @@ public void windowsAccountRealmUpdateTests() throws TskCoreException, OsAccountM //String realmName1 = "realm4444"; String hostname1 = "host4444"; - Host host1 = caseDB.getHostManager().createHost(hostname1); + Host host1 = caseDB.getHostManager().newHost(hostname1); // create an account, a realm should be created implicitly with just the SID, and no name - OsAccount osAccount1 = caseDB.getOsAccountManager().createWindowsOsAccount(ownerUid1, null, null, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccount osAccount1 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerUid1, null, null, host1, OsAccountRealm.RealmScope.LOCAL); String realmAddr1 = "S-1-5-21-111111111-222222222-4444444444"; - OsAccountRealm realm1 = caseDB.getOsAccountRealmManager().getRealmById(osAccount1.getRealmId()); + OsAccountRealm realm1 = caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount1.getRealmId()); assertEquals(realm1.getRealmAddr().orElse("").equalsIgnoreCase(realmAddr1), true ); assertEquals(realm1.getRealmNames().isEmpty(), true); // @@ -860,10 +861,10 @@ public void windowsAccountRealmUpdateTests() throws TskCoreException, OsAccountM String ownerUid2 = "S-1-5-21-111111111-222222222-4444444444-0002"; String realmName2 = "realm4444"; - OsAccount osAccount2 = caseDB.getOsAccountManager().createWindowsOsAccount(ownerUid2, null, realmName2, host1, OsAccountRealm.RealmScope.LOCAL); + OsAccount osAccount2 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerUid2, null, realmName2, host1, OsAccountRealm.RealmScope.LOCAL); // Account 2 should have the same realm by addr, but it's realm name should now get updated. - OsAccountRealm realm2 = caseDB.getOsAccountRealmManager().getRealmById(osAccount2.getRealmId()); + OsAccountRealm realm2 = caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount2.getRealmId()); assertEquals(osAccount1.getRealmId(), osAccount2.getRealmId() ); assertEquals(realm2.getRealmAddr().orElse("").equalsIgnoreCase(realmAddr1), true ); @@ -873,13 +874,13 @@ public void windowsAccountRealmUpdateTests() throws TskCoreException, OsAccountM // Create an account with known realm name but no known addr String hostname3 = "host4444_3"; - Host host3 = caseDB.getHostManager().createHost(hostname3); + Host host3 = caseDB.getHostManager().newHost(hostname3); String realmName3 = "realm4444_3"; String loginName3 = "User4444_3"; - OsAccount osAccount3 = caseDB.getOsAccountManager().createWindowsOsAccount(null, loginName3, realmName3, host3, OsAccountRealm.RealmScope.DOMAIN); + OsAccount osAccount3 = caseDB.getOsAccountManager().newWindowsOsAccount(null, loginName3, realmName3, host3, OsAccountRealm.RealmScope.DOMAIN); - OsAccountRealm realm3 = caseDB.getOsAccountRealmManager().getRealmById(osAccount3.getRealmId()); + OsAccountRealm realm3 = caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount3.getRealmId()); assertEquals(realm3.getRealmAddr().orElse("").equalsIgnoreCase(""), true ); assertEquals(realm3.getRealmNames().size(), 1 ); // should have 1 name assertEquals(realm3.getRealmNames().get(0).equalsIgnoreCase(realmName3), true ); @@ -891,12 +892,12 @@ public void windowsAccountRealmUpdateTests() throws TskCoreException, OsAccountM String realm4Addr = "S-1-5-21-111111111-444444444-4444444444"; String hostname4 = "host4444_4"; - Host host4 = caseDB.getHostManager().createHost(hostname4); + Host host4 = caseDB.getHostManager().newHost(hostname4); - OsAccount osAccount4 = caseDB.getOsAccountManager().createWindowsOsAccount(ownerSid4, loginName4, realmName3, host4, OsAccountRealm.RealmScope.DOMAIN); + OsAccount osAccount4 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerSid4, loginName4, realmName3, host4, OsAccountRealm.RealmScope.DOMAIN); // realm4 should be the same as realm3 but the addr should be updaed now - OsAccountRealm realm4 = caseDB.getOsAccountRealmManager().getRealmById(osAccount4.getRealmId()); + OsAccountRealm realm4 = caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount4.getRealmId()); assertEquals(osAccount3.getRealmId(), osAccount4.getRealmId() ); assertEquals(realm4.getRealmAddr().orElse("").equalsIgnoreCase(realm4Addr), true ); assertEquals(realm4.getRealmNames().size(), 1 ); // should have 1 name