Search in sources :

Example 16 with Credential

use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesAccountCredentialCacheTest method getCredentialsNoClientId.

@Test
public void getCredentialsNoClientId() {
    // Save an AccessToken into the cache
    final AccessTokenRecord accessToken = new AccessTokenRecord();
    accessToken.setCredentialType(CredentialType.AccessToken.name());
    accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
    accessToken.setRealm(REALM);
    accessToken.setEnvironment(ENVIRONMENT);
    accessToken.setClientId(CLIENT_ID);
    accessToken.setTarget(TARGET);
    accessToken.setCachedAt(CACHED_AT);
    accessToken.setExpiresOn(EXPIRES_ON);
    accessToken.setSecret(SECRET);
    mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
    // Save a RefreshToken into the cache
    final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
    refreshToken.setCredentialType(CredentialType.RefreshToken.name());
    refreshToken.setEnvironment(ENVIRONMENT);
    refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
    refreshToken.setClientId(CLIENT_ID + "2");
    refreshToken.setSecret(SECRET);
    refreshToken.setTarget(TARGET);
    mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
    final List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(HOME_ACCOUNT_ID, ENVIRONMENT, null, null, REALM, TARGET, BEARER_AUTHENTICATION_SCHEME.getName());
    assertEquals(2, credentials.size());
}
Also used : Credential(com.microsoft.identity.common.internal.dto.Credential) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 17 with Credential

use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesAccountCredentialCacheTest method getCredentialsNoRealm.

@Test
public void getCredentialsNoRealm() {
    final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
    refreshToken.setSecret(SECRET);
    refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
    refreshToken.setEnvironment(ENVIRONMENT);
    refreshToken.setCredentialType(CredentialType.RefreshToken.name());
    refreshToken.setClientId(CLIENT_ID);
    refreshToken.setTarget(TARGET);
    final AccessTokenRecord accessToken = new AccessTokenRecord();
    accessToken.setCachedAt(CACHED_AT);
    accessToken.setExpiresOn(EXPIRES_ON);
    accessToken.setSecret(SECRET);
    accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
    accessToken.setRealm("Foo");
    accessToken.setEnvironment(ENVIRONMENT);
    accessToken.setCredentialType(CredentialType.AccessToken.name());
    accessToken.setClientId(CLIENT_ID);
    accessToken.setTarget(TARGET);
    final AccessTokenRecord accessToken2 = new AccessTokenRecord();
    accessToken2.setCachedAt(CACHED_AT);
    accessToken2.setExpiresOn(EXPIRES_ON);
    accessToken2.setSecret(SECRET);
    accessToken2.setHomeAccountId(HOME_ACCOUNT_ID);
    accessToken2.setRealm("Bar");
    accessToken2.setEnvironment(ENVIRONMENT);
    accessToken2.setCredentialType(CredentialType.AccessToken.name());
    accessToken2.setClientId(CLIENT_ID);
    accessToken2.setTarget(TARGET);
    // Save the Credentials
    mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
    mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
    mSharedPreferencesAccountCredentialCache.saveCredential(accessToken2);
    List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(HOME_ACCOUNT_ID, ENVIRONMENT, CredentialType.AccessToken, CLIENT_ID, null, TARGET, BEARER_AUTHENTICATION_SCHEME.getName());
    assertEquals(2, credentials.size());
}
Also used : Credential(com.microsoft.identity.common.internal.dto.Credential) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 18 with Credential

use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesAccountCredentialCacheTest method getCredentialsNoHomeAccountIdNoRealmNoTarget.

@Test
public void getCredentialsNoHomeAccountIdNoRealmNoTarget() {
    final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
    refreshToken.setSecret(SECRET);
    refreshToken.setHomeAccountId("Foo");
    refreshToken.setEnvironment(ENVIRONMENT);
    refreshToken.setCredentialType(CredentialType.RefreshToken.name());
    refreshToken.setClientId(CLIENT_ID);
    refreshToken.setTarget(TARGET);
    final AccessTokenRecord accessToken = new AccessTokenRecord();
    accessToken.setCachedAt(CACHED_AT);
    accessToken.setExpiresOn(EXPIRES_ON);
    accessToken.setSecret(SECRET);
    accessToken.setHomeAccountId("Bar");
    accessToken.setRealm(REALM);
    accessToken.setEnvironment(ENVIRONMENT);
    accessToken.setCredentialType(CredentialType.AccessToken.name());
    accessToken.setClientId(CLIENT_ID);
    accessToken.setTarget(TARGET);
    final AccessTokenRecord accessToken2 = new AccessTokenRecord();
    accessToken2.setCachedAt(CACHED_AT);
    accessToken2.setExpiresOn(EXPIRES_ON);
    accessToken2.setSecret(SECRET);
    accessToken2.setHomeAccountId("Baz");
    accessToken2.setRealm(REALM);
    accessToken2.setEnvironment(ENVIRONMENT);
    accessToken2.setCredentialType(CredentialType.AccessToken.name());
    accessToken2.setClientId(CLIENT_ID);
    accessToken2.setTarget("qux");
    // Save the Credentials
    mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
    mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
    mSharedPreferencesAccountCredentialCache.saveCredential(accessToken2);
    List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(null, ENVIRONMENT, CredentialType.AccessToken, CLIENT_ID, null, null, BEARER_AUTHENTICATION_SCHEME.getName());
    assertEquals(2, credentials.size());
}
Also used : Credential(com.microsoft.identity.common.internal.dto.Credential) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 19 with Credential

use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesAccountCredentialCacheTest method getCredentialsNoEnvironment.

@Test
public void getCredentialsNoEnvironment() {
    final RefreshTokenRecord refreshToken1 = new RefreshTokenRecord();
    refreshToken1.setCredentialType(CredentialType.RefreshToken.name());
    refreshToken1.setEnvironment(ENVIRONMENT);
    refreshToken1.setHomeAccountId(HOME_ACCOUNT_ID);
    refreshToken1.setClientId(CLIENT_ID);
    refreshToken1.setSecret(SECRET);
    refreshToken1.setTarget(TARGET);
    final RefreshTokenRecord refreshToken2 = new RefreshTokenRecord();
    refreshToken2.setCredentialType(CredentialType.RefreshToken.name());
    refreshToken2.setEnvironment(ENVIRONMENT_LEGACY);
    refreshToken2.setHomeAccountId(HOME_ACCOUNT_ID);
    refreshToken2.setClientId(CLIENT_ID);
    refreshToken2.setSecret(SECRET);
    refreshToken2.setTarget(TARGET);
    mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken1);
    mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken2);
    List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(HOME_ACCOUNT_ID, // * wildcard
    null, CredentialType.RefreshToken, CLIENT_ID, REALM, TARGET, BEARER_AUTHENTICATION_SCHEME.getName());
    assertEquals(2, credentials.size());
}
Also used : Credential(com.microsoft.identity.common.internal.dto.Credential) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) Test(org.junit.Test)

Example 20 with Credential

use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesAccountCredentialCacheTest method getCredentialsComplete.

@Test
public void getCredentialsComplete() {
    final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
    refreshToken.setCredentialType(CredentialType.RefreshToken.name());
    refreshToken.setEnvironment(ENVIRONMENT);
    refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
    refreshToken.setClientId(CLIENT_ID);
    refreshToken.setSecret(SECRET);
    refreshToken.setTarget(TARGET);
    final AccessTokenRecord accessToken = new AccessTokenRecord();
    accessToken.setCredentialType(CredentialType.AccessToken.name());
    accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
    accessToken.setRealm(REALM);
    accessToken.setEnvironment(ENVIRONMENT);
    accessToken.setClientId(CLIENT_ID);
    accessToken.setTarget(TARGET);
    accessToken.setCachedAt(CACHED_AT);
    accessToken.setExpiresOn(EXPIRES_ON);
    accessToken.setSecret(SECRET);
    // Save the Credentials
    mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
    mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
    List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(HOME_ACCOUNT_ID, ENVIRONMENT, CredentialType.RefreshToken, CLIENT_ID, REALM, TARGET, BEARER_AUTHENTICATION_SCHEME.getName());
    assertEquals(1, credentials.size());
    final Credential retrievedCredential = credentials.get(0);
    assertEquals(CredentialType.RefreshToken.name(), retrievedCredential.getCredentialType());
}
Also used : Credential(com.microsoft.identity.common.internal.dto.Credential) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Aggregations

Credential (com.microsoft.identity.common.internal.dto.Credential)64 Test (org.junit.Test)45 RefreshTokenRecord (com.microsoft.identity.common.internal.dto.RefreshTokenRecord)33 PrimaryRefreshTokenRecord (com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord)31 AccessTokenRecord (com.microsoft.identity.common.internal.dto.AccessTokenRecord)30 AccountRecord (com.microsoft.identity.common.internal.dto.AccountRecord)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 JsonElement (com.google.gson.JsonElement)7 JsonPrimitive (com.google.gson.JsonPrimitive)7 IdTokenRecord (com.microsoft.identity.common.internal.dto.IdTokenRecord)7 CredentialType (com.microsoft.identity.common.internal.dto.CredentialType)3 Map (java.util.Map)3 Nullable (androidx.annotation.Nullable)2 HashSet (java.util.HashSet)2 NonNull (androidx.annotation.NonNull)1 ClientException (com.microsoft.identity.common.exception.ClientException)1 SharedPreferencesFileManager (com.microsoft.identity.common.internal.cache.SharedPreferencesFileManager)1 CacheEndEvent (com.microsoft.identity.common.internal.telemetry.events.CacheEndEvent)1 CacheStartEvent (com.microsoft.identity.common.internal.telemetry.events.CacheStartEvent)1