use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCache method getAllTenantAccountsForAccountByClientId.
@Override
public List<AccountRecord> getAllTenantAccountsForAccountByClientId(@NonNull final String clientId, @NonNull final AccountRecord accountRecord) {
final List<AccountRecord> allTenantAccounts = new ArrayList<>();
// Add the supplied AccountRecord as the 0th element...
allTenantAccounts.add(accountRecord);
// Grab all the accounts which might match
final List<AccountRecord> allMatchingAccountsByHomeId = mAccountCredentialCache.getAccountsFilteredBy(accountRecord.getHomeAccountId(), accountRecord.getEnvironment(), // realm
null);
// Grab all of the AccountRecords associated with this clientId
final List<AccountRecord> allAppAccounts = getAccounts(accountRecord.getEnvironment(), clientId);
// Iterate and populate
for (final AccountRecord acct : allAppAccounts) {
if (allMatchingAccountsByHomeId.contains(acct) && !accountRecord.equals(acct)) {
allTenantAccounts.add(acct);
}
}
return Collections.unmodifiableList(allTenantAccounts);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class AbstractAccountCredentialCache method getAccountsFilteredByInternal.
@NonNull
protected List<AccountRecord> getAccountsFilteredByInternal(@Nullable final String homeAccountId, @Nullable final String environment, @Nullable final String realm, @NonNull final List<AccountRecord> allAccounts) {
final boolean mustMatchOnHomeAccountId = !StringExtensions.isNullOrBlank(homeAccountId);
final boolean mustMatchOnEnvironment = !StringExtensions.isNullOrBlank(environment);
final boolean mustMatchOnRealm = !StringExtensions.isNullOrBlank(realm);
Logger.verbose(TAG, "Account lookup filtered by home_account_id? [" + mustMatchOnHomeAccountId + "]" + NEW_LINE + "Account lookup filtered by realm? [" + mustMatchOnRealm + "]");
final List<AccountRecord> matchingAccounts = new ArrayList<>();
for (final AccountRecord account : allAccounts) {
boolean matches = true;
if (mustMatchOnHomeAccountId) {
matches = equalsIgnoreCaseTrimBoth(homeAccountId, account.getHomeAccountId());
}
if (mustMatchOnEnvironment) {
matches = matches && equalsIgnoreCaseTrimBoth(environment, account.getEnvironment());
}
if (mustMatchOnRealm) {
matches = matches && equalsIgnoreCaseTrimBoth(realm, account.getRealm());
}
if (matches) {
matchingAccounts.add(account);
}
}
Logger.verbose(TAG, "Found [" + matchingAccounts.size() + "] matching accounts");
return matchingAccounts;
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCache method removeAccountInternal.
private AccountDeletionRecord removeAccountInternal(@Nullable final String environment, @Nullable final String clientId, @Nullable final String homeAccountId, @Nullable final String realm, boolean deviceWide) {
final String methodName = ":removeAccountInternal";
final List<BrokerApplicationMetadata> allMetadata = mApplicationMetadataCache.getAll();
final List<AccountDeletionRecord> deletionRecordList = new ArrayList<>();
for (final BrokerApplicationMetadata metadata : allMetadata) {
final OAuth2TokenCache candidateCache = getTokenCacheForClient(metadata.getClientId(), metadata.getEnvironment(), deviceWide ? // Supports the removeAccountFromDevice() function
metadata.getUid() : mCallingProcessUid);
if (null != candidateCache) {
deletionRecordList.add(candidateCache.removeAccount(environment, clientId, homeAccountId, realm));
}
}
// Create a List of the deleted AccountRecords...
final List<AccountRecord> deletedAccountRecords = new ArrayList<>();
for (final AccountDeletionRecord accountDeletionRecord : deletionRecordList) {
deletedAccountRecords.addAll(accountDeletionRecord);
}
Logger.info(TAG + methodName, "Deleted [" + deletedAccountRecords.size() + "] AccountRecords.");
return new AccountDeletionRecord(deletedAccountRecords);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class CacheKeyValueDelegateTest method accountCreateCacheKeyCompleteNoHomeAccountIdNoRealm.
@Test
public void accountCreateCacheKeyCompleteNoHomeAccountIdNoRealm() {
final AccountRecord account = new AccountRecord();
account.setEnvironment(ENVIRONMENT);
final String expectedKey = "" + CACHE_VALUE_SEPARATOR + ENVIRONMENT + CACHE_VALUE_SEPARATOR;
assertEquals(expectedKey, mDelegate.generateCacheKey(account));
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class CacheKeyValueDelegateTest method accountCreateCacheKeyComplete.
// End AccessTokens
// Accounts
@Test
public void accountCreateCacheKeyComplete() {
final AccountRecord account = new AccountRecord();
account.setHomeAccountId(HOME_ACCOUNT_ID);
account.setEnvironment(ENVIRONMENT);
account.setRealm(REALM);
final String expectedKey = "" + HOME_ACCOUNT_ID + CACHE_VALUE_SEPARATOR + ENVIRONMENT + CACHE_VALUE_SEPARATOR + REALM;
assertEquals(expectedKey, mDelegate.generateCacheKey(account));
}
Aggregations