Skip to content
Snippets Groups Projects
Unverified Commit 5313b36c authored by Richard Cordovano's avatar Richard Cordovano Committed by GitHub
Browse files

Merge pull request #2265 from jayaramcs/develop

OsAccount Add attribute event bug fix
parents d5d60558 fbec6ff6
No related branches found
No related tags found
No related merge requests found
......@@ -64,6 +64,7 @@ public final class OsAccount extends AbstractContent {
private boolean isDirty = false; // indicates that some member value has changed since construction and it should be updated in the database.
/**
* Encapsulates status of an account - whether is it active or disabled or
* deleted.
......@@ -371,18 +372,13 @@ void resetDirty() {
}
/**
* Adds account attributes to the account. Attributes can be at a host-level
* or domain-level (for domain-scoped accounts).
*
* @param osAccountAttributes List of attributes to add.
*
* @throws TskCoreException
*
* @throws org.sleuthkit.datamodel.TskCoreException
* This function is used by OsAccountManger to update the list of
* OsAccount attributes.
*
* @param osAccountAttribute The osAccount Attribute that is to be added.
*/
public void addAttributes(List<OsAccountAttribute> osAccountAttributes) throws TskCoreException {
sleuthkitCase.getOsAccountManager().addOsAccountAttributes(this, osAccountAttributes);
osAccountAttributes.addAll(osAccountAttributes);
void setAttributesInternal(List<OsAccountAttribute> osAccountAttributes) {
this.osAccountAttributes = osAccountAttributes;
}
/**
......@@ -485,7 +481,7 @@ public OsAccountDbStatus getOsAccountDbStatus() {
*
* @throws TskCoreException
*/
public List<OsAccountAttribute> getOsAccountAttributes() throws TskCoreException {
public synchronized List<OsAccountAttribute> getOsAccountAttributes() throws TskCoreException {
if (osAccountAttributes == null) {
osAccountAttributes = sleuthkitCase.getOsAccountManager().getOsAccountAttributes(this);
}
......
......@@ -964,74 +964,77 @@ public Optional<OsAccount> getWindowsOsAccount(String sid, String loginName, Str
*
* @throws TskCoreException,
*/
void addOsAccountAttributes(OsAccount account, List<OsAccountAttribute> accountAttributes) throws TskCoreException {
public void addOsAccountAttributes(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();
db.acquireSingleUserCaseWriteLock();
try (CaseDbConnection connection = db.getConnection()) {
for (OsAccountAttribute accountAttribute : accountAttributes) {
try (CaseDbConnection connection = db.getConnection()) {
for (OsAccountAttribute accountAttribute : accountAttributes) {
String attributeInsertSQL = "INSERT INTO tsk_os_account_attributes(os_account_obj_id, host_id, source_obj_id, attribute_type_id, value_type, value_byte, value_text, value_int32, value_int64, value_double)"
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; // NON-NLS
String attributeInsertSQL = "INSERT INTO tsk_os_account_attributes(os_account_obj_id, host_id, source_obj_id, attribute_type_id, value_type, value_byte, value_text, value_int32, value_int64, value_double)"
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; // NON-NLS
PreparedStatement preparedStatement = connection.getPreparedStatement(attributeInsertSQL, Statement.RETURN_GENERATED_KEYS);
preparedStatement.clearParameters();
PreparedStatement preparedStatement = connection.getPreparedStatement(attributeInsertSQL, Statement.RETURN_GENERATED_KEYS);
preparedStatement.clearParameters();
preparedStatement.setLong(1, account.getId());
if (accountAttribute.getHostId().isPresent()) {
preparedStatement.setLong(2, accountAttribute.getHostId().get());
} else {
preparedStatement.setNull(2, java.sql.Types.NULL);
}
if (accountAttribute.getSourceObjectId().isPresent()) {
preparedStatement.setLong(3, accountAttribute.getSourceObjectId().get());
} else {
preparedStatement.setNull(3, java.sql.Types.NULL);
}
preparedStatement.setLong(1, account.getId());
if (accountAttribute.getHostId().isPresent()) {
preparedStatement.setLong(2, accountAttribute.getHostId().get());
} else {
preparedStatement.setNull(2, java.sql.Types.NULL);
}
if (accountAttribute.getSourceObjectId().isPresent()) {
preparedStatement.setLong(3, accountAttribute.getSourceObjectId().get());
} else {
preparedStatement.setNull(3, java.sql.Types.NULL);
}
preparedStatement.setLong(4, accountAttribute.getAttributeType().getTypeID());
preparedStatement.setLong(5, accountAttribute.getAttributeType().getValueType().getType());
preparedStatement.setLong(4, accountAttribute.getAttributeType().getTypeID());
preparedStatement.setLong(5, accountAttribute.getAttributeType().getValueType().getType());
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.BYTE) {
preparedStatement.setBytes(6, accountAttribute.getValueBytes());
} else {
preparedStatement.setBytes(6, null);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.BYTE) {
preparedStatement.setBytes(6, accountAttribute.getValueBytes());
} else {
preparedStatement.setBytes(6, null);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING
|| accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.JSON) {
preparedStatement.setString(7, accountAttribute.getValueString());
} else {
preparedStatement.setString(7, null);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.INTEGER) {
preparedStatement.setInt(8, accountAttribute.getValueInt());
} else {
preparedStatement.setNull(8, java.sql.Types.NULL);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING
|| accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.JSON) {
preparedStatement.setString(7, accountAttribute.getValueString());
} else {
preparedStatement.setString(7, null);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.INTEGER) {
preparedStatement.setInt(8, accountAttribute.getValueInt());
} else {
preparedStatement.setNull(8, java.sql.Types.NULL);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME
|| accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.LONG) {
preparedStatement.setLong(9, accountAttribute.getValueLong());
} else {
preparedStatement.setNull(9, java.sql.Types.NULL);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME
|| accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.LONG) {
preparedStatement.setLong(9, accountAttribute.getValueLong());
} else {
preparedStatement.setNull(9, java.sql.Types.NULL);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DOUBLE) {
preparedStatement.setDouble(10, accountAttribute.getValueDouble());
} else {
preparedStatement.setNull(10, java.sql.Types.NULL);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DOUBLE) {
preparedStatement.setDouble(10, accountAttribute.getValueDouble());
} else {
preparedStatement.setNull(10, java.sql.Types.NULL);
connection.executeUpdate(preparedStatement);
}
connection.executeUpdate(preparedStatement);
} catch (SQLException ex) {
throw new TskCoreException(String.format("Error adding OS Account attribute for account id = %d", account.getId()), ex);
} finally {
db.releaseSingleUserCaseWriteLock();
}
} catch (SQLException ex) {
throw new TskCoreException(String.format("Error adding OS Account attribute for account id = %d", account.getId()), ex);
} finally {
db.releaseSingleUserCaseWriteLock();
List<OsAccountAttribute> currentAttribsList = getOsAccountAttributes(account);
currentAttribsList.addAll(accountAttributes);
account.setAttributesInternal(currentAttribsList);
}
fireChangeEvent(account);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment