Merge pull request #5948 from kellykelly3/1478-CVT-query-for-specific-account-type

1478 cvt query for specific account type
This commit is contained in:
Richard Cordovano 2020-06-09 12:43:31 -04:00 committed by GitHub
commit 7aa735c91b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 160 additions and 50 deletions

View File

@ -27,6 +27,7 @@ import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.Account;
/** /**
* This class represents an association between a Persona and an Account. * This class represents an association between a Persona and an Account.
@ -130,7 +131,13 @@ public class PersonaAccount {
* account. * account.
*/ */
static PersonaAccount addPersonaAccount(Persona persona, CentralRepoAccount account, String justification, Persona.Confidence confidence) throws CentralRepoException { static PersonaAccount addPersonaAccount(Persona persona, CentralRepoAccount account, String justification, Persona.Confidence confidence) throws CentralRepoException {
CentralRepoExaminer currentExaminer = CentralRepository.getInstance().getOrInsertExaminer(System.getProperty("user.name")); CentralRepository cr = CentralRepository.getInstance();
if(cr == null) {
throw new CentralRepoException("Failed to add Persona, Central Repository is not enable");
}
CentralRepoExaminer currentExaminer = cr.getOrInsertExaminer(System.getProperty("user.name"));
Instant instant = Instant.now(); Instant instant = Instant.now();
Long timeStampMillis = instant.toEpochMilli(); Long timeStampMillis = instant.toEpochMilli();
@ -235,46 +242,62 @@ public class PersonaAccount {
* Gets all the Accounts for the specified Persona. * Gets all the Accounts for the specified Persona.
* *
* @param personaId Id of persona for which to get the accounts for. * @param personaId Id of persona for which to get the accounts for.
*
* @return Collection of PersonaAccounts, may be empty. * @return Collection of PersonaAccounts, may be empty.
* *
* @throws CentralRepoException If there is an error in getting the * @throws CentralRepoException If there is an error in getting the
* persona_account. * persona_account.
*/ */
static Collection<PersonaAccount> getPersonaAccountsForPersona(long personaId) throws CentralRepoException { static Collection<PersonaAccount> getPersonaAccountsForPersona(long personaId) throws CentralRepoException {
CentralRepository cr = CentralRepository.getInstance();
if (cr != null) {
String queryClause = PERSONA_ACCOUNTS_QUERY_CALUSE String queryClause = PERSONA_ACCOUNTS_QUERY_CALUSE
+ " WHERE persona_accounts.persona_id = " + personaId; + " WHERE persona_accounts.persona_id = " + personaId;
PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback();
CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback); cr.executeSelectSQL(queryClause, queryCallback);
return queryCallback.getPersonaAccountsList(); return queryCallback.getPersonaAccountsList();
} }
return new ArrayList<>();
}
/** /**
* Gets all the Persona for the specified Account. * Gets all the Persona for the specified Account.
* *
* @param accountId Id of account for which to get the Personas for. * @param accountId Id of account for which to get the Personas for.
*
* @return Collection of PersonaAccounts. may be empty. * @return Collection of PersonaAccounts. may be empty.
* *
* @throws CentralRepoException If there is an error in getting the * @throws CentralRepoException If there is an error in getting the
* persona_account. * persona_account.
*/ */
public static Collection<PersonaAccount> getPersonaAccountsForAccount(long accountId) throws CentralRepoException { public static Collection<PersonaAccount> getPersonaAccountsForAccount(long accountId) throws CentralRepoException {
CentralRepository cr = CentralRepository.getInstance();
if (cr != null) {
String queryClause = PERSONA_ACCOUNTS_QUERY_CALUSE String queryClause = PERSONA_ACCOUNTS_QUERY_CALUSE
+ " WHERE persona_accounts.account_id = " + accountId; + " WHERE persona_accounts.account_id = " + accountId;
PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback();
CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback); cr.executeSelectSQL(queryClause, queryCallback);
return queryCallback.getPersonaAccountsList(); return queryCallback.getPersonaAccountsList();
} }
return new ArrayList<>();
}
/** /**
* Gets all the Persona associated with all the accounts matching the given * Gets all the Persona associated with all the accounts matching the given
* account identifier substring. * account identifier substring.
* *
* @param accountIdentifierSubstring Account identifier substring to search * @param accountIdentifierSubstring Account identifier substring to search
* for. * for.
*
* @return Collection of PersonaAccounts. may be empty. * @return Collection of PersonaAccounts. may be empty.
* *
* @throws CentralRepoException If there is an error in getting the * @throws CentralRepoException If there is an error in getting the
@ -284,12 +307,41 @@ public class PersonaAccount {
String queryClause = PERSONA_ACCOUNTS_QUERY_CALUSE String queryClause = PERSONA_ACCOUNTS_QUERY_CALUSE
+ " WHERE LOWER(accounts.account_unique_identifier) LIKE LOWER('%" + accountIdentifierSubstring + "%')"; + " WHERE LOWER(accounts.account_unique_identifier) LIKE LOWER('%" + accountIdentifierSubstring + "%')";
CentralRepository cr = CentralRepository.getInstance();
if (cr != null) {
PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback();
CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback); cr.executeSelectSQL(queryClause, queryCallback);
return queryCallback.getPersonaAccountsList(); return queryCallback.getPersonaAccountsList();
} }
return new ArrayList<>();
}
/**
* Gets all the Persona associated with the given account.
*
* @param account Account to search for.
*
* @return Collection of PersonaAccounts, maybe empty if none were found or
* CR is not enabled.
*
* @throws CentralRepoException
*/
public static Collection<PersonaAccount> getPersonaAccountsForAccount(Account account) throws CentralRepoException {
String queryClause = PERSONA_ACCOUNTS_QUERY_CALUSE
+ " WHERE LOWER(accounts.account_unique_identifier) LIKE LOWER('%" + account.getTypeSpecificID() + "%') AND type_name = '" + account.getAccountType().getTypeName() + "' ";
CentralRepository cr = CentralRepository.getInstance();
if (cr != null) {
PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback();
cr.executeSelectSQL(queryClause, queryCallback);
return queryCallback.getPersonaAccountsList();
}
return new ArrayList<>();
}
/** /**
* Removes the PersonaAccount row by the given id * Removes the PersonaAccount row by the given id
* *
@ -299,8 +351,14 @@ public class PersonaAccount {
* account. * account.
*/ */
static void removePersonaAccount(long id) throws CentralRepoException { static void removePersonaAccount(long id) throws CentralRepoException {
CentralRepository cr = CentralRepository.getInstance();
if(cr == null) {
throw new CentralRepoException("Failed to remove persona account, Central Repo is not enabled");
}
String deleteClause = " DELETE FROM persona_accounts WHERE id = " + id; String deleteClause = " DELETE FROM persona_accounts WHERE id = " + id;
CentralRepository.getInstance().executeDeleteSQL(deleteClause); cr.executeDeleteSQL(deleteClause);
} }
/** /**
@ -343,6 +401,9 @@ public class PersonaAccount {
* accounts. * accounts.
*/ */
static Collection<CentralRepoAccount> getAccountsForPersona(long personaId) throws CentralRepoException { static Collection<CentralRepoAccount> getAccountsForPersona(long personaId) throws CentralRepoException {
CentralRepository cr = CentralRepository.getInstance();
if (cr != null) {
String queryClause = "SELECT account_id, " String queryClause = "SELECT account_id, "
+ " accounts.account_type_id as account_type_id, accounts.account_unique_identifier as account_unique_identifier," + " accounts.account_type_id as account_type_id, accounts.account_unique_identifier as account_unique_identifier,"
+ " account_types.type_name as type_name " + " account_types.type_name as type_name "
@ -352,8 +413,11 @@ public class PersonaAccount {
+ " WHERE persona_accounts.persona_id = " + personaId; + " WHERE persona_accounts.persona_id = " + personaId;
AccountsForPersonaQueryCallback queryCallback = new AccountsForPersonaQueryCallback(); AccountsForPersonaQueryCallback queryCallback = new AccountsForPersonaQueryCallback();
CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback); cr.executeSelectSQL(queryClause, queryCallback);
return queryCallback.getAccountsList(); return queryCallback.getAccountsList();
} }
return new ArrayList<>();
}
} }

View File

@ -1,18 +1,38 @@
AddAccountDialog.title.text=Add Account AddAccountDialog.title.text=Add Account
AddAccountDialog_dup_msg=This account is already added to the persona
AddAccountDialog_dup_Title=Account add failure
AddAccountDialog_empty_msg=The identifier field cannot be empty
AddAccountDialog_empty_Title=Empty identifier
AddAccountDialog_get_types_exception_msg=Failed to access central repository AddAccountDialog_get_types_exception_msg=Failed to access central repository
AddAccountDialog_get_types_exception_Title=Central Repository failure AddAccountDialog_get_types_exception_Title=Central Repository failure
AddAccountDialog_validate_id_failure=Account ID must not be empty AddAccountDialog_search_empty_msg=Account not found for given identifier and type
AddAccountDialog_validate_id_failure_title=Account ID issue AddAccountDialog_search_empty_Title=Account not found
AddAccountDialog_search_failure_msg=Central Repository account search failed
AddAccountDialog_search_failure_Title=Account add failure
AddAliasDialog.title.text=Add Alias
AddAliasDialog_dup_msg=This alias has already been added to this persona
AddAliasDialog_dup_Title=Alias add failure
AddMetadataDialog.title.text=Add Metadata
AddMetadataDialog_dup_msg=A metadata entry with this name has already been added to this persona
AddMetadataDialog_dup_Title=Metadata add failure
CTL_OpenPersonaManager=Persona Manager CTL_OpenPersonaManager=Persona Manager
CTL_PersonaManagerTopComponentAction=Persona Manager CTL_PersonaManagerTopComponentAction=Persona Manager
CTL_PersonaDetailsTopComponent=Persona Details CTL_PersonaDetailsTopComponent=Persona Details
OpenPersonasAction.displayName=Persona Manager OpenPersonasAction.displayName=Persona Manager
PersonaDetailsDialogCreateTitle=Create Persona
PersonaDetailsDialogEditTitle=Edit Persona
PersonaDetailsPanel_CentralRepoErr_msg=Failure to write to Central Repository
PersonaDetailsPanel_CentralRepoErr_Title=Central Repository failure
PersonaDetailsPanel_EmptyName_msg=Persona name cannot be empty
PersonaDetailsPanel_EmptyName_Title=Empty persona name
PersonaDetailsPanel_load_exception_msg=Failed to load persona PersonaDetailsPanel_load_exception_msg=Failed to load persona
PersonaDetailsPanel_load_exception_Title=Initialization failure PersonaDetailsPanel_load_exception_Title=Initialization failure
PersonaDetailsPanel_NameCreate=Create Persona PersonaDetailsPanel_NameCreate=Create Persona
PersonaDetailsPanel_NameEdit=Edit Persona PersonaDetailsPanel_NameEdit=Edit Persona
PersonaDetailsPanel_NameView=View Persona PersonaDetailsPanel_NameView=View Persona
PersonaManagerTopComponent.createBtn.text=Create New PersonaDetailsPanel_NotEnoughAccounts_msg=Two or more accounts are necessary to create a persona
PersonaDetailsPanel_NotEnoughAccounts_Title=Not enough accounts
PersonaManagerTopComponent.createBtn.text=New Persona
PersonaManagerTopComponent.searchBtn.text=Search PersonaManagerTopComponent.searchBtn.text=Search
PersonaManagerTopComponent.resultsTable.columnModel.title1=Name PersonaManagerTopComponent.resultsTable.columnModel.title1=Name
PersonaManagerTopComponent.resultsTable.columnModel.title0=ID PersonaManagerTopComponent.resultsTable.columnModel.title0=ID
@ -20,6 +40,17 @@ PersonaManagerTopComponent.resultsTable.toolTipText=
PersonaManagerTopComponent.searchAccountRadio.text=Account PersonaManagerTopComponent.searchAccountRadio.text=Account
PersonaManagerTopComponent.searchNameRadio.text=Name PersonaManagerTopComponent.searchNameRadio.text=Name
PersonaManagerTopComponent.searchField.text= PersonaManagerTopComponent.searchField.text=
AddAccountDialog.cancelBtn.text=Cancel
AddAccountDialog.okBtn.text=OK
PersonaManagerTopComponent.editBtn.text=Edit Persona
PersonaDetailsDialog.cancelBtn.text=Cancel
PersonaDetailsDialog.okBtn.text=OK
PersonaDetailsPanel.deleteCaseBtn.text=Delete
PersonaDetailsPanel.addCaseBtn.text=Add
PersonaDetailsPanel.casesLbl.text=Cases found in:
PersonaDetailsPanel.deleteAliasBtn.text=Delete
PersonaDetailsPanel.addAliasBtn.text=Add
PersonaDetailsPanel.aliasesLabel.text=Aliases:
PersonaDetailsPanel.deleteMetadataBtn.text=Delete PersonaDetailsPanel.deleteMetadataBtn.text=Delete
PersonaDetailsPanel.addMetadataBtn.text=Add PersonaDetailsPanel.addMetadataBtn.text=Add
PersonaDetailsPanel.metadataLabel.text=Metadata: PersonaDetailsPanel.metadataLabel.text=Metadata:
@ -27,18 +58,32 @@ PersonaDetailsPanel.deleteAccountBtn.text=Delete
PersonaDetailsPanel.addAccountBtn.text=Add PersonaDetailsPanel.addAccountBtn.text=Add
PersonaDetailsPanel.accountsLbl.text=Accounts: PersonaDetailsPanel.accountsLbl.text=Accounts:
PersonaDetailsPanel.nameField.text= PersonaDetailsPanel.nameField.text=
PersonaDetailsPanel.saveBtn.toolTipText=
PersonaDetailsPanel.saveBtn.text=Save Changes
PersonaDetailsPanel.nameLbl.text=Name: PersonaDetailsPanel.nameLbl.text=Name:
PersonaDetailsPanel.deleteCaseBtn.text=Delete AddAliasDialog.accountsLbl.text=Account:
PersonaDetailsPanel.addCaseBtn.text=Add AddAliasDialog.okBtn.text=OK
PersonaDetailsPanel.casesLbl.text=Cases found in: AddAliasDialog.cancelBtn.text=Cancel
PersonaDetailsPanel.deleteAliasBtn.text=Delete AddMetadataDialog.cancelBtn.text=Cancel
PersonaDetailsPanel.addAliasBtn.text=Add AddMetadataDialog.okBtn.text=OK
PersonaDetailsPanel.aliasesLabel.text=Aliases: AddMetadataDialog.nameLbl.text=Name:
AddAccountDialog.cancelBtn.text=Cancel AddMetadataDialog.nameTextField.text=
AddAccountDialog.okBtn.text=OK AddMetadataDialog.valueLbl.text=Value:
PersonaManagerTopComponent.editBtn.text=Edit AddMetadataDialog.valueTextField.text=
AddMetadataDialog.justificationLbl.text=Justification:
AddMetadataDialog.justificationTextField.text=
AddMetadataDialog.confidenceLbl.text=Confidence:
AddAliasDialog.justificationLbl.text=Justification:
AddAliasDialog.okBtn.text_1=OK
AddAliasDialog.cancelBtn.text_1=Cancel
AddAliasDialog.confidenceLbl.text=Confidence:
AddAliasDialog.justificationTextField.text=
AddAliasDialog.aliasLbl.text=Alias:
AddAliasDialog.aliasTextField.text=
AddAccountDialog.justificationTextField.text=
AddAccountDialog.justificationLbl.text=Justification:
AddAccountDialog.confidenceLbl.text=Confidence:
AddAccountDialog.typeLbl.text=Type:
AddAccountDialog.identiferLbl.text=Identifier:
AddAccountDialog.identifierTextField.text=
PMTopComponent_Name=Persona Manager PMTopComponent_Name=Persona Manager
PMTopComponent_search_exception_msg=Failed to search personas PMTopComponent_search_exception_msg=Failed to search personas
PMTopComponent_search_exception_Title=Search failure PMTopComponent_search_exception_Title=Search failure

View File

@ -123,7 +123,7 @@ final class AccountDeviceInstanceNode extends AbstractNode {
public String getShortDescription() { public String getShortDescription() {
List<PersonaAccount> personaList; List<PersonaAccount> personaList;
try { try {
personaList = CVTPersonaCache.getPersonaAccounts(getName()); personaList = CVTPersonaCache.getPersonaAccounts(account);
} catch (ExecutionException ex) { } catch (ExecutionException ex) {
logger.log(Level.WARNING, "Failed to retrieve Persona details for node.", ex); logger.log(Level.WARNING, "Failed to retrieve Persona details for node.", ex);
return getDisplayName(); return getDisplayName();

View File

@ -31,6 +31,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoException;
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository;
import org.sleuthkit.autopsy.centralrepository.datamodel.PersonaAccount; import org.sleuthkit.autopsy.centralrepository.datamodel.PersonaAccount;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.Account;
/** /**
* A singleton cache of the PersonaAccount information. The list of * A singleton cache of the PersonaAccount information. The list of
@ -40,7 +41,7 @@ import org.sleuthkit.autopsy.coreutils.Logger;
final class CVTPersonaCache { final class CVTPersonaCache {
private static final Logger logger = Logger.getLogger(CVTPersonaCache.class.getName()); private static final Logger logger = Logger.getLogger(CVTPersonaCache.class.getName());
private final LoadingCache<String, List<PersonaAccount>> accountMap; private final LoadingCache<Account, List<PersonaAccount>> accountMap;
private static CVTPersonaCache instance; private static CVTPersonaCache instance;
@ -49,13 +50,13 @@ final class CVTPersonaCache {
*/ */
private CVTPersonaCache() { private CVTPersonaCache() {
accountMap = CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.MINUTES).build( accountMap = CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.MINUTES).build(
new CacheLoader<String, List<PersonaAccount>>() { new CacheLoader<Account, List<PersonaAccount>>() {
@Override @Override
public List<PersonaAccount> load(String key) { public List<PersonaAccount> load(Account key) {
List<PersonaAccount> accountList = new ArrayList<>(); List<PersonaAccount> accountList = new ArrayList<>();
try { try {
if (CentralRepository.isEnabled()) { if (CentralRepository.isEnabled()) {
Collection<PersonaAccount> accounts = PersonaAccount.getPersonaAccountsForIdentifierLike(key); Collection<PersonaAccount> accounts = PersonaAccount.getPersonaAccountsForAccount(key);
accountList.addAll(accounts); accountList.addAll(accounts);
} }
} catch (CentralRepoException ex) { } catch (CentralRepoException ex) {
@ -89,7 +90,7 @@ final class CVTPersonaCache {
* *
* @throws ExecutionException * @throws ExecutionException
*/ */
static synchronized List<PersonaAccount> getPersonaAccounts(String typeSpecificID) throws ExecutionException { static synchronized List<PersonaAccount> getPersonaAccounts(Account account) throws ExecutionException {
return getInstance().accountMap.get(typeSpecificID); return getInstance().accountMap.get(account);
} }
} }