use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method malformedCacheValueForAccount.
@Test
public void malformedCacheValueForAccount() {
final AccountRecord account = new AccountRecord();
account.setHomeAccountId(HOME_ACCOUNT_ID);
account.setEnvironment(ENVIRONMENT);
account.setRealm(REALM);
// Generate a cache key
final String cacheKey = mDelegate.generateCacheKey(account);
mSharedPreferencesFileManager.putString(cacheKey, "{\"thing\" : \"not an account\"}");
final AccountRecord malformedAccount = mSharedPreferencesAccountCredentialCache.getAccount(cacheKey);
assertNull(malformedAccount);
assertNull(mSharedPreferencesFileManager.getString(cacheKey));
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getAccountsNoRealm.
@Test
public void getAccountsNoRealm() {
final AccountRecord account = new AccountRecord();
account.setHomeAccountId(HOME_ACCOUNT_ID);
account.setEnvironment(ENVIRONMENT);
account.setRealm(REALM);
account.setLocalAccountId(LOCAL_ACCOUNT_ID);
account.setUsername(USERNAME);
account.setAuthorityType(AUTHORITY_TYPE);
// Save the Account
mSharedPreferencesAccountCredentialCache.saveAccount(account);
// Test retrieval
final List<AccountRecord> accounts = mSharedPreferencesAccountCredentialCache.getAccountsFilteredBy(HOME_ACCOUNT_ID, ENVIRONMENT, null);
assertEquals(1, accounts.size());
final AccountRecord retrievedAccount = accounts.get(0);
assertEquals(HOME_ACCOUNT_ID, retrievedAccount.getHomeAccountId());
assertEquals(ENVIRONMENT, retrievedAccount.getEnvironment());
assertEquals(REALM, retrievedAccount.getRealm());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getAccountsNullEnvironment.
@Test
public void getAccountsNullEnvironment() {
final AccountRecord account1 = new AccountRecord();
account1.setHomeAccountId(HOME_ACCOUNT_ID);
account1.setEnvironment(ENVIRONMENT);
account1.setRealm(REALM);
account1.setLocalAccountId(LOCAL_ACCOUNT_ID);
account1.setUsername(USERNAME);
account1.setAuthorityType(AUTHORITY_TYPE);
final AccountRecord account2 = new AccountRecord();
account2.setHomeAccountId(HOME_ACCOUNT_ID);
account2.setEnvironment(ENVIRONMENT_LEGACY);
account2.setRealm(REALM);
account2.setLocalAccountId(LOCAL_ACCOUNT_ID);
account2.setUsername(USERNAME);
account2.setAuthorityType(AUTHORITY_TYPE);
// Save the Accounts
mSharedPreferencesAccountCredentialCache.saveAccount(account1);
mSharedPreferencesAccountCredentialCache.saveAccount(account2);
// Test retrieval
final List<AccountRecord> accounts = mSharedPreferencesAccountCredentialCache.getAccountsFilteredBy(HOME_ACCOUNT_ID, null, REALM);
assertEquals(2, accounts.size());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method noValueForCacheKeyAccount.
@Test
public void noValueForCacheKeyAccount() {
assertEquals(0, mSharedPreferencesAccountCredentialCache.getAccounts().size());
final AccountRecord account = (AccountRecord) mSharedPreferencesAccountCredentialCache.getAccount("No account");
assertNull(account);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCache method getAccountsByUsername.
/**
* MSAL-only API for querying AccountRecords by username (upn/preferred_username).
*
* @param environment The environment to which the sought AccountRecords are associated.
* @param clientId The clientId to which the sought AccountRecords are associated.
* @param username The username of the sought AccountRecords.
* @return A List of AccountRecords matching the supplied criteria. Cannot be null, may be empty.
*/
public List<AccountRecord> getAccountsByUsername(@Nullable final String environment, @NonNull final String clientId, @NonNull final String username) {
final String methodName = ":getAccountsByUsername";
final List<AccountRecord> result = new ArrayList<>();
final List<AccountRecord> accounts = getAccounts(environment, clientId);
for (final AccountRecord account : accounts) {
if (StringUtil.equalsIgnoreCase(account.getUsername(), username)) {
result.add(account);
}
}
Logger.verbose(TAG + methodName, "Found " + accounts.size() + " accounts matching username.");
return result;
}
Aggregations