use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.
the class CognitoDeviceHelper method clearCachedDevice.
/**
* Clears cached device details for this user.
*
* @param username REQUIRED: The current user.
* @param userPoolId REQUIRED: Client ID of the device.
* @param context REQUIRED: App context, needed to access device datastore.
*/
public static void clearCachedDevice(String username, String userPoolId, Context context) {
try {
final AWSKeyValueStore awsKeyValueStore = getAWSKeyValueStore(context, username, userPoolId);
awsKeyValueStore.clear();
} catch (final Exception e) {
LOGGER.error("Error accessing SharedPreferences", e);
}
}
use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method testCacheWithEncryptionKeyNotRetrieved.
@Test
public void testCacheWithEncryptionKeyNotRetrieved() throws Exception {
SharedPreferences sharedPreferencesForEncryptionMaterials = appContext.getSharedPreferences(SHARED_PREFERENCES_NAME + ".encryptionKey", Context.MODE_PRIVATE);
// Test with a user cached in shared preferences
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + ".LastAuthUser", TEST_USER_NAME);
CognitoUser user = testPool.getCurrentUser();
assertNotNull(user);
String username = user.getUserId();
assertEquals(TEST_USER_NAME, username);
deleteAllEncryptionKeys();
CognitoUserPool testPoolAfterKeyDeleted = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET);
AWSKeyValueStore store = getAWSKeyValueStorageUtility(testPoolAfterKeyDeleted);
assertNull(store.get("CognitoIdentityProvider." + TEST_CLIENT_ID + ".LastAuthUser"));
}
use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method newUserPoolWithPinpointWithCachedApp.
@Test
public void newUserPoolWithPinpointWithCachedApp() {
// Test new user pool creation with PP app id.
// Test shared Pinpoint context
awsKeyValueStorageUtility = new AWSKeyValueStore(ApplicationProvider.getApplicationContext(), TEST_PP_APP_ID_1 + PP_PREFERENCES_AND_FILE_MANAGER_SUFFIX, true);
awsKeyValueStorageUtility.put("UNIQUE_ID_KEY", TEST_PP_ENDPOINT_1);
CognitoUserPool pool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, new ClientConfiguration(), TEST_AWS_REGION_1, TEST_PP_APP_ID_1);
assertNotNull(pool);
assertNotNull(pool.getUserPoolId());
assertEquals(TEST_USER_POOL, pool.getUserPoolId());
assertNotNull(pool.getClientId());
assertEquals(TEST_CLIENT_ID, pool.getClientId());
}
use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.
the class CognitoDeviceHelper method cacheDeviceKey.
/**
* This method caches the device key. Device key is assigned by the Amazon Cognito service and is
* used as a device identifier.
*
* @param username REQUIRED: The current user.
* @param userPoolId REQUIRED: Client ID of the device.
* @param deviceKey REQUIRED: Cognito assigned device key.
* @param context REQUIRED: App context, needed to access device datastore.
*/
public static void cacheDeviceKey(String username, String userPoolId, String deviceKey, Context context) {
try {
final AWSKeyValueStore awsKeyValueStore = getAWSKeyValueStore(context, username, userPoolId);
awsKeyValueStore.put(COGNITO_DEVICE_KEY, deviceKey);
} catch (final Exception e) {
LOGGER.error("Error accessing SharedPreferences", e);
}
}
use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.
the class CognitoDeviceHelper method getAWSKeyValueStore.
/**
* Retrieve an instance of AWSKeyValueStore for the sharedPreferencesName.
*
* @param context application context
* @param username username of current authenticated user
* @param userPoolId identifier of the cognito userpool
* @return the instance of utility that provides access to SharedPreferences.
*/
private static AWSKeyValueStore getAWSKeyValueStore(Context context, String username, String userPoolId) {
synchronized (LOCK) {
try {
final String sharedPreferencesName = getDeviceDetailsCacheForUser(username, userPoolId);
if (awsKeyValueStoreMap.containsKey(sharedPreferencesName)) {
return awsKeyValueStoreMap.get(sharedPreferencesName);
} else {
AWSKeyValueStore awsKeyValueStore = new AWSKeyValueStore(context, sharedPreferencesName, isPersistenceEnabled);
awsKeyValueStoreMap.put(sharedPreferencesName, awsKeyValueStore);
return awsKeyValueStore;
}
} catch (Exception ex) {
LOGGER.error("Error in retrieving the persistent store.", ex);
return null;
}
}
}
Aggregations