Search in sources :

Example 1 with IStorageHelper

use of com.microsoft.identity.common.adal.internal.cache.IStorageHelper in project microsoft-authentication-library-common-for-android by AzureAD.

the class BrokerOAuth2TokenCache method initializeProcessUidCache.

private MsalOAuth2TokenCache initializeProcessUidCache(@NonNull final Context context, final int bindingProcessUid) {
    final String methodName = ":initializeProcessUidCache";
    Logger.verbose(TAG + methodName, "Initializing uid cache.");
    if (null != mDelegate) {
        Logger.warn(TAG + methodName, "Using swapped delegate cache.");
        return mDelegate.getTokenCache(context, bindingProcessUid);
    }
    final IStorageHelper storageHelper = new StorageHelper(context);
    final ISharedPreferencesFileManager sharedPreferencesFileManager = SharedPreferencesFileManager.getSharedPreferences(context, SharedPreferencesAccountCredentialCache.getBrokerUidSequesteredFilename(bindingProcessUid), storageHelper);
    return getTokenCache(context, sharedPreferencesFileManager, false);
}
Also used : IStorageHelper(com.microsoft.identity.common.adal.internal.cache.IStorageHelper) StorageHelper(com.microsoft.identity.common.adal.internal.cache.StorageHelper) IStorageHelper(com.microsoft.identity.common.adal.internal.cache.IStorageHelper)

Example 2 with IStorageHelper

use of com.microsoft.identity.common.adal.internal.cache.IStorageHelper in project microsoft-authentication-library-common-for-android by AzureAD.

the class MsalOAuth2TokenCache method create.

/**
 * Factory method for creating an instance of MsalOAuth2TokenCache
 * <p>
 * NOTE: Currently this is configured for AAD v2 as the only IDP
 *
 * @param context The Application Context
 * @return An instance of the MsalOAuth2TokenCache.
 */
public static MsalOAuth2TokenCache<MicrosoftStsOAuth2Strategy, MicrosoftStsAuthorizationRequest, MicrosoftStsTokenResponse, MicrosoftAccount, MicrosoftRefreshToken> create(@NonNull final Context context) {
    final String methodName = ":create";
    Logger.verbose(TAG + methodName, "Creating MsalOAuth2TokenCache");
    // Init the new-schema cache
    final ICacheKeyValueDelegate cacheKeyValueDelegate = new CacheKeyValueDelegate();
    final IStorageHelper storageHelper = new StorageHelper(context);
    final ISharedPreferencesFileManager sharedPreferencesFileManager = SharedPreferencesFileManager.getSharedPreferences(context, DEFAULT_ACCOUNT_CREDENTIAL_SHARED_PREFERENCES, storageHelper);
    final IAccountCredentialCache accountCredentialCache = new SharedPreferencesAccountCredentialCache(cacheKeyValueDelegate, sharedPreferencesFileManager);
    final MicrosoftStsAccountCredentialAdapter accountCredentialAdapter = new MicrosoftStsAccountCredentialAdapter();
    return new MsalOAuth2TokenCache<>(context, accountCredentialCache, accountCredentialAdapter);
}
Also used : IStorageHelper(com.microsoft.identity.common.adal.internal.cache.IStorageHelper) StorageHelper(com.microsoft.identity.common.adal.internal.cache.StorageHelper) IStorageHelper(com.microsoft.identity.common.adal.internal.cache.IStorageHelper)

Example 3 with IStorageHelper

use of com.microsoft.identity.common.adal.internal.cache.IStorageHelper in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesFileManagerTests method testGetSharedPreferences.

@Test
public void testGetSharedPreferences() throws Exception {
    Field f = SharedPreferencesFileManager.class.getDeclaredField("mStorageHelper");
    f.setAccessible(true);
    Assert.assertSame(mSharedPreferencesFileManager, SharedPreferencesFileManager.getSharedPreferences(InstrumentationRegistry.getTargetContext(), mSharedPreferencesFileManager.getSharedPreferencesFileName(), (IStorageHelper) f.get(mSharedPreferencesFileManager)));
}
Also used : Field(java.lang.reflect.Field) IStorageHelper(com.microsoft.identity.common.adal.internal.cache.IStorageHelper) Test(org.junit.Test)

Example 4 with IStorageHelper

use of com.microsoft.identity.common.adal.internal.cache.IStorageHelper in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesFileManagerTests method testGetSharedPreferencesClear.

@Test
public void testGetSharedPreferencesClear() throws Exception {
    Field f = SharedPreferencesFileManager.class.getDeclaredField("mStorageHelper");
    f.setAccessible(true);
    Assert.assertSame(mSharedPreferencesFileManager, SharedPreferencesFileManager.getSharedPreferences(InstrumentationRegistry.getTargetContext(), mSharedPreferencesFileManager.getSharedPreferencesFileName(), (IStorageHelper) f.get(mSharedPreferencesFileManager)));
    SharedPreferencesFileManager.clearSingletonCache();
    Assert.assertNotSame(mSharedPreferencesFileManager, SharedPreferencesFileManager.getSharedPreferences(InstrumentationRegistry.getTargetContext(), mSharedPreferencesFileManager.getSharedPreferencesFileName(), (IStorageHelper) f.get(mSharedPreferencesFileManager)));
}
Also used : Field(java.lang.reflect.Field) IStorageHelper(com.microsoft.identity.common.adal.internal.cache.IStorageHelper) Test(org.junit.Test)

Example 5 with IStorageHelper

use of com.microsoft.identity.common.adal.internal.cache.IStorageHelper in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesFileManagerTests method testGetSharedPreferencesNoStorageHelper.

@Test
public void testGetSharedPreferencesNoStorageHelper() throws Exception {
    Field f = SharedPreferencesFileManager.class.getDeclaredField("mStorageHelper");
    f.setAccessible(true);
    IStorageHelper storageHelper = (IStorageHelper) f.get(mSharedPreferencesFileManager);
    IStorageHelper newStorageHelper;
    if (storageHelper == null) {
        newStorageHelper = new StorageHelper(InstrumentationRegistry.getTargetContext());
    } else {
        newStorageHelper = null;
    }
    Assert.assertNotSame(mSharedPreferencesFileManager, SharedPreferencesFileManager.getSharedPreferences(InstrumentationRegistry.getTargetContext(), mSharedPreferencesFileManager.getSharedPreferencesFileName(), newStorageHelper));
    Assert.assertSame(mSharedPreferencesFileManager, SharedPreferencesFileManager.getSharedPreferences(InstrumentationRegistry.getTargetContext(), mSharedPreferencesFileManager.getSharedPreferencesFileName(), storageHelper));
}
Also used : Field(java.lang.reflect.Field) IStorageHelper(com.microsoft.identity.common.adal.internal.cache.IStorageHelper) StorageHelper(com.microsoft.identity.common.adal.internal.cache.StorageHelper) IStorageHelper(com.microsoft.identity.common.adal.internal.cache.IStorageHelper) Test(org.junit.Test)

Aggregations

IStorageHelper (com.microsoft.identity.common.adal.internal.cache.IStorageHelper)6 StorageHelper (com.microsoft.identity.common.adal.internal.cache.StorageHelper)4 Field (java.lang.reflect.Field)3 Test (org.junit.Test)3