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);
}
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());
}
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));
}
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;
}
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;
}
Aggregations