Search in sources :

Example 16 with AccountRecord

use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class MsalCppOAuth2TokenCacheTest method getAccountNullTest.

@Test
public void getAccountNullTest() throws ClientException {
    final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
    final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
    Assert.assertNull(restoredAccount);
}
Also used : AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Example 17 with AccountRecord

use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class MsalCppOAuth2TokenCacheTest method saveCredentialsWithAccountForPRTTest.

@Test
public void saveCredentialsWithAccountForPRTTest() throws ClientException {
    final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
    mCppCache.saveAccountRecord(generatedAccount);
    mCppCache.saveCredentials(generatedAccount, mTestBundle.mGeneratedAccessToken, mTestBundle.mGeneratedIdToken, mTestBundle.mGeneratedRefreshToken, mTestBundle.mGeneratedPrimaryRefreshToken);
    // Restore it
    final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
    Assert.assertNotNull(restoredAccount);
    Assert.assertEquals(generatedAccount, restoredAccount);
    final ICacheRecord cacheRecord = mCppCache.load(mTestBundle.mGeneratedIdToken.getClientId(), mTestBundle.mGeneratedAccessToken.getTarget(), generatedAccount, new BearerAuthenticationSchemeInternal());
    Assert.assertEquals(mTestBundle.mGeneratedAccessToken, cacheRecord.getAccessToken());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) BearerAuthenticationSchemeInternal(com.microsoft.identity.common.internal.authscheme.BearerAuthenticationSchemeInternal) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Example 18 with AccountRecord

use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class MsalCppOAuth2TokenCacheTest method saveCredentialsWithoutAccountForPRTTest.

@Test
public void saveCredentialsWithoutAccountForPRTTest() throws ClientException {
    final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
    mCppCache.saveCredentials(null, mTestBundle.mGeneratedAccessToken, mTestBundle.mGeneratedIdToken, mTestBundle.mGeneratedPrimaryRefreshToken);
    // Restore it
    final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
    // Account doesn't exist
    Assert.assertNull(restoredAccount);
    // Inspect the contents of the cache
    final List<Credential> credentials = mCppCache.getCredentials();
    Assert.assertTrue(credentials.contains(mTestBundle.mGeneratedAccessToken));
    Assert.assertTrue(credentials.contains(mTestBundle.mGeneratedIdToken));
    Assert.assertTrue(credentials.contains(mTestBundle.mGeneratedPrimaryRefreshToken));
}
Also used : Credential(com.microsoft.identity.common.internal.dto.Credential) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Example 19 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 getAllTenantAccountsForAccountByClientId.

@Override
public List<AccountRecord> getAllTenantAccountsForAccountByClientId(@NonNull final String clientId, @NonNull final AccountRecord accountRecord) {
    final OAuth2TokenCache cache = getTokenCacheForClient(clientId, accountRecord.getEnvironment(), mCallingProcessUid);
    // Suppressing unchecked warnings due to casting List to List<AccountRecord> as the generic type for cache was not provided
    @SuppressWarnings(WarningType.unchecked_warning) List<AccountRecord> tenantAccountsForAccountByClientId = cache.getAllTenantAccountsForAccountByClientId(clientId, accountRecord);
    return tenantAccountsForAccountByClientId;
}
Also used : OAuth2TokenCache(com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord)

Example 20 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 getFociCacheRecords.

/**
 * Returns the List of FoCI users in the cache. This API is provided so that the broker may
 * **internally** query the cache for known users, such that the broker may verify an
 * unknown clientId is a part of the FoCI family.
 * <p>
 * Please note, the ICacheRecords returned by this query are NOT fully populated. Only the
 * {@link GenericAccount} and {@link GenericRefreshToken} will be returned.
 * will be resutned.
 *
 * @return A List of ICacheRecords for the FoCI accounts.
 */
@SuppressWarnings(UNCHECKED)
public List<ICacheRecord> getFociCacheRecords() {
    final String methodName = ":getFociCacheRecords";
    final List<ICacheRecord> result = new ArrayList<>();
    final List<BrokerApplicationMetadata> allFociApplicationMetadata = mApplicationMetadataCache.getAllFociApplicationMetadata();
    for (final BrokerApplicationMetadata fociAppMetadata : allFociApplicationMetadata) {
        // Load all the accounts
        final List<AccountRecord> accounts = mFociCache.getAccounts(fociAppMetadata.getEnvironment(), fociAppMetadata.getClientId());
        // For each account, load the RT
        for (final AccountRecord account : accounts) {
            final String homeAccountId = account.getHomeAccountId();
            final String environment = account.getEnvironment();
            final String clientId = fociAppMetadata.getClientId();
            final String realm = account.getRealm();
            // Load the refresh token (1 per user per environment)
            final List<Credential> refreshTokens = mFociCache.getAccountCredentialCache().getCredentialsFilteredBy(homeAccountId, environment, CredentialType.RefreshToken, clientId, // wildcard (*)
            null, // wildcard (*)
            null, // Not applicable
            null);
            // Load the V1IdToken (v1 if adal used)
            final List<Credential> v1IdTokens = mFociCache.getAccountCredentialCache().getCredentialsFilteredBy(homeAccountId, environment, CredentialType.V1IdToken, clientId, realm, null, // Not applicable
            null);
            // Load the IdToken
            final List<Credential> idTokens = mFociCache.getAccountCredentialCache().getCredentialsFilteredBy(homeAccountId, environment, CredentialType.IdToken, clientId, realm, null, // not applicable
            null);
            // Construct the ICacheRecord
            if (!refreshTokens.isEmpty()) {
                final CacheRecord.CacheRecordBuilder cacheRecord = CacheRecord.builder();
                cacheRecord.account(account);
                cacheRecord.refreshToken((RefreshTokenRecord) refreshTokens.get(0));
                // Add the V1IdToken (if exists, should have 1 if ADAL used)
                if (!v1IdTokens.isEmpty()) {
                    Logger.verbose(TAG + methodName, "Found [" + v1IdTokens.size() + "] V1IdTokens");
                    cacheRecord.v1IdToken((IdTokenRecord) v1IdTokens.get(0));
                } else {
                    Logger.warn(TAG + methodName, "No V1IdTokens exist for this account.");
                }
                // Add the IdTokens (if exists, should have 1 if MSAL used)
                if (!idTokens.isEmpty()) {
                    Logger.verbose(TAG + methodName, "Found [" + idTokens.size() + "] IdTokens");
                    cacheRecord.idToken((IdTokenRecord) idTokens.get(0));
                } else {
                    Logger.warn(TAG + methodName, "No IdTokens exist for this account.");
                }
                // Add it to the result
                result.add(cacheRecord.build());
            }
        }
    }
    return result;
}
Also used : Credential(com.microsoft.identity.common.internal.dto.Credential) ArrayList(java.util.ArrayList) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord)

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