diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java index 11002c2d978356091580c73b3e1a21c94ccb098f..cba4f4299b2b9108148a8da479f6950860f4ce76 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java @@ -11034,7 +11034,8 @@ void setAcquisitionToolDetails(DataSource datasource, String name, String versio * * @throws TskCoreException */ - void setAcquisitionDetails(long dataSourceId, String details, CaseDbTransaction trans) throws TskCoreException { + @Beta + public void setAcquisitionDetails(long dataSourceId, String details, CaseDbTransaction trans) throws TskCoreException { try { CaseDbConnection connection = trans.getConnection(); PreparedStatement statement = connection.getPreparedStatement(PREPARED_STATEMENT.UPDATE_ACQUISITION_DETAILS); diff --git a/bindings/java/test/org/sleuthkit/datamodel/OsAccountTest.java b/bindings/java/test/org/sleuthkit/datamodel/OsAccountTest.java index 8f3e373d06af979f7000d9aee5d566fe724f0cc2..63a02e12ec233a52f99d7a21280446a1f5f50b09 100644 --- a/bindings/java/test/org/sleuthkit/datamodel/OsAccountTest.java +++ b/bindings/java/test/org/sleuthkit/datamodel/OsAccountTest.java @@ -396,6 +396,87 @@ public void mergeRealmsTests() throws TskCoreException, OsAccountManager.NotUser } } + @Test + public void updateRealmAndMergeTests() throws TskCoreException, OsAccountManager.NotUserSIDException { + + /** + * Test the scenario where an update of an account triggers an update of + * a realm and subsequent merge of realms and accounts. + */ + + Host host = caseDB.getHostManager().newHost("updateRealmAndMergeTestHost"); + + + + // Step 1: create a local account with SID and user name + String ownerUid1 = "S-1-5-21-1182664808-117526782-2525957323-13395"; + String realmName1 = null; + String loginName1 = "sandip"; + + OsAccount osAccount1 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerUid1, loginName1, realmName1, host, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm1 = caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount1.getRealmId()); + + assertEquals(realm1.getRealmAddr().isPresent(), true); // verify the realm has a SID + assertEquals(realm1.getRealmNames().isEmpty(), true); // verify the realm has no name + + + // Step2: create a local account with domain name and username + String ownerUid2 = null; + String realmName2 = "CORP"; + String loginName2 = "sandip"; + + Optional<OsAccount> oOsAccount2 = caseDB.getOsAccountManager().getWindowsOsAccount(ownerUid2, loginName2, realmName2, host); + + // this account should not exists + assertEquals(oOsAccount2.isPresent(), false); + + // create a new account - a new realm as there is nothing to tie it to realm1 + OsAccount osAccount2 = caseDB.getOsAccountManager().newWindowsOsAccount(ownerUid2, loginName2, realmName2, host, OsAccountRealm.RealmScope.LOCAL); + OsAccountRealm realm2 = caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount2.getRealmId()); + + assertTrue(osAccount1.getId() != osAccount2.getId()); + assertTrue(realm1.getRealmId() != realm2.getRealmId()); + + + + // Step 3: now create/update the account with sid/domain/username + // this should return the existing account1, which needs to be updated. + String ownerUid3 = "S-1-5-21-1182664808-117526782-2525957323-13395"; + String realmAddr3 = "S-1-5-21-1182664808-117526782-2525957323"; + String loginName3 = "sandip"; + String realmName3 = "CORP"; + + Optional<OsAccount> oOsAccount3 = caseDB.getOsAccountManager().getWindowsOsAccount(ownerUid3, loginName3, realmName3, host); + + assertTrue(oOsAccount3.isPresent()); + + + // update the account so that its domain gets updated. + OsAccountManager.OsAccountUpdateResult updateResult = caseDB.getOsAccountManager().updateCoreWindowsOsAccountAttributes(oOsAccount3.get(), ownerUid3, loginName3, realmName3, host); + Optional<OsAccount> updatedAccount3 = updateResult.getUpdatedAccount(); + assertTrue(updatedAccount3.isPresent()); + + // this should cause the realm1 to be updated - and then realm2 to be merged into realm1 + OsAccountRealm realm3 = caseDB.getOsAccountRealmManager().getRealmByRealmId(updatedAccount3.get().getRealmId()); + + assertTrue(realm3.getRealmId() == realm1.getRealmId()); + + assertTrue(realm3.getRealmAddr().isPresent()); // verify the realm gets an addr + assertTrue(realm3.getRealmAddr().get().equalsIgnoreCase(realmAddr3)); + + assertTrue(realm3.getRealmNames().get(0).equalsIgnoreCase(realmName3)); // verify realm name. + + + // And now verify that the realm2 has been merged into realm1. + OsAccountRealm realm22 = caseDB.getOsAccountRealmManager().getRealmByRealmId(osAccount2.getRealmId()); + assertTrue(realm22.getDbStatus() == OsAccountRealm.RealmDbStatus.MERGED); + + //and account2 has been merged into account1 + OsAccount osAccount22 = caseDB.getOsAccountManager().getOsAccountByObjectId(osAccount2.getId()); + assertTrue(osAccount22.getOsAccountDbStatus() == OsAccount.OsAccountDbStatus.MERGED); + + } + @Test public void hostAddressTests() throws TskCoreException {