diff --git a/bindings/java/src/org/sleuthkit/datamodel/OsAccountInstance.java b/bindings/java/src/org/sleuthkit/datamodel/OsAccountInstance.java index fbe026b8a6a21bfe95f9633feb7230c8d418de78..935b2217ba6eb4f97cafe421da2a76fc5d3256ec 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/OsAccountInstance.java +++ b/bindings/java/src/org/sleuthkit/datamodel/OsAccountInstance.java @@ -27,7 +27,7 @@ */ public class OsAccountInstance implements Comparable<OsAccountInstance> { - private DataSource dataSource; + private DataSource dataSource = null; private final OsAccount account; private final OsAccountInstanceType instanceType; @@ -40,18 +40,28 @@ public class OsAccountInstance implements Comparable<OsAccountInstance> { /** * Construct with OsAccount and DataSource instances. * - * @param account The instance account. + * @param account The instance account. * @param dataSource The instance data source * @param instanceType The instance type. */ OsAccountInstance(OsAccount account, DataSource dataSource, OsAccountInstanceType instanceType) { - this.account = account; + this(account, dataSource.getId(), instanceType); this.dataSource = dataSource; - this.instanceType = instanceType; - - dataSourceId = dataSource.getId(); } + /** + * Construct with OsAccount and DataSource instances. + * + * @param account The instance account. + * @param dataSourceObjId The instance data source object id. + * @param instanceType The instance type. + */ + OsAccountInstance(OsAccount account, long dataSourceObjId, OsAccountInstanceType instanceType) { + this.account = account; + this.dataSourceId = dataSourceObjId; + this.instanceType = instanceType; + } + /** * Construct the OsAccountInstance doing a lazy construction on the data * source object. diff --git a/bindings/java/src/org/sleuthkit/datamodel/OsAccountManager.java b/bindings/java/src/org/sleuthkit/datamodel/OsAccountManager.java index 897e7213ab507734a664075460ba29a9f62b52df..c109e682e57a1674ef31880bf4438f0cbfa3c3e4 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/OsAccountManager.java +++ b/bindings/java/src/org/sleuthkit/datamodel/OsAccountManager.java @@ -527,7 +527,6 @@ public void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, */ void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccountInstance.OsAccountInstanceType instanceType, CaseDbConnection connection) throws TskCoreException { - if (osAccount == null) { throw new IllegalArgumentException("Cannot create account instance with null account."); } @@ -535,8 +534,29 @@ void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccou throw new IllegalArgumentException("Cannot create account instance with null data source."); } + createOsAccountInstance(osAccount, dataSource.getId(), instanceType, connection); + } + + /** + * Adds a row to the tsk_os_account_instances table. Does nothing if the + * instance already exists in the table. + * + * @param osAccount Account for which an instance needs to be added. + * @param dataSourceObjId Data source where the instance is found. + * @param instanceType Instance type. + * @param connection The current database connection. + * + * @throws TskCoreException + */ + void createOsAccountInstance(OsAccount osAccount, long dataSourceObjId, OsAccountInstance.OsAccountInstanceType instanceType, CaseDbConnection connection) throws TskCoreException { + + + if (osAccount == null) { + throw new IllegalArgumentException("Cannot create account instance with null account."); + } + // check cache first - OsAccountInstance accountInstance = new OsAccountInstance(osAccount, dataSource, instanceType); + OsAccountInstance accountInstance = new OsAccountInstance(osAccount, dataSourceObjId, instanceType); if (osAccountInstanceCache.contains(accountInstance)) { return; } @@ -551,7 +571,7 @@ void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccou preparedStatement.clearParameters(); preparedStatement.setLong(1, osAccount.getId()); - preparedStatement.setLong(2, dataSource.getId()); + preparedStatement.setLong(2, dataSourceObjId); preparedStatement.setInt(3, instanceType.getId()); connection.executeUpdate(preparedStatement); @@ -560,7 +580,7 @@ void createOsAccountInstance(OsAccount osAccount, DataSource dataSource, OsAccou osAccountInstanceCache.add(accountInstance); } catch (SQLException ex) { - throw new TskCoreException(String.format("Error adding os account instance for account = %s, data source object id = %d", osAccount.getUniqueIdWithinRealm().orElse(osAccount.getLoginName().orElse("UNKNOWN")), dataSource.getId()), ex); + throw new TskCoreException(String.format("Error adding os account instance for account = %s, data source object id = %d", osAccount.getUniqueIdWithinRealm().orElse(osAccount.getLoginName().orElse("UNKNOWN")), dataSourceObjId), ex); } finally { db.releaseSingleUserCaseWriteLock(); } diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java index 60a0415b63dbdfc388d9d05cd0dddafcdb863df6..c39f978a9c503ab9a8b5d31965b17ea18831769a 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java @@ -7022,7 +7022,7 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId, } if(osAccount != null) { - osAccountManager.createOsAccountInstance(osAccount, getDataSource(dataSourceObjId), OsAccountInstance.OsAccountInstanceType.LAUNCHED, connection); + osAccountManager.createOsAccountInstance(osAccount, dataSourceObjId, OsAccountInstance.OsAccountInstanceType.LAUNCHED, connection); } return new org.sleuthkit.datamodel.File(this, objectId, dataSourceObjId, fsObjId, @@ -7034,9 +7034,7 @@ public FsContent addFileSystemFile(long dataSourceObjId, long fsObjId, } catch (SQLException ex) { throw new TskCoreException(String.format("Failed to INSERT file system file %s (%s) with parent id %d in tsk_files table", fileName, parentPath, parent.getId()), ex); - } catch(TskDataException ex) { - throw new TskCoreException(String.format("Failed to get DataSource (%d) object while creating OsAccount Instance", dataSourceObjId), ex); - }finally { + } finally { closeStatement(queryStatement); } }