use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method removeNonexistentAccountTest.
@Test
public void removeNonexistentAccountTest() throws ClientException {
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
final AccountDeletionRecord deletionRecord = mCppCache.removeAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
Assert.assertTrue(deletionRecord.isEmpty());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method removeNoMatchingAccount.
@Test
public void removeNoMatchingAccount() throws ClientException {
// Get the generated account
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
// Save it to the cache
mCppCache.saveAccountRecord(generatedAccount);
mCppCache.saveCredentials(null, mTestBundle.mGeneratedRefreshToken);
// Call remove with a different realm
final AccountDeletionRecord deletionRecord = mCppCache.removeAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), REALM2);
// Check the receipt, should remove nothing
Assert.assertEquals(0, deletionRecord.size());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method getAllAccountsTest.
@Test
public void getAllAccountsTest() {
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
mCppCache.saveAccountRecord(generatedAccount);
final List<AccountRecord> accounts = mCppCache.getAllAccounts();
final AccountRecord restoredAccount = accounts.get(0);
Assert.assertEquals(generatedAccount, restoredAccount);
Assert.assertEquals(1, accounts.size());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method removeAccountTest.
@Test
public void removeAccountTest() throws ClientException {
// Get the generated account
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
// Save it to the cache
mCppCache.saveAccountRecord(generatedAccount);
mCppCache.saveCredentials(null, mTestBundle.mGeneratedRefreshToken);
// Call remove
final AccountDeletionRecord deletionRecord = mCppCache.removeAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
// Check the receipt
Assert.assertEquals(generatedAccount, deletionRecord.get(0));
// Try to restore it
final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
// Make sure it doesn't exist....
Assert.assertNull(restoredAccount);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BaseController method getCachedAccountRecord.
/**
* Helper method to get a cached account
*
* @param parameters
* @return
*/
protected AccountRecord getCachedAccountRecord(@NonNull final SilentTokenCommandParameters parameters) throws ClientException {
if (parameters.getAccount() == null) {
throw new ClientException(ErrorStrings.NO_ACCOUNT_FOUND, "No cached accounts found for the supplied homeAccountId and clientId");
}
final boolean isB2CAuthority = B2C.equalsIgnoreCase(parameters.getAuthority().getAuthorityTypeString());
final String clientId = parameters.getClientId();
final String homeAccountId = parameters.getAccount().getHomeAccountId();
final String localAccountId = parameters.getAccount().getLocalAccountId();
AccountRecord targetAccount;
if (isB2CAuthority) {
// Due to differences in the B2C service API relative to AAD, all IAccounts returned by
// the B2C-STS have the same local_account_id irrespective of the policy used to load it.
//
// Because the home_account_id is unique to policy and there is no concept of
// multi-realm accounts relative to B2C, we'll conditionally use the home_account_id
// in these cases
targetAccount = parameters.getOAuth2TokenCache().getAccountByHomeAccountId(null, clientId, homeAccountId);
} else {
targetAccount = parameters.getOAuth2TokenCache().getAccountByLocalAccountId(null, clientId, localAccountId);
}
if (null == targetAccount && parameters.getOAuth2TokenCache() instanceof MsalOAuth2TokenCache) {
targetAccount = getAccountWithFRTIfAvailable(parameters, (MsalOAuth2TokenCache) parameters.getOAuth2TokenCache());
}
if (null == targetAccount) {
Logger.info(TAG, "No accounts found for clientId [" + clientId + ", " + "]", null);
Logger.errorPII(TAG, "No accounts found for clientId, homeAccountId: [" + clientId + ", " + homeAccountId + "]", null);
throw new ClientException(ErrorStrings.NO_ACCOUNT_FOUND, "No cached accounts found for the supplied homeAccountId");
}
return targetAccount;
}
Aggregations