Search in sources :

Example 86 with AccountRecord

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);
}
Also used : AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) ArrayList(java.util.ArrayList)

Example 87 with AccountRecord

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;
}
Also used : AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) ArrayList(java.util.ArrayList) NonNull(androidx.annotation.NonNull)

Example 88 with AccountRecord

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);
}
Also used : OAuth2TokenCache(com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache) ArrayList(java.util.ArrayList) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord)

Example 89 with AccountRecord

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));
}
Also used : AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Example 90 with AccountRecord

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));
}
Also used : AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Aggregations

AccountRecord (com.microsoft.identity.common.internal.dto.AccountRecord)92 Test (org.junit.Test)61 ArrayList (java.util.ArrayList)20 ICacheRecord (com.microsoft.identity.common.internal.cache.ICacheRecord)11 AccessTokenRecord (com.microsoft.identity.common.internal.dto.AccessTokenRecord)11 OAuth2TokenCache (com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache)11 Credential (com.microsoft.identity.common.internal.dto.Credential)10 IdTokenRecord (com.microsoft.identity.common.internal.dto.IdTokenRecord)10 RefreshTokenRecord (com.microsoft.identity.common.internal.dto.RefreshTokenRecord)10 AccountDeletionRecord (com.microsoft.identity.common.internal.cache.AccountDeletionRecord)9 PrimaryRefreshTokenRecord (com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord)7 Nullable (androidx.annotation.Nullable)6 MsalOAuth2TokenCache (com.microsoft.identity.common.internal.cache.MsalOAuth2TokenCache)5 HashMap (java.util.HashMap)5 IAccountRecord (com.microsoft.identity.common.internal.dto.IAccountRecord)4 Context (android.content.Context)3 NonNull (androidx.annotation.NonNull)3 JsonElement (com.google.gson.JsonElement)3 JsonPrimitive (com.google.gson.JsonPrimitive)3 BearerAuthenticationSchemeInternal (com.microsoft.identity.common.internal.authscheme.BearerAuthenticationSchemeInternal)3