use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCache method mergeCacheRecordWithOtherTenantCacheRecords.
@NonNull
private List<ICacheRecord> mergeCacheRecordWithOtherTenantCacheRecords(@NonNull final ICacheRecord savedCacheRecord) {
final List<ICacheRecord> result = new ArrayList<>();
// Whatever ICacheRecord you provide will _always_ be the first element in the result List.
result.add(savedCacheRecord);
final List<AccountRecord> accountsInOtherTenants = new ArrayList<>(getAllTenantAccountsForAccountByClientId(savedCacheRecord.getRefreshToken().getClientId(), savedCacheRecord.getAccount()));
if (!accountsInOtherTenants.isEmpty()) {
// Remove the first element from the List since it is already contained in the result List
accountsInOtherTenants.remove(0);
// Iterate over the rest of the Accounts to build up the final result
for (final AccountRecord acct : accountsInOtherTenants) {
result.add(getSparseCacheRecordForAccount(savedCacheRecord.getRefreshToken().getClientId(), acct));
}
}
return result;
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCache method getAccountsWithAggregatedAccountData.
@Override
public List<ICacheRecord> getAccountsWithAggregatedAccountData(@Nullable final String environment, @NonNull final String clientId) {
final String methodName = ":getAccountsWithAggregatedAccountData";
final List<ICacheRecord> result = new ArrayList<>();
final List<AccountRecord> allMatchingAccounts = getAccounts(environment, clientId);
for (final AccountRecord accountRecord : allMatchingAccounts) {
final List<IdTokenRecord> idTokensForAccount = getIdTokensForAccountRecord(clientId, accountRecord);
if (idTokensForAccount == null || idTokensForAccount.size() == 0) {
// Skip returning account record if there is no corresponding idToken record in the cache for the given clientId
continue;
}
// Construct the cache record....
final CacheRecord.CacheRecordBuilder cacheRecordBuilder = CacheRecord.builder();
cacheRecordBuilder.account(accountRecord);
// Set the IdTokens...
for (IdTokenRecord idTokenRecord : idTokensForAccount) {
setToCacheRecord(cacheRecordBuilder, idTokenRecord);
}
result.add(cacheRecordBuilder.build());
}
Logger.verbose(TAG + methodName, "Found " + result.size() + " accounts with IdTokens");
return Collections.unmodifiableList(result);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MicrosoftFamilyOAuth2TokenCache method loadByFamilyIdWithAggregatedAccountData.
public List<ICacheRecord> loadByFamilyIdWithAggregatedAccountData(@NonNull final String clientId, @Nullable final String target, @NonNull final AccountRecord account, @Nullable final AbstractAuthenticationScheme authenticationScheme) {
final String methodName = ":loadByFamilyIdWithAggregatedAccountData";
final List<ICacheRecord> result = new ArrayList<>();
// First, load our primary record...
result.add(loadByFamilyId(clientId, target, account, authenticationScheme));
// We also want to add accounts from different realms...
final List<AccountRecord> accountsInOtherTenants = new ArrayList<>(getAllTenantAccountsForAccountByClientId(clientId, account));
Logger.info(TAG + methodName, "Found " + (accountsInOtherTenants.size() - 1) + " profiles for this account");
// Ignore the first element, as it will contain the same result as loadByFamilyId()....
accountsInOtherTenants.remove(0);
if (!accountsInOtherTenants.isEmpty()) {
for (final AccountRecord accountRecord : accountsInOtherTenants) {
// Declare our container
final CacheRecord.CacheRecordBuilder cacheRecord = CacheRecord.builder();
cacheRecord.mAccount(accountRecord);
cacheRecord.refreshToken(result.get(0).getRefreshToken());
// Load all of the IdTokens and set as appropriate...
final List<IdTokenRecord> idTokensForAccount = getIdTokensForAccountRecord(clientId, accountRecord);
for (final IdTokenRecord idTokenRecord : idTokensForAccount) {
if (CredentialType.V1IdToken.name().equalsIgnoreCase(idTokenRecord.getCredentialType())) {
cacheRecord.v1IdToken(idTokenRecord);
} else {
cacheRecord.idToken(idTokenRecord);
}
}
// We can ignore the A/T, since this account isn't being authorized...
result.add(cacheRecord.build());
}
}
return result;
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCache method getAccount.
@Override
@Nullable
public AccountRecord getAccount(@Nullable final String environment, @NonNull final String clientId, @NonNull final String homeAccountId, @Nullable final String realm) {
final String methodName = ":getAccount";
Logger.verbosePII(TAG + methodName, "Environment: [" + environment + "]" + "\n" + "ClientId: [" + clientId + "]" + "\n" + "HomeAccountId: [" + homeAccountId + "]" + "\n" + "Realm: [" + realm + "]");
final List<AccountRecord> allAccounts = getAccounts(environment, clientId);
Logger.info(TAG + methodName, "Found " + allAccounts.size() + " accounts");
// Return the sought Account matching the supplied homeAccountId and realm, if applicable
for (final AccountRecord account : allAccounts) {
if (homeAccountId.equals(account.getHomeAccountId()) && (null == realm || realm.equals(account.getRealm()))) {
return account;
}
}
Logger.warn(TAG + methodName, "No matching account found.");
return null;
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCache method getAccountByLocalAccountId.
@Override
@Nullable
public AccountRecord getAccountByLocalAccountId(@Nullable final String environment, @NonNull final String clientId, @NonNull final String localAccountId) {
final String methodName = ":getAccountByLocalAccountId";
final List<AccountRecord> accounts = getAccounts(environment, clientId);
Logger.verbosePII(TAG + methodName, "LocalAccountId: [" + localAccountId + "]");
for (final AccountRecord account : accounts) {
if (localAccountId.equals(account.getLocalAccountId())) {
return account;
}
}
return null;
}
Aggregations