use of com.microsoft.identity.common.internal.cache.SharedPreferencesFileManager in project microsoft-authentication-library-common-for-android by AzureAD.
the class CacheUtils method clear.
public void clear(String sharedPrefName, boolean encrypted) {
final SharedPreferencesFileManager sharedPref = encrypted ? TestUtils.getEncryptedSharedPreferences(sharedPrefName) : TestUtils.getSharedPreferences(sharedPrefName);
sharedPref.clear();
}
use of com.microsoft.identity.common.internal.cache.SharedPreferencesFileManager in project microsoft-authentication-library-common-for-android by AzureAD.
the class CacheUtils method editAllTokenInCache.
/**
* This method will edit all the token specified by the predicate using the editor
* in the shared preference.
*
* @param sharedPrefName Name of the shared preference where token has been stored.
* @param predicate Generic functional interface representing function that returns true
* or false depending on token type.
* @param editor Functional interface to have any number of token editing method.
*/
public void editAllTokenInCache(@NonNull final String sharedPrefName, @NonNull final Predicate<String> predicate, @NonNull Function<String, Class<? extends Credential>> classFunction, @NonNull final Function<String, String> editor, final boolean encrypted) {
final SharedPreferencesFileManager sharedPref = encrypted ? TestUtils.getEncryptedSharedPreferences(sharedPrefName) : TestUtils.getSharedPreferences(sharedPrefName);
final Map<String, ?> cacheEntries = sharedPref.getAll();
// get all the key from the cache entry, verify and edit it.
for (final Map.Entry<String, ?> cacheEntry : cacheEntries.entrySet()) {
final String keyToEdit = cacheEntry.getKey();
if (predicate.test(keyToEdit)) {
final String cacheValue = (String) cacheEntries.get(keyToEdit);
final Class<? extends Credential> credClass = classFunction.apply(keyToEdit);
if (credClass == null) {
continue;
}
final Credential credential = CACHE_KEY_VALUE_DELEGATE.fromCacheValue(cacheValue, credClass);
if (credential == null) {
Logger.warn("CacheUtils:editAllTokenInCache", "Value did not deserialize");
continue;
}
credential.setSecret(editor.apply(credential.getSecret()));
sharedPref.putString(keyToEdit, CACHE_KEY_VALUE_DELEGATE.generateCacheValue(credential));
}
}
}
use of com.microsoft.identity.common.internal.cache.SharedPreferencesFileManager in project microsoft-authentication-library-common-for-android by AzureAD.
the class TestUtils method removeAccessTokenFromCache.
public static void removeAccessTokenFromCache(final String sharedPrefName) {
SharedPreferencesFileManager sharedPreferences = getSharedPreferences(sharedPrefName);
final Map<String, ?> cacheValues = sharedPreferences.getAll();
final String keyToRemove = getCacheKeyForAccessToken(cacheValues);
if (keyToRemove != null) {
sharedPreferences.remove(keyToRemove);
}
}
Aggregations