use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCache method setSingleSignOnState.
@Override
public void setSingleSignOnState(final GenericAccount account, final GenericRefreshToken refreshToken) throws ClientException {
Logger.info(TAG + ":setSingleSignOnState", "Set SSO state called.");
final AccountRecord accountDto = mAccountCredentialAdapter.asAccount(account);
final RefreshTokenRecord rt = mAccountCredentialAdapter.asRefreshToken(refreshToken);
final IdTokenRecord idToken = mAccountCredentialAdapter.asIdToken(account, refreshToken);
validateCacheArtifacts(accountDto, null, rt, idToken);
saveAccounts(accountDto);
saveCredentialsInternal(idToken, rt);
removeAllRefreshTokensExcept(accountDto, rt);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCache method getAccountWithAggregatedAccountDataByLocalAccountId.
@Override
@Nullable
public ICacheRecord getAccountWithAggregatedAccountDataByLocalAccountId(@Nullable String environment, @NonNull String clientId, @NonNull String localAccountId) {
CacheRecord.CacheRecordBuilder result = null;
final AccountRecord acct = getAccountByLocalAccountId(environment, clientId, localAccountId);
if (null != acct) {
final List<IdTokenRecord> acctIdTokens = getIdTokensForAccountRecord(clientId, acct);
result = CacheRecord.builder();
result.account(acct);
for (final IdTokenRecord idTokenRecord : acctIdTokens) {
setToCacheRecord(result, idTokenRecord);
}
return result.build();
}
return null;
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCache method removeAccount.
@Override
public boolean removeAccount(@NonNull final AccountRecord accountToRemove) {
Logger.info(TAG, "Removing Account...");
if (null == accountToRemove) {
throw new IllegalArgumentException("Param [accountToRemove] cannot be null.");
}
final Map<String, AccountRecord> accounts = getAccountsWithKeys();
boolean accountRemoved = false;
for (final Map.Entry<String, AccountRecord> entry : accounts.entrySet()) {
Logger.verbosePII(TAG, "Inspecting: [" + entry.getKey() + "]");
final IAccountRecord currentAccount = entry.getValue();
if (currentAccount.equals(accountToRemove)) {
mSharedPreferencesFileManager.remove(entry.getKey());
accountRemoved = true;
break;
}
}
Logger.info(TAG, "Account was removed? [" + accountRemoved + "]");
return accountRemoved;
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCache method forceRemoveAccount.
/**
* Force remove an AccountRecord matching the supplied criteria.
*
* @param homeAccountId HomeAccountId of the Account.
* @param environment The Environment of the Account.
* @param realm The Realm of the Account.
* @return An {@link AccountDeletionRecord} containing a receipt of the removed Accounts.
* @throws ClientException
*/
// private by default for production code
@VisibleForTesting
public synchronized AccountDeletionRecord forceRemoveAccount(@NonNull final String homeAccountId, @Nullable final String environment, @Nullable final String realm) throws ClientException {
validateNonNull(homeAccountId, "homeAccountId");
final boolean mustMatchOnEnvironment = !StringExtensions.isNullOrBlank(environment);
final boolean mustMatchOnRealm = !StringExtensions.isNullOrBlank(realm);
final List<AccountRecord> removedAccounts = new ArrayList<>();
for (final AccountRecord accountRecord : getAllAccounts()) {
boolean matches = accountRecord.getHomeAccountId().equals(homeAccountId);
if (mustMatchOnEnvironment) {
matches = matches && accountRecord.getEnvironment().equals(environment);
}
if (mustMatchOnRealm) {
matches = matches && accountRecord.getRealm().equals(realm);
}
if (matches) {
// Delete the AccountRecord...
final boolean accountRemoved = getAccountCredentialCache().removeAccount(accountRecord);
if (accountRemoved) {
removedAccounts.add(accountRecord);
}
}
}
return new AccountDeletionRecord(removedAccounts);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCache method save.
@Override
public ICacheRecord save(@NonNull final GenericOAuth2Strategy oAuth2Strategy, @NonNull final GenericAuthorizationRequest request, @NonNull final GenericTokenResponse response) throws ClientException {
// Create the Account
final AccountRecord accountToSave = mAccountCredentialAdapter.createAccount(oAuth2Strategy, request, response);
// Create the AccessToken
final AccessTokenRecord accessTokenToSave = mAccountCredentialAdapter.createAccessToken(oAuth2Strategy, request, response);
// Create the RefreshToken
final RefreshTokenRecord refreshTokenToSave = mAccountCredentialAdapter.createRefreshToken(oAuth2Strategy, request, response);
// Create the IdToken
final IdTokenRecord idTokenToSave = mAccountCredentialAdapter.createIdToken(oAuth2Strategy, request, response);
// Check that everything we're about to save is schema-compliant...
validateCacheArtifacts(accountToSave, accessTokenToSave, refreshTokenToSave, idTokenToSave);
// Save the Account and Credentials...
saveAccounts(accountToSave);
saveCredentialsInternal(accessTokenToSave, refreshTokenToSave, idTokenToSave);
// Remove old refresh tokens (except for the one we just saved) if it's MRRT or FRT
removeAllRefreshTokensExcept(accountToSave, refreshTokenToSave);
final CacheRecord.CacheRecordBuilder result = CacheRecord.builder();
result.account(accountToSave);
result.accessToken(accessTokenToSave);
result.refreshToken(refreshTokenToSave);
setToCacheRecord(result, idTokenToSave);
return result.build();
}
Aggregations