use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCache method getAccounts.
/**
* Broker-only API. Fetches AccountRecords from all provided caches - makes NO GUARANTEES
* as to whether or not an AT/RT pair exists for these Accounts.
*
* @return A List of AccountRecords, may be empty but is never null.
*/
public List<AccountRecord> getAccounts() {
final String methodName = ":getAccounts";
final Set<AccountRecord> allAccounts = new HashSet<>();
final List<BrokerApplicationMetadata> allMetadata = mApplicationMetadataCache.getAll();
// TODO - Everything inside this loop can be parallelized... should it be?
for (final BrokerApplicationMetadata metadata : allMetadata) {
final OAuth2TokenCache candidateCache = getTokenCacheForClient(metadata);
if (null != candidateCache) {
allAccounts.addAll(((MsalOAuth2TokenCache) candidateCache).getAccountCredentialCache().getAccounts());
}
}
// Hit the FOCI cache
allAccounts.addAll(mFociCache.getAccountCredentialCache().getAccounts());
final List<AccountRecord> allAccountsResult = new ArrayList<>(allAccounts);
Logger.verbose(TAG + methodName, "Found [" + allAccountsResult.size() + "] accounts.");
return allAccountsResult;
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCache method getAccountByHomeAccountId.
@Override
public AccountRecord getAccountByHomeAccountId(@Nullable final String environment, @NonNull final String clientId, @NonNull final String homeAccountId) {
final String methodName = "getAccountByHomeAccountId";
Logger.verbose(TAG + methodName, "Loading account by home account id.");
if (null != environment) {
OAuth2TokenCache targetCache = getTokenCacheForClient(clientId, environment, mCallingProcessUid);
Logger.info(TAG + methodName, "Loading from FOCI cache? [" + (targetCache == null) + "]");
if (null != targetCache) {
return targetCache.getAccountByHomeAccountId(environment, clientId, homeAccountId);
} else {
return mFociCache.getAccountByHomeAccountId(environment, clientId, homeAccountId);
}
} else {
AccountRecord result = null;
final List<OAuth2TokenCache> cachesToInspect = getTokenCachesForClientId(clientId);
final Iterator<OAuth2TokenCache> cacheIterator = cachesToInspect.iterator();
while (null == result && cacheIterator.hasNext()) {
result = cacheIterator.next().getAccountByHomeAccountId(environment, clientId, homeAccountId);
}
return result;
}
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCache method getAccountByLocalAccountId.
@Override
@Nullable
public AccountRecord getAccountByLocalAccountId(@Nullable final String environment, @NonNull final String clientId, @NonNull final String localAccountId) {
final String methodName = ":getAccountByLocalAccountId";
Logger.verbose(TAG + methodName, "Loading account by local account id.");
if (null != environment) {
OAuth2TokenCache targetCache = getTokenCacheForClient(clientId, environment, mCallingProcessUid);
Logger.info(TAG + methodName, "Loading from FOCI cache? [" + (targetCache == null) + "]");
if (null != targetCache) {
return targetCache.getAccountByLocalAccountId(environment, clientId, localAccountId);
} else {
return mFociCache.getAccountByLocalAccountId(environment, clientId, localAccountId);
}
} else {
AccountRecord result = null;
final List<OAuth2TokenCache> cachesToInspect = getTokenCachesForClientId(clientId);
final Iterator<OAuth2TokenCache> cacheIterator = cachesToInspect.iterator();
while (null == result && cacheIterator.hasNext()) {
result = cacheIterator.next().getAccountByLocalAccountId(environment, clientId, localAccountId);
}
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 getAccountByHomeAccountId.
@Nullable
@Override
public AccountRecord getAccountByHomeAccountId(@Nullable final String environment, @NonNull final String clientId, @NonNull final String homeAccountId) {
final String methodName = ":getAccountByHomeAccountId";
final List<AccountRecord> accounts = getAccounts(environment, clientId);
Logger.verbosePII(TAG + methodName, "homeAccountId: [" + homeAccountId + "]");
for (final AccountRecord account : accounts) {
if (homeAccountId.equals(account.getHomeAccountId())) {
return account;
}
}
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 removeAccount.
/**
* Removes the specified Account or Accounts from the cache.
* <p>
* Note: if realm is passed as null, all tokens and AccountRecords associated to the
* provided homeAccountId will be deleted. If a realm is provided, then the deletion is
* restricted to only those AccountRecords and Credentials in that realm (tenant).
* <p>
* clientId, and home_account_id are nullable parameters. However, it should be
* noted that if these params are null, this method will have no effect.
*
* @param environment The environment to which the targeted Account is associated.
* @param clientId The clientId of this current app.
* @param homeAccountId The homeAccountId of the Account targeted for deletion.
* @param realm The tenant id of the targeted Account (if applicable).
* @param typesToRemove The CredentialTypes to delete for the targeted Account.
* @return An {@link AccountDeletionRecord}, containing the deleted {@link AccountDeletionRecord}s.
*/
@Override
public AccountDeletionRecord removeAccount(@Nullable final String environment, @Nullable final String clientId, @Nullable final String homeAccountId, @Nullable final String realm, @Nullable final CredentialType... typesToRemove) {
final String methodName = ":removeAccount";
Logger.verbosePII(TAG + methodName, "Environment: [" + environment + "]" + "\n" + "ClientId: [" + clientId + "]" + "\n" + "HomeAccountId: [" + homeAccountId + "]" + "\n" + "Realm: [" + realm + "]" + "\n" + "CredentialTypes to delete: [" + Arrays.toString(typesToRemove) + "]");
final AccountRecord targetAccount;
if (null == clientId || null == homeAccountId || null == (targetAccount = getAccount(environment, clientId, homeAccountId, realm))) {
Logger.warn(TAG + methodName, "Insufficient filtering provided for account removal - preserving Account.");
return new AccountDeletionRecord(null);
}
// If no realm is provided, remove the Account/Credentials from all realms.
final boolean isRealmAgnostic = (null == realm);
Logger.verbose(TAG + methodName, "IsRealmAgnostic? " + isRealmAgnostic);
if (null != typesToRemove && typesToRemove.length > 0) {
for (final CredentialType type : typesToRemove) {
// A count of the deleted creds...
int deletedCredentialsOfTypeCount = removeCredentialsOfTypeForAccount(environment, clientId, type, targetAccount, isRealmAgnostic);
com.microsoft.identity.common.internal.logging.Logger.info(TAG + methodName, "Removed " + deletedCredentialsOfTypeCount + " credentials of type: " + type);
}
} else {
com.microsoft.identity.common.internal.logging.Logger.warn(TAG + methodName, "removeAccount called, but no CredentialTypes to remove specified");
}
final List<AccountRecord> deletedAccounts = new ArrayList<>();
if (isRealmAgnostic) {
// Remove all Accounts associated with this home_account_id...
final List<AccountRecord> accountsToRemove = mAccountCredentialCache.getAccountsFilteredBy(homeAccountId, environment, // wildcard (*) realm
null);
for (final AccountRecord accountToRemove : accountsToRemove) {
if (mAccountCredentialCache.removeAccount(accountToRemove)) {
deletedAccounts.add(accountToRemove);
}
}
} else {
// Remove only the target Account
if (mAccountCredentialCache.removeAccount(targetAccount)) {
deletedAccounts.add(targetAccount);
}
}
return new AccountDeletionRecord(deletedAccounts);
}
Aggregations