use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method saveCredentialNoHomeAccountIdNoTarget.
@Test
public void saveCredentialNoHomeAccountIdNoTarget() {
final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
refreshToken.setCredentialType(CredentialType.RefreshToken.name());
refreshToken.setEnvironment(ENVIRONMENT);
refreshToken.setClientId(CLIENT_ID);
refreshToken.setSecret(SECRET);
// Save the Credential
mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
// Synthesize a cache key for it
final String credentialCacheKey = mDelegate.generateCacheKey(refreshToken);
// Resurrect the Credential
final Credential restoredRefreshToken = mSharedPreferencesAccountCredentialCache.getCredential(credentialCacheKey);
assertEquals(refreshToken, restoredRefreshToken);
}
use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getCredentials.
@Test
public void getCredentials() {
// Save an Account into the cache
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);
mSharedPreferencesAccountCredentialCache.saveAccount(account);
// Save an AccessToken into the cache
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setRealm("Foo");
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);
refreshToken.setSecret(SECRET);
refreshToken.setTarget(TARGET);
mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
// Verify getCredentials() returns two matching elements
final List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentials();
assertTrue(credentials.size() == 2);
}
use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method testIdTokenMerge.
@Test
public void testIdTokenMerge() {
final IdTokenRecord idTokenFirst = new IdTokenRecord();
idTokenFirst.setCredentialType(CredentialType.IdToken.name());
idTokenFirst.setHomeAccountId(HOME_ACCOUNT_ID);
idTokenFirst.setRealm(REALM);
idTokenFirst.setEnvironment(ENVIRONMENT);
idTokenFirst.setClientId(CLIENT_ID);
idTokenFirst.setCachedAt(CACHED_AT);
idTokenFirst.setSecret(SECRET);
// Create and set some additional field data...
final String additionalKey = "extra-prop-1";
final String additionalValue = "extra-value-1";
final JsonElement additionalValueElement = new JsonPrimitive(additionalValue);
final Map<String, JsonElement> additionalFields = new HashMap<>();
additionalFields.put(additionalKey, additionalValueElement);
idTokenFirst.setAdditionalFields(additionalFields);
// Save the Credential
mSharedPreferencesAccountCredentialCache.saveCredential(idTokenFirst);
final IdTokenRecord idTokenSecond = new IdTokenRecord();
idTokenSecond.setCredentialType(CredentialType.IdToken.name());
idTokenSecond.setHomeAccountId(HOME_ACCOUNT_ID);
idTokenSecond.setRealm(REALM);
idTokenSecond.setEnvironment(ENVIRONMENT);
idTokenSecond.setClientId(CLIENT_ID);
idTokenSecond.setCachedAt(CACHED_AT);
idTokenSecond.setSecret(SECRET);
// Create and set some additional field data...
final String additionalKey2 = "extra-prop-2";
final String additionalValue2 = "extra-value-2";
final JsonElement additionalValueElement2 = new JsonPrimitive(additionalValue2);
final Map<String, JsonElement> additionalFields2 = new HashMap<>();
additionalFields2.put(additionalKey2, additionalValueElement2);
idTokenSecond.setAdditionalFields(additionalFields2);
// Save the Credential
mSharedPreferencesAccountCredentialCache.saveCredential(idTokenSecond);
// Synthesize a cache key for it
final String credentialCacheKey = mDelegate.generateCacheKey(idTokenFirst);
// Resurrect the Credential
final Credential restoredIdToken = mSharedPreferencesAccountCredentialCache.getCredential(credentialCacheKey);
assertTrue(idTokenFirst.equals(restoredIdToken));
assertEquals(additionalValue, restoredIdToken.getAdditionalFields().get(additionalKey).getAsString());
assertEquals(additionalValue2, restoredIdToken.getAdditionalFields().get(additionalKey2).getAsString());
}
use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getCredentialsNoRealmNoTarget.
@Test
public void getCredentialsNoRealmNoTarget() {
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("Foo");
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setClientId(CLIENT_ID);
accessToken.setTarget(TARGET);
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
final AccessTokenRecord accessToken2 = new AccessTokenRecord();
accessToken2.setCredentialType(CredentialType.AccessToken.name());
accessToken2.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken2.setRealm("Bar");
accessToken2.setEnvironment(ENVIRONMENT);
accessToken2.setClientId(CLIENT_ID);
accessToken2.setTarget("qux");
accessToken2.setCachedAt(CACHED_AT);
accessToken2.setExpiresOn(EXPIRES_ON);
accessToken2.setSecret(SECRET);
// 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, null, BEARER_AUTHENTICATION_SCHEME.getName());
assertEquals(2, credentials.size());
}
use of com.microsoft.identity.common.internal.dto.Credential in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getCredentialsNoHomeAccountIdNoRealm.
@Test
public void getCredentialsNoHomeAccountIdNoRealm() {
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(TARGET);
// Save the Credentials
mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken2);
List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(null, ENVIRONMENT, CredentialType.AccessToken, CLIENT_ID, null, TARGET, BEARER_AUTHENTICATION_SCHEME.getName());
assertEquals(2, credentials.size());
}
Aggregations