Search in sources :

Example 76 with AccountRecord

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));
}
Also used : AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Example 77 with AccountRecord

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());
}
Also used : AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Example 78 with AccountRecord

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());
}
Also used : AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Example 79 with AccountRecord

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);
}
Also used : AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Example 80 with AccountRecord

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;
}
Also used : AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) ArrayList(java.util.ArrayList)

Aggregations

AccountRecord (com.microsoft.identity.common.internal.dto.AccountRecord)92 Test (org.junit.Test)61 ArrayList (java.util.ArrayList)20 ICacheRecord (com.microsoft.identity.common.internal.cache.ICacheRecord)11 AccessTokenRecord (com.microsoft.identity.common.internal.dto.AccessTokenRecord)11 OAuth2TokenCache (com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache)11 Credential (com.microsoft.identity.common.internal.dto.Credential)10 IdTokenRecord (com.microsoft.identity.common.internal.dto.IdTokenRecord)10 RefreshTokenRecord (com.microsoft.identity.common.internal.dto.RefreshTokenRecord)10 AccountDeletionRecord (com.microsoft.identity.common.internal.cache.AccountDeletionRecord)9 PrimaryRefreshTokenRecord (com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord)7 Nullable (androidx.annotation.Nullable)6 MsalOAuth2TokenCache (com.microsoft.identity.common.internal.cache.MsalOAuth2TokenCache)5 HashMap (java.util.HashMap)5 IAccountRecord (com.microsoft.identity.common.internal.dto.IAccountRecord)4 Context (android.content.Context)3 NonNull (androidx.annotation.NonNull)3 JsonElement (com.google.gson.JsonElement)3 JsonPrimitive (com.google.gson.JsonPrimitive)3 BearerAuthenticationSchemeInternal (com.microsoft.identity.common.internal.authscheme.BearerAuthenticationSchemeInternal)3