From 66489b325f04399f4c119eeffcbe346df7764ba1 Mon Sep 17 00:00:00 2001 From: Kelly Kelly Date: Mon, 8 Jun 2020 13:18:28 -0400 Subject: [PATCH] Added getPersonaAccountsForAccount --- .../datamodel/PersonaAccount.java | 132 ++++++++++++------ .../persona/Bundle.properties-MERGED | 73 ++++++++-- .../AccountDeviceInstanceNode.java | 2 +- .../communications/CVTPersonaCache.java | 13 +- 4 files changed, 159 insertions(+), 61 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/PersonaAccount.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/PersonaAccount.java index 213a5f95c5..7e88739b66 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/PersonaAccount.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/PersonaAccount.java @@ -24,13 +24,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Objects; +import org.sleuthkit.datamodel.Account; /** * This class represents an association between a Persona and an Account. - * + * * A Persona has at least one, possibly more, accounts associated with it. - * - * + * + * */ public class PersonaAccount { @@ -108,7 +109,6 @@ public class PersonaAccount { return Objects.equals(this.examiner, other.getExaminer()); } - /** * Callback to process a Persona Accounts query. */ @@ -166,7 +166,7 @@ public class PersonaAccount { } }; - // Query clause to select from persona_accounts table to create PersonaAccount(s) + // Query clause to select from persona_accounts table to create PersonaAccount(s) private static final String PERSONA_ACCOUNTS_QUERY_CALUSE = "SELECT justification, confidence_id, date_added, persona_accounts.examiner_id as pa_examiner_id, pa_examiner.login_name as pa_examiner_login_name, pa_examiner.display_name as pa_examiner_display_name," + " personas.id as persona_id, personas.uuid, personas.name, personas.comment, personas.created_date, personas.modified_date, personas.status_id, " + " personas.examiner_id as persona_examiner_id, persona_examiner.login_name as persona_examiner_login_name, persona_examiner.display_name as persona_examiner_display_name, " @@ -178,67 +178,111 @@ public class PersonaAccount { + " JOIN account_types as account_types on accounts.account_type_id = account_types.id " + " JOIN examiners as pa_examiner ON pa_examiner.id = persona_accounts.examiner_id " + " JOIN examiners as persona_examiner ON persona_examiner.id = personas.examiner_id "; - - - /** + + /** * Gets all the Accounts for the specified Persona. * * @param personaId Id of persona for which to get the accounts for. + * * @return Collection of PersonaAccounts, may be empty. * * @throws CentralRepoException If there is an error in getting the - * persona_account. + * persona_account. */ static Collection getPersonaAccountsForPersona(long personaId) throws CentralRepoException { - String queryClause = PERSONA_ACCOUNTS_QUERY_CALUSE - + " WHERE persona_accounts.persona_id = " + personaId; + CentralRepository cr = CentralRepository.getInstance(); - PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); - CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback); + if (cr != null) { + String queryClause = PERSONA_ACCOUNTS_QUERY_CALUSE + + " WHERE persona_accounts.persona_id = " + personaId; - return queryCallback.getPersonaAccountsList(); + PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); + cr.executeSelectSQL(queryClause, queryCallback); + + return queryCallback.getPersonaAccountsList(); + } + + return new ArrayList<>(); } - + /** * Gets all the Persona for the specified Account. * * @param accountId Id of account for which to get the Personas for. + * * @return Collection of PersonaAccounts. may be empty. * * @throws CentralRepoException If there is an error in getting the - * persona_account. + * persona_account. */ public static Collection getPersonaAccountsForAccount(long accountId) throws CentralRepoException { - String queryClause = PERSONA_ACCOUNTS_QUERY_CALUSE - + " WHERE persona_accounts.account_id = " + accountId; - PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); - CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback); + CentralRepository cr = CentralRepository.getInstance(); - return queryCallback.getPersonaAccountsList(); + if (cr != null) { + String queryClause = PERSONA_ACCOUNTS_QUERY_CALUSE + + " WHERE persona_accounts.account_id = " + accountId; + + PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); + cr.executeSelectSQL(queryClause, queryCallback); + + return queryCallback.getPersonaAccountsList(); + } + + return new ArrayList<>(); } - + /** * Gets all the Persona associated with all the accounts matching the given * account identifier substring. * * @param accountIdentifierSubstring Account identifier substring to search - * for. + * for. + * * @return Collection of PersonaAccounts. may be empty. * * @throws CentralRepoException If there is an error in getting the - * persona_account. + * persona_account. */ public static Collection getPersonaAccountsForIdentifierLike(String accountIdentifierSubstring) throws CentralRepoException { String queryClause = PERSONA_ACCOUNTS_QUERY_CALUSE + " WHERE LOWER(accounts.account_unique_identifier) LIKE LOWER('%" + accountIdentifierSubstring + "%')"; - PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); - CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback); + CentralRepository cr = CentralRepository.getInstance(); + if (cr != null) { + PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); + 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 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<>(); + } + /** * Callback to process a query that gets all accounts belonging to a * persona. @@ -274,21 +318,29 @@ public class PersonaAccount { * @param personaId Id of the persona to look for. * * @return Collection of all accounts associated with the given persona, may - * be empty. - * @throws CentralRepoException If there is an error in getting the accounts. + * be empty. + * + * @throws CentralRepoException If there is an error in getting the + * accounts. */ static Collection getAccountsForPersona(long personaId) throws CentralRepoException { - String queryClause = "SELECT account_id, " - + " accounts.account_type_id as account_type_id, accounts.account_unique_identifier as account_unique_identifier," - + " account_types.type_name as type_name " - + " FROM persona_accounts " - + " JOIN accounts as accounts on persona_accounts.account_id = accounts.id " - + " JOIN account_types as account_types on accounts.account_type_id = account_types.id " - + " WHERE persona_accounts.persona_id = " + personaId; + CentralRepository cr = CentralRepository.getInstance(); - AccountsForPersonaQueryCallback queryCallback = new AccountsForPersonaQueryCallback(); - CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback); + if (cr != null) { + String queryClause = "SELECT account_id, " + + " accounts.account_type_id as account_type_id, accounts.account_unique_identifier as account_unique_identifier," + + " account_types.type_name as type_name " + + " FROM persona_accounts " + + " JOIN accounts as accounts on persona_accounts.account_id = accounts.id " + + " JOIN account_types as account_types on accounts.account_type_id = account_types.id " + + " WHERE persona_accounts.persona_id = " + personaId; - return queryCallback.getAccountsList(); + AccountsForPersonaQueryCallback queryCallback = new AccountsForPersonaQueryCallback(); + cr.executeSelectSQL(queryClause, queryCallback); + + return queryCallback.getAccountsList(); + } + + return new ArrayList<>(); } } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/persona/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/centralrepository/persona/Bundle.properties-MERGED index 2258c7df21..3c7765f09c 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/persona/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/persona/Bundle.properties-MERGED @@ -1,18 +1,38 @@ 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_Title=Central Repository failure -AddAccountDialog_validate_id_failure=Account ID must not be empty -AddAccountDialog_validate_id_failure_title=Account ID issue +AddAccountDialog_search_empty_msg=Account not found for given identifier and type +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_PersonaManagerTopComponentAction=Persona Manager CTL_PersonaDetailsTopComponent=Persona Details 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_Title=Initialization failure PersonaDetailsPanel_NameCreate=Create Persona PersonaDetailsPanel_NameEdit=Edit 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.resultsTable.columnModel.title1=Name PersonaManagerTopComponent.resultsTable.columnModel.title0=ID @@ -20,6 +40,17 @@ PersonaManagerTopComponent.resultsTable.toolTipText= PersonaManagerTopComponent.searchAccountRadio.text=Account PersonaManagerTopComponent.searchNameRadio.text=Name 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.addMetadataBtn.text=Add PersonaDetailsPanel.metadataLabel.text=Metadata: @@ -27,18 +58,32 @@ PersonaDetailsPanel.deleteAccountBtn.text=Delete PersonaDetailsPanel.addAccountBtn.text=Add PersonaDetailsPanel.accountsLbl.text=Accounts: PersonaDetailsPanel.nameField.text= -PersonaDetailsPanel.saveBtn.toolTipText= -PersonaDetailsPanel.saveBtn.text=Save Changes PersonaDetailsPanel.nameLbl.text=Name: -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: -AddAccountDialog.cancelBtn.text=Cancel -AddAccountDialog.okBtn.text=OK -PersonaManagerTopComponent.editBtn.text=Edit +AddAliasDialog.accountsLbl.text=Account: +AddAliasDialog.okBtn.text=OK +AddAliasDialog.cancelBtn.text=Cancel +AddMetadataDialog.cancelBtn.text=Cancel +AddMetadataDialog.okBtn.text=OK +AddMetadataDialog.nameLbl.text=Name: +AddMetadataDialog.nameTextField.text= +AddMetadataDialog.valueLbl.text=Value: +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_search_exception_msg=Failed to search personas PMTopComponent_search_exception_Title=Search failure diff --git a/Core/src/org/sleuthkit/autopsy/communications/AccountDeviceInstanceNode.java b/Core/src/org/sleuthkit/autopsy/communications/AccountDeviceInstanceNode.java index a567e6a31a..4a50969ef3 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/AccountDeviceInstanceNode.java +++ b/Core/src/org/sleuthkit/autopsy/communications/AccountDeviceInstanceNode.java @@ -123,7 +123,7 @@ final class AccountDeviceInstanceNode extends AbstractNode { public String getShortDescription() { List personaList; try { - personaList = CVTPersonaCache.getPersonaAccounts(getName()); + personaList = CVTPersonaCache.getPersonaAccounts(account); } catch (ExecutionException ex) { logger.log(Level.WARNING, "Failed to retrieve Persona details for node.", ex); return getDisplayName(); diff --git a/Core/src/org/sleuthkit/autopsy/communications/CVTPersonaCache.java b/Core/src/org/sleuthkit/autopsy/communications/CVTPersonaCache.java index b66fab6731..92cebad8a3 100755 --- a/Core/src/org/sleuthkit/autopsy/communications/CVTPersonaCache.java +++ b/Core/src/org/sleuthkit/autopsy/communications/CVTPersonaCache.java @@ -31,6 +31,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoException; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository; import org.sleuthkit.autopsy.centralrepository.datamodel.PersonaAccount; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.datamodel.Account; /** * A singleton cache of the PersonaAccount information. The list of @@ -40,7 +41,7 @@ import org.sleuthkit.autopsy.coreutils.Logger; final class CVTPersonaCache { private static final Logger logger = Logger.getLogger(CVTPersonaCache.class.getName()); - private final LoadingCache> accountMap; + private final LoadingCache> accountMap; private static CVTPersonaCache instance; @@ -49,13 +50,13 @@ final class CVTPersonaCache { */ private CVTPersonaCache() { accountMap = CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.MINUTES).build( - new CacheLoader>() { + new CacheLoader>() { @Override - public List load(String key) { + public List load(Account key) { List accountList = new ArrayList<>(); try { if (CentralRepository.isEnabled()) { - Collection accounts = PersonaAccount.getPersonaAccountsForIdentifierLike(key); + Collection accounts = PersonaAccount.getPersonaAccountsForAccount(key); accountList.addAll(accounts); } } catch (CentralRepoException ex) { @@ -89,7 +90,7 @@ final class CVTPersonaCache { * * @throws ExecutionException */ - static synchronized List getPersonaAccounts(String typeSpecificID) throws ExecutionException { - return getInstance().accountMap.get(typeSpecificID); + static synchronized List getPersonaAccounts(Account account) throws ExecutionException { + return getInstance().accountMap.get(account); } }