com.amazonaws.auth
Class CognitoCachingCredentialsProvider

java.lang.Object
  extended by com.amazonaws.auth.CognitoCredentialsProvider
      extended by com.amazonaws.auth.CognitoCachingCredentialsProvider
All Implemented Interfaces:
AWSCredentialsProvider

public class CognitoCachingCredentialsProvider
extends CognitoCredentialsProvider

This credentials provider is intended for Android applications. It offers the ability to persist the Cognito identity id in SharedPreferences. Furthermore, it caches session credentials so as to reduce the number of network requests. This is the provider to use with a custom identity provider, which should be an extension of AWSAbstractCognitoIdentityProvider. This will consume an identity provider, as well. If one is passed in to a constructor, then that one is the one that is consumed, but if not/a constructor that doesn't take an identity provider is used, then the Cognito identity provider is used by default.

 // initiate a credentials provider
 CognitoCachingCredentialsProvider provider = new CognitoCachingCredentialsProvider(
         context,
         "awsAccountId",
         "identityPoolId",
         "unauthRoleArn",
         "authRoleArn",
         Regions.US_EAST_1);
 
 // use the provider to instantiate an AWS client
 AmazonSNS snsClient = new AmazonSNSClient(provider);
 
 // If the user is authenticated through login with Amazon, you can set the map
 // of token to the provider
 Map<String, String> logins = new HashMap<String, String>();
 logins.put(""www.amazon.com", "login with Amazon token");
 provider.setLogins(logins);
 
 // Note: Please reuse the provider when possible.
 


Field Summary
 
Fields inherited from class com.amazonaws.auth.CognitoCredentialsProvider
DEFAULT_DURATION_SECONDS, DEFAULT_THRESHOLD_SECONDS
 
Constructor Summary
CognitoCachingCredentialsProvider(android.content.Context context, AWSCognitoIdentityProvider provider, java.lang.String unauthRoleArn, java.lang.String authRoleArn)
          Constructs a new CognitoCachingCredentialsProvider, which will use the specified Amazon Cognito identity pool and account id to make a request to the AWS Security Token Service (STS), as well as various other tasks to handle the lifecycle.
CognitoCachingCredentialsProvider(android.content.Context context, AWSCognitoIdentityProvider provider, java.lang.String unauthRoleArn, java.lang.String authRoleArn, AWSSecurityTokenService sts)
          Constructs a new CognitoCachingCredentialsProvider, which will use the specified Amazon Cognito identity pool and account id to make a request to the AWS Security Token Service (STS), as well as various other tasks to handle the lifecycle.
CognitoCachingCredentialsProvider(android.content.Context context, java.lang.String accountId, java.lang.String identityPoolId, java.lang.String unauthRoleArn, java.lang.String authRoleArn, AmazonCognitoIdentityClient cib, AWSSecurityTokenService sts)
          Constructs a new CognitoCachingCredentialsProvider, which will use the specified Amazon Cognito identity pool and account id to make a request to the AWS Security Token Service (STS), as well as various other tasks to handle the lifecycle.
CognitoCachingCredentialsProvider(android.content.Context context, java.lang.String accountId, java.lang.String identityPoolId, java.lang.String unauthRoleArn, java.lang.String authRoleArn, Regions region)
          Constructs a new CognitoCachingCredentialsProvider, which will use the specified Amazon Cognito identity pool and account id to make a request to the AWS Security Token Service (STS), as well as various other tasks to handle the lifecycle.
CognitoCachingCredentialsProvider(android.content.Context context, java.lang.String accountId, java.lang.String identityPoolId, java.lang.String unauthRoleArn, java.lang.String authRoleArn, Regions region, ClientConfiguration clientConfiguration)
          Constructs a new CognitoCachingCredentialsProvider, which will use the specified Amazon Cognito identity pool and account id to make a request to the AWS Security Token Service (STS), as well as various other tasks to handle the lifecycle.
 
Method Summary
 void clear()
          Clear all in-memory and saved state for the credentials provider.
 void clearCredentials()
          Clear credentials.
 java.lang.String getCachedIdentityId()
          Gets the cached identity id without making a network request.
 AWSSessionCredentials getCredentials()
          If the current session has expired/credentials are invalid, a new session is started, establishing the credentials.
 java.lang.String getIdentityId()
          Gets the Cognito identity id of the user.
 void setLogins(java.util.Map<java.lang.String,java.lang.String> logins)
          Set the logins map used to authenticated with Amazon Cognito.
 
Methods inherited from class com.amazonaws.auth.CognitoCredentialsProvider
getIdentityPoolId, getIdentityProvider, getLogins, getRefreshThreshold, getSessionCredentitalsExpiration, getSessionDuration, getToken, refresh, registerIdentityChangedListener, setRefreshThreshold, setSessionCredentialsExpiration, setSessionDuration, unregisterIdentityChangedListener, withLogins, withRefreshThreshold, withSessionDuration
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CognitoCachingCredentialsProvider

public CognitoCachingCredentialsProvider(android.content.Context context,
                                         java.lang.String accountId,
                                         java.lang.String identityPoolId,
                                         java.lang.String unauthRoleArn,
                                         java.lang.String authRoleArn,
                                         Regions region)
Constructs a new CognitoCachingCredentialsProvider, which will use the specified Amazon Cognito identity pool and account id to make a request to the AWS Security Token Service (STS), as well as various other tasks to handle the lifecycle. By default, this will utilize a Cognito identity provider.

Parameters:
context - The context to be used for the caching
accountId - The AWS accountId for the account with Amazon Cognito
identityPoolId - The Amazon Cogntio identity pool to use
unauthRoleArn - The ARN of the IAM Role that will be assumed when unauthenticated
authRoleArn - The ARN of the IAM Role that will be assumed when authenticated
region - The region to use when contacting Cognito Identity, and STS (if STS supports the provided regions, otherwise STS will be contacted using the US_EAST_1 region)

CognitoCachingCredentialsProvider

public CognitoCachingCredentialsProvider(android.content.Context context,
                                         java.lang.String accountId,
                                         java.lang.String identityPoolId,
                                         java.lang.String unauthRoleArn,
                                         java.lang.String authRoleArn,
                                         Regions region,
                                         ClientConfiguration clientConfiguration)
Constructs a new CognitoCachingCredentialsProvider, which will use the specified Amazon Cognito identity pool and account id to make a request to the AWS Security Token Service (STS), as well as various other tasks to handle the lifecycle. By default, this will utilize a Cognito identity provider.

Parameters:
context - The context to be used for the caching
accountId - The AWS accountId for the account with Amazon Cognito
identityPoolId - The Amazon Cogntio identity pool to use
unauthRoleArn - The ARN of the IAM Role that will be assumed when unauthenticated
authRoleArn - The ARN of the IAM Role that will be assumed when authenticated
clientConfiguration - Configuration to apply to service clients created
region - The region to use when contacting Cognito Identity, and STS (if STS supports the provided regions, otherwise STS will be contacted using the US_EAST_1 region)

CognitoCachingCredentialsProvider

public CognitoCachingCredentialsProvider(android.content.Context context,
                                         java.lang.String accountId,
                                         java.lang.String identityPoolId,
                                         java.lang.String unauthRoleArn,
                                         java.lang.String authRoleArn,
                                         AmazonCognitoIdentityClient cib,
                                         AWSSecurityTokenService sts)
Constructs a new CognitoCachingCredentialsProvider, which will use the specified Amazon Cognito identity pool and account id to make a request to the AWS Security Token Service (STS), as well as various other tasks to handle the lifecycle. By default, this will utilize a Cognito identity provider.

Parameters:
context - The context to be used for the caching
accountId - The AWS accountId for the account with Amazon Cognito
identityPoolId - The Amazon Cogntio identity pool to use
unauthRoleArn - The ARN of the IAM Role that will be assumed when unauthenticated
authRoleArn - The ARN of the IAM Role that will be assumed when authenticated
cibClient - Preconfigured CognitoIdentity client to make requests with
stsClient - Preconfigured STS client to make requests with

CognitoCachingCredentialsProvider

public CognitoCachingCredentialsProvider(android.content.Context context,
                                         AWSCognitoIdentityProvider provider,
                                         java.lang.String unauthRoleArn,
                                         java.lang.String authRoleArn,
                                         AWSSecurityTokenService sts)
Constructs a new CognitoCachingCredentialsProvider, which will use the specified Amazon Cognito identity pool and account id to make a request to the AWS Security Token Service (STS), as well as various other tasks to handle the lifecycle. This is to be used with a custom identity provider

Parameters:
context - The context to be used for the caching
provider - The identity provider to be consumed by the credentials provider
unauthRoleArn - The ARN of the IAM Role that will be assumed when unauthenticated
authRoleArn - The ARN of the IAM Role that will be assumed when authenticated
stsClient - Preconfigured STS client to make requests with

CognitoCachingCredentialsProvider

public CognitoCachingCredentialsProvider(android.content.Context context,
                                         AWSCognitoIdentityProvider provider,
                                         java.lang.String unauthRoleArn,
                                         java.lang.String authRoleArn)
Constructs a new CognitoCachingCredentialsProvider, which will use the specified Amazon Cognito identity pool and account id to make a request to the AWS Security Token Service (STS), as well as various other tasks to handle the lifecycle. This is to be used with a custom identity provider

Parameters:
context - The context to be used for the caching
provider - The identity provider to be consumed by the credentials provider
unauthRoleArn - The ARN of the IAM Role that will be assumed when unauthenticated
authRoleArn - The ARN of the IAM Role that will be assumed when authenticated
Method Detail

getIdentityId

public java.lang.String getIdentityId()
Gets the Cognito identity id of the user. The first time when this method is called, a network request will be made to retrieve a new identity id. After that it's saved in SharedPreferences. Please don't call it in the main thread.

Overrides:
getIdentityId in class CognitoCredentialsProvider
Returns:
identity id of the user

getCredentials

public AWSSessionCredentials getCredentials()
Description copied from class: CognitoCredentialsProvider
If the current session has expired/credentials are invalid, a new session is started, establishing the credentials. In either case, those credentials are returned

Specified by:
getCredentials in interface AWSCredentialsProvider
Overrides:
getCredentials in class CognitoCredentialsProvider
Returns:
AWSCredentials which the caller can use to authorize an AWS request.

setLogins

public void setLogins(java.util.Map<java.lang.String,java.lang.String> logins)
Description copied from class: CognitoCredentialsProvider
Set the logins map used to authenticated with Amazon Cognito. Note: You should manually call refresh on on the credentials provider after adding logins to the provider as your Identity Id may have changed.

Overrides:
setLogins in class CognitoCredentialsProvider
Parameters:
logins - The new logins map (providerName, providerToken) to use to communicate with Amazon Cognito

clear

public void clear()
Description copied from class: CognitoCredentialsProvider
Clear all in-memory and saved state for the credentials provider. Will destroy any saved Amazon Cognito Identity Id and associated AWS credentials.

Overrides:
clear in class CognitoCredentialsProvider

clearCredentials

public void clearCredentials()
Description copied from class: CognitoCredentialsProvider
Clear credentials. This will destroy all the saved AWS credentials but not the identity Id.

Overrides:
clearCredentials in class CognitoCredentialsProvider

getCachedIdentityId

public java.lang.String getCachedIdentityId()
Gets the cached identity id without making a network request.

Returns:
cached identity id, null if it doesn't exist


Copyright © 2010 Amazon Web Services, Inc. All Rights Reserved.