Search in sources :

Example 6 with CognitoCachingCredentialsProvider

use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.

the class CognitoCachingCredentialsProviderIntegrationTest method testEncryptionKeyLossInAWSCredentials_WhileAppIsInClosed.

@Test
public void testEncryptionKeyLossInAWSCredentials_WhileAppIsInClosed() throws Exception {
    // Makes a network call to get credentials and saves it to local persistence store
    AWSSessionCredentials awsSessionCredentialsFromNetwork = credentialsProvider.getCredentials();
    verifyAWSCredentials(awsSessionCredentialsFromNetwork);
    AWSSessionCredentials awsSessionCredentialsFromCache = credentialsProvider.getCredentials();
    verifyAWSCredentials(awsSessionCredentialsFromCache);
    assertTrue(compareAWSSessionCredentials(awsSessionCredentialsFromNetwork, awsSessionCredentialsFromCache));
    deleteAllEncryptionKeys();
    CognitoCachingCredentialsProvider newCredentialsProvider = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("identity_pool_id"), Regions.US_EAST_1);
    awsSessionCredentialsFromNetwork = newCredentialsProvider.getCredentials();
    verifyAWSCredentials(awsSessionCredentialsFromNetwork);
    awsSessionCredentialsFromCache = newCredentialsProvider.getCredentials();
    verifyAWSCredentials(awsSessionCredentialsFromCache);
    assertTrue(compareAWSSessionCredentials(awsSessionCredentialsFromNetwork, awsSessionCredentialsFromCache));
}
Also used : AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) CognitoCachingCredentialsProvider(com.amazonaws.auth.CognitoCachingCredentialsProvider) Test(org.junit.Test)

Example 7 with CognitoCachingCredentialsProvider

use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.

the class AWSKeyValueStoreMigrationIntegrationTest method verifyCredentialsProviderClear.

private void verifyCredentialsProviderClear() {
    for (int iterator = 0; iterator < credentialsProviders.size(); iterator++) {
        final CognitoCachingCredentialsProvider cccp = credentialsProviders.get(iterator);
        cccp.clearCredentials();
        cccp.clear();
        assertNull(cccp.getCachedIdentityId());
        assertNotNull(cccp.getIdentityId());
        assertNotNull(cccp.getCachedIdentityId());
    }
}
Also used : CognitoCachingCredentialsProvider(com.amazonaws.auth.CognitoCachingCredentialsProvider)

Example 8 with CognitoCachingCredentialsProvider

use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.

the class AWSKeyValueStoreMigrationIntegrationTest method testCachedAWSCredentialsMigrationFromNoEncryption.

@Test
public void testCachedAWSCredentialsMigrationFromNoEncryption() throws Exception {
    Log.d(TAG, "SharedPreferences contents before migration for " + SHARED_PREFERENCES_NAME + "=> " + sharedPreferencesForAuth.getAll().toString());
    assertEquals("accessKey", sharedPreferencesForAuth.getString(identityPoolId + ".accessKey", null));
    assertEquals("secretKey", sharedPreferencesForAuth.getString(identityPoolId + ".secretKey", null));
    assertEquals("sessionToken", sharedPreferencesForAuth.getString(identityPoolId + ".sessionToken", null));
    assertEquals("identityId", sharedPreferencesForAuth.getString(identityPoolId + ".identityId", null));
    assertEquals(time, sharedPreferencesForAuth.getLong(identityPoolId + ".expirationDate", 0));
    assertEquals(stringSet, sharedPreferencesForAuth.getStringSet("stringSet", null));
    credentialsProvider = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("identity_pool_id"), Regions.US_EAST_1);
    credentialsProviders.add(credentialsProvider);
    AWSKeyValueStore awsKeyValueStore = new AWSKeyValueStore(ApplicationProvider.getApplicationContext(), SHARED_PREFERENCES_NAME, true);
    assertNotNull(awsKeyValueStore);
    Log.d(TAG, "SharedPreferences contents after migration for " + SHARED_PREFERENCES_NAME + " => " + sharedPreferencesForAuth.getAll().toString());
    assertEquals("accessKey", awsKeyValueStore.get(identityPoolId + ".accessKey"));
    assertEquals("secretKey", awsKeyValueStore.get(identityPoolId + ".secretKey"));
    assertEquals("sessionToken", awsKeyValueStore.get(identityPoolId + ".sessionToken"));
    assertEquals("identityId", awsKeyValueStore.get(identityPoolId + ".identityId"));
    assertEquals(String.valueOf(time), awsKeyValueStore.get(identityPoolId + ".expirationDate"));
    assertNotNull(awsKeyValueStore.get("stringSet"));
    verifyStringSet();
    credentialsProvider.clearCredentials();
    credentialsProvider.clear();
    assertNull(credentialsProvider.getCachedIdentityId());
    assertNotNull(credentialsProvider.getCredentials());
    assertNotNull(credentialsProvider.getIdentityId());
    assertNotNull(credentialsProvider.getCachedIdentityId());
    assertEquals(credentialsProvider.getIdentityId(), credentialsProvider.getCachedIdentityId());
    verifySharedPreferencesContents();
    verifyCredentialsProviderClear();
}
Also used : CognitoCachingCredentialsProvider(com.amazonaws.auth.CognitoCachingCredentialsProvider) Test(org.junit.Test)

Example 9 with CognitoCachingCredentialsProvider

use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.

the class AWSKeyValueStoreNoCachingIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    sharedPreferencesForAuth.edit().clear().commit();
    AWSKeyValueStore.cacheFactory.clear();
    credentialsProviders = new ArrayList<CognitoCachingCredentialsProvider>();
    credentialsProvider = new CognitoCachingCredentialsProvider(ApplicationProvider.getApplicationContext(), getPackageConfigure().getString("identity_pool_id"), Regions.US_EAST_1);
    credentialsProvider.setPersistenceEnabled(false);
    credentialsProviders.add(credentialsProvider);
}
Also used : CognitoCachingCredentialsProvider(com.amazonaws.auth.CognitoCachingCredentialsProvider) Before(org.junit.Before)

Example 10 with CognitoCachingCredentialsProvider

use of com.amazonaws.auth.CognitoCachingCredentialsProvider in project aws-sdk-android by aws-amplify.

the class MqttManagerIntegrationTest method beforeSuite.

@BeforeClass
public static void beforeSuite() throws JSONException {
    Context appContext = ApplicationProvider.getApplicationContext();
    keyStorePath = appContext.getFilesDir().toString() + "/";
    System.out.println(keyStorePath);
    credentialsProvider = new CognitoCachingCredentialsProvider(appContext, getPackageConfigure("iot").getString(ConfigKey.IDENTITY_POOL_ID.toString()), Regions.US_EAST_1);
    iotClient = new IotClient(credentialsProvider);
    iotClient.cleanupPolicy(IOT_POLICY_NAME);
    keysAndCertificateInfo = iotClient.createAndAttachPolicy(IOT_POLICY_NAME, new JSONObject().put("Version", "2012-10-17").put("Statement", new JSONArray(Collections.singletonList(new JSONObject().put("Action", "iot:*").put("Resource", "*").put("Effect", "Allow")))).toString());
    customAuthorization = CustomAuthorization.from(getPackageConfigure("iot"), keysAndCertificateInfo);
    iotClient.cleanupAuthorizer(customAuthorization.getCustomAuthorizerName());
    iotClient.createAuthorizer(customAuthorization.getCustomAuthorizerName(), customAuthorization.getCustomAuthorizerLamdbaArn(), customAuthorization.getTokenKeyName(), keysAndCertificateInfo.getPublicKey());
}
Also used : Context(android.content.Context) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) CognitoCachingCredentialsProvider(com.amazonaws.auth.CognitoCachingCredentialsProvider) BeforeClass(org.junit.BeforeClass)

Aggregations

CognitoCachingCredentialsProvider (com.amazonaws.auth.CognitoCachingCredentialsProvider)23 Test (org.junit.Test)10 JSONObject (org.json.JSONObject)5 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)4 Regions (com.amazonaws.regions.Regions)3 Before (org.junit.Before)3 PinpointConfiguration (com.amazonaws.mobileconnectors.pinpoint.PinpointConfiguration)2 PinpointManager (com.amazonaws.mobileconnectors.pinpoint.PinpointManager)2 JSONException (org.json.JSONException)2 Context (android.content.Context)1 CustomTabsCallback (androidx.browser.customtabs.CustomTabsCallback)1 AmazonClientException (com.amazonaws.AmazonClientException)1 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AWSAbstractCognitoIdentityProvider (com.amazonaws.auth.AWSAbstractCognitoIdentityProvider)1 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)1 IdentityManager (com.amazonaws.mobile.auth.core.IdentityManager)1 SignInStateChangeListener (com.amazonaws.mobile.auth.core.SignInStateChangeListener)1 InternalCallback (com.amazonaws.mobile.client.internal.InternalCallback)1 ReturningRunnable (com.amazonaws.mobile.client.internal.ReturningRunnable)1 OAuth2Client (com.amazonaws.mobile.client.internal.oauth2.OAuth2Client)1