Search in sources :

Example 21 with OAuth2TokenCache

use of com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache in project microsoft-authentication-library-common-for-android by AzureAD.

the class BrokerOAuth2TokenCache method getAccountsWithAggregatedAccountData.

@Override
public List<ICacheRecord> getAccountsWithAggregatedAccountData(@Nullable final String environment, @NonNull final String clientId, @NonNull final String homeAccountId) {
    final String methodName = ":getAccountsWithAggregatedAccountData";
    final List<ICacheRecord> result;
    OAuth2TokenCache targetCache;
    if (null != environment) {
        targetCache = getTokenCacheForClient(clientId, environment, mCallingProcessUid);
        if (null == targetCache) {
            Logger.verbose(TAG + methodName, "Falling back to FoCI cache...");
            targetCache = mFociCache;
        }
        // Suppressing unchecked warnings due to casting of rawtypes to generic types of OAuth2TokenCache's instance targetCache while calling method getAccountsWithAggregatedAccountData
        @SuppressWarnings(WarningType.unchecked_warning) List<ICacheRecord> resultByAggregatedAccountData = targetCache.getAccountsWithAggregatedAccountData(environment, clientId, homeAccountId);
        result = resultByAggregatedAccountData;
    } else {
        // If no environment was specified, return all of the accounts across all of the envs...
        // Callers should really specify an environment...
        final List<OAuth2TokenCache> caches = getTokenCachesForClientId(clientId);
        // Declare a new List to which we will add all of our results...
        result = new ArrayList<>();
        for (final OAuth2TokenCache cache : caches) {
            // Suppressing unchecked warning as the generic type was not provided for cache
            @SuppressWarnings(WarningType.unchecked_warning) List<ICacheRecord> accountsWithAggregatedAccountData = cache.getAccountsWithAggregatedAccountData(environment, clientId, homeAccountId);
            result.addAll(accountsWithAggregatedAccountData);
        }
    }
    return result;
}
Also used : OAuth2TokenCache(com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache)

Example 22 with OAuth2TokenCache

use of com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache 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)

Aggregations

OAuth2TokenCache (com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache)20 AccountRecord (com.microsoft.identity.common.internal.dto.AccountRecord)11 ArrayList (java.util.ArrayList)6 ICacheRecord (com.microsoft.identity.common.internal.cache.ICacheRecord)5 Context (android.content.Context)3 Nullable (androidx.annotation.Nullable)3 BrokerApplicationMetadata (com.microsoft.identity.common.internal.cache.BrokerApplicationMetadata)3 BrokerOAuth2TokenCache (com.microsoft.identity.common.internal.cache.BrokerOAuth2TokenCache)3 MicrosoftFamilyOAuth2TokenCache (com.microsoft.identity.common.internal.cache.MicrosoftFamilyOAuth2TokenCache)3 MsalOAuth2TokenCache (com.microsoft.identity.common.internal.cache.MsalOAuth2TokenCache)3 Test (org.junit.Test)3 OAuth2StrategyParameters (com.microsoft.identity.common.internal.providers.oauth2.OAuth2StrategyParameters)2 TokenResult (com.microsoft.identity.common.internal.providers.oauth2.TokenResult)2 AcquireTokenResult (com.microsoft.identity.common.internal.result.AcquireTokenResult)2 LocalAuthenticationResult (com.microsoft.identity.common.internal.result.LocalAuthenticationResult)2 Uri (android.net.Uri)1 ClientException (com.microsoft.identity.common.exception.ClientException)1 AbstractAuthenticationScheme (com.microsoft.identity.common.internal.authscheme.AbstractAuthenticationScheme)1 IPoPAuthenticationSchemeParams (com.microsoft.identity.common.internal.authscheme.IPoPAuthenticationSchemeParams)1 AccountDeletionRecord (com.microsoft.identity.common.internal.cache.AccountDeletionRecord)1