public class CognitoCredentialsProvider extends java.lang.Object implements AWSCredentialsProvider
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_DURATION_SECONDS
Default duration for started sessions
|
static int |
DEFAULT_THRESHOLD_SECONDS
Default threshold for refreshing session credentials
|
Constructor and Description |
---|
CognitoCredentialsProvider(AWSCognitoIdentityProvider provider,
com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient cibClient)
Constructs a new CognitoCredentialsProvider, which will set up a link to
the provider passed in using the enhanced authentication flow to get
short-lived credentials from Amazon Cognito, which can be retrieved from
getCredentials() |
CognitoCredentialsProvider(AWSCognitoIdentityProvider provider,
Regions region)
Constructs a new CognitoCredentialsProvider, which will set up a link to
the provider passed in using the enhanced authentication flow to get
short-lived credentials from Amazon Cognito, which can be retrieved from
getCredentials() |
CognitoCredentialsProvider(AWSCognitoIdentityProvider provider,
Regions region,
ClientConfiguration clientConfiguration)
Constructs a new CognitoCredentialsProvider, which will set up a link to
the provider passed in using the enhanced authentication flow to get
short-lived credentials from Amazon Cognito, which can be retrieved from
getCredentials() |
CognitoCredentialsProvider(AWSCognitoIdentityProvider provider,
java.lang.String unauthArn,
java.lang.String authArn)
Constructs a new CognitoCredentialsProvider, which will set up a link to
the provider passed in using the basic authentication flow to get get
short-lived credentials from STS, which can be retrieved from
getCredentials() |
CognitoCredentialsProvider(AWSCognitoIdentityProvider provider,
java.lang.String unauthArn,
java.lang.String authArn,
com.amazonaws.services.securitytoken.AWSSecurityTokenService stsClient)
Constructs a new CognitoCredentialsProvider, which will set up a link to
the provider passed in to use the basic authentication flow to get
short-lived credentials from STS, which can be retrieved from
getCredentials() |
CognitoCredentialsProvider(AWSConfiguration awsConfiguration)
Constructs a new
CognitoCredentialsProvider , which will use the
specified Amazon Cognito identity pool to make a request to Cognito,
using the enhanced flow, to get short lived session credentials, which
will then be returned by this class's getCredentials() method. |
CognitoCredentialsProvider(java.lang.String identityPoolId,
Regions region)
Constructs a new
CognitoCredentialsProvider , which will use the
specified Amazon Cognito identity pool to make a request to Cognito,
using the enhanced flow, to get short lived session credentials, which
will then be returned by this class's getCredentials() method. |
CognitoCredentialsProvider(java.lang.String identityPoolId,
Regions region,
ClientConfiguration clientConfiguration)
Constructs a new
CognitoCredentialsProvider , which will use the
specified Amazon Cognito identity pool to make a request to Cognito,
using the enhanced flow, to get short lived session credentials, which
will then be returned by this class's getCredentials() method. |
CognitoCredentialsProvider(java.lang.String accountId,
java.lang.String identityPoolId,
java.lang.String unauthRoleArn,
java.lang.String authRoleArn,
com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient cibClient,
com.amazonaws.services.securitytoken.AWSSecurityTokenService stsClient)
Constructs a new
CognitoCredentialsProvider , which will use the
specified Amazon Cognito identity pool to make a request to the AWS
Security Token Service (STS) to get short-lived session credentials,
which will then be returned by this class's getCredentials()
method. |
CognitoCredentialsProvider(java.lang.String accountId,
java.lang.String identityPoolId,
java.lang.String unauthRoleArn,
java.lang.String authRoleArn,
Regions region)
Constructs a new
CognitoCredentialsProvider , which will use the
specified Amazon Cognito identity pool to make a request, using the basic
authentication flow, to the AWS Security Token Service (STS) to request
short-lived session credentials, which will then be returned by this
class's getCredentials() method. |
CognitoCredentialsProvider(java.lang.String accountId,
java.lang.String identityPoolId,
java.lang.String unauthRoleArn,
java.lang.String authRoleArn,
Regions region,
ClientConfiguration clientConfiguration)
Constructs a new
CognitoCredentialsProvider , which will use the
specified Amazon Cognito identity pool to make a request, using the basic
authentication flow, to the AWS Security Token Service (STS) to request
short-lived session credentials, which will then be returned by this
class's getCredentials() method. |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear all in-memory and saved state for the credentials provider.
|
void |
clearCredentials()
Clear credentials.
|
AWSSessionCredentials |
getCredentials()
If the current session has expired/credentials are invalid, a new session
is started, establishing the credentials.
|
java.lang.String |
getCustomRoleArn()
Get the custom role arn associated with the credentials provider.
|
java.lang.String |
getIdentityId() |
java.lang.String |
getIdentityPoolId() |
AWSIdentityProvider |
getIdentityProvider() |
java.util.Map<java.lang.String,java.lang.String> |
getLogins()
Get the logins map used to authenticated with Amazon Cognito
|
int |
getRefreshThreshold()
Get the refresh threshold for the session credentials created by this
client in seconds.
|
java.util.Date |
getSessionCredentialsExpiration() |
java.util.Date |
getSessionCredentitalsExpiration()
Deprecated.
Use
getSessionCredentialsExpiration() instead. |
int |
getSessionDuration()
Get the duration of the session credentials created by this client in
seconds.
|
java.lang.String |
getToken() |
void |
refresh()
Forces this credentials provider to refresh its credentials.
|
void |
registerIdentityChangedListener(IdentityChangedListener listener)
Adds a new identity changed listener to process some event when the
identity has changed.
|
void |
setCustomRoleArn(java.lang.String customRoleArn)
Set the custom role arn that will be used to get credentials with Amazon
Cognito.
|
void |
setLogins(java.util.Map<java.lang.String,java.lang.String> logins)
Set the logins map used to authenticated with Amazon Cognito.
|
void |
setRefreshThreshold(int refreshThreshold)
Set the refresh threshold for the session credentials created by this
client in seconds.
|
void |
setSessionCredentialsExpiration(java.util.Date expiration) |
void |
setSessionDuration(int sessionDuration)
Set the duration of the session credentials created by this client in
seconds.
|
void |
unregisterIdentityChangedListener(IdentityChangedListener listener)
Removes an identity changed listener from being triggered when the
identity has changed.
|
AWSCredentialsProvider |
withLogins(java.util.Map<java.lang.String,java.lang.String> logins)
Set the logins map used to authenticated with Amazon Cognito.
|
CognitoCredentialsProvider |
withRefreshThreshold(int refreshThreshold)
Set the refresh threshold for the session credentials created by this
client in seconds.
|
CognitoCredentialsProvider |
withSessionDuration(int sessionDuration)
Set the duration of the session credentials created by this client in
seconds.
|
public static final int DEFAULT_DURATION_SECONDS
public static final int DEFAULT_THRESHOLD_SECONDS
public CognitoCredentialsProvider(java.lang.String accountId, java.lang.String identityPoolId, java.lang.String unauthRoleArn, java.lang.String authRoleArn, Regions region)
CognitoCredentialsProvider
, which will use the
specified Amazon Cognito identity pool to make a request, using the basic
authentication flow, to the AWS Security Token Service (STS) to request
short-lived session credentials, which will then be returned by this
class's getCredentials()
method.accountId
- The AWS accountId for the account with Amazon CognitoidentityPoolId
- The Amazon Cogntio identity pool to useunauthRoleArn
- The ARN of the IAM Role that will be assumed when
unauthenticatedauthRoleArn
- The ARN of the IAM Role that will be assumed when
authenticatedregion
- The region to use when contacting Cognito Identitypublic CognitoCredentialsProvider(java.lang.String accountId, java.lang.String identityPoolId, java.lang.String unauthRoleArn, java.lang.String authRoleArn, Regions region, ClientConfiguration clientConfiguration)
CognitoCredentialsProvider
, which will use the
specified Amazon Cognito identity pool to make a request, using the basic
authentication flow, to the AWS Security Token Service (STS) to request
short-lived session credentials, which will then be returned by this
class's getCredentials()
method.
This version of the constructor allows you to specify a client configuration for the Amazon Cognito and STS clients.
accountId
- The AWS accountId for the account with Amazon CognitoidentityPoolId
- The Amazon Cognito identity pool to useunauthRoleArn
- The ARN of the IAM Role that will be assumed when
unauthenticatedauthRoleArn
- The ARN of the IAM Role that will be assumed when
authenticatedregion
- The region to use when contacting Cognito IdentityclientConfiguration
- Configuration to apply to service clients
createdpublic CognitoCredentialsProvider(AWSConfiguration awsConfiguration)
CognitoCredentialsProvider
, which will use the
specified Amazon Cognito identity pool to make a request to Cognito,
using the enhanced flow, to get short lived session credentials, which
will then be returned by this class's getCredentials()
method.
Example json file:
{
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "us-east-1:example-pool-id1234",
"Region": "us-east-1"
}
}
}
}awsConfiguration
- The configuration holding you identity pool id
and the region to use when contacting
Cognito Identitypublic CognitoCredentialsProvider(java.lang.String identityPoolId, Regions region)
CognitoCredentialsProvider
, which will use the
specified Amazon Cognito identity pool to make a request to Cognito,
using the enhanced flow, to get short lived session credentials, which
will then be returned by this class's getCredentials()
method.identityPoolId
- The Amazon Cognito identity pool to useregion
- The region to use when contacting Cognito Identitypublic CognitoCredentialsProvider(java.lang.String identityPoolId, Regions region, ClientConfiguration clientConfiguration)
CognitoCredentialsProvider
, which will use the
specified Amazon Cognito identity pool to make a request to Cognito,
using the enhanced flow, to get short lived session credentials, which
will then be returned by this class's getCredentials()
method.
This version of the constructor allows you to specify a client configuration for the Amazon Cognito client.
identityPoolId
- The Amazon Cognito identity pool to useregion
- The region to use when contacting Cognito IdentityclientConfiguration
- Configuration to apply to service clients
createdpublic CognitoCredentialsProvider(java.lang.String accountId, java.lang.String identityPoolId, java.lang.String unauthRoleArn, java.lang.String authRoleArn, com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient cibClient, com.amazonaws.services.securitytoken.AWSSecurityTokenService stsClient)
CognitoCredentialsProvider
, which will use the
specified Amazon Cognito identity pool to make a request to the AWS
Security Token Service (STS) to get short-lived session credentials,
which will then be returned by this class's getCredentials()
method.
This version of the constructor allows you to specify the Amazon Cognito and STS client to use.
Set the roles and stsClient to null to use the enhanced authentication flow, not contacting STS. Otherwise the basic flow will be used.
accountId
- The AWS accountId for the account with Amazon CognitoidentityPoolId
- The Amazon Cogntio identity pool to useunauthRoleArn
- The ARN of the IAM Role that will be assumed when
unauthenticatedauthRoleArn
- The ARN of the IAM Role that will be assumed when
authenticatedcibClient
- Preconfigured CognitoIdentity client to make requests
withstsClient
- Preconfigured STS client to make requests withpublic CognitoCredentialsProvider(AWSCognitoIdentityProvider provider, java.lang.String unauthArn, java.lang.String authArn)
getCredentials()
This version of the constructor allows you to specify your own Identity Provider class.
provider
- a reference to the provider in question, including what's
needed to interact with it to later connect with STSunauthArn
- the unauthArn, for use with the STS callauthArn
- the authArn, for use with the STS callpublic CognitoCredentialsProvider(AWSCognitoIdentityProvider provider, java.lang.String unauthArn, java.lang.String authArn, com.amazonaws.services.securitytoken.AWSSecurityTokenService stsClient)
getCredentials()
This version of the constructor allows you to specify your own Identity Provider class, and the STS client to use.
provider
- a reference to the provider in question, including what's
needed to interact with it to later connect with STSunauthArn
- the unauthArn, for use with the STS callauthArn
- the authArn, for use with the STS callstsClient
- the sts endpoint to get session credentials frompublic CognitoCredentialsProvider(AWSCognitoIdentityProvider provider, Regions region)
getCredentials()
This version of the constructor allows you to specify your own Identity Provider class.
provider
- a reference to the provider in question, including what's
needed to interact with it to later connect with Amazon
Cognitoregion
- The region to use when contacting Cognitopublic CognitoCredentialsProvider(AWSCognitoIdentityProvider provider, Regions region, ClientConfiguration clientConfiguration)
getCredentials()
This version of the constructor allows you to specify your own Identity Provider class and the configuration for the Amazon Cognito client.
provider
- a reference to the provider in question, including what's
needed to interact with it to later connect with Amazon
CognitoclientConfiguration
- Configuration to apply to service clients
createdregion
- The region to use when contacting Cognito Identitypublic CognitoCredentialsProvider(AWSCognitoIdentityProvider provider, com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient cibClient)
getCredentials()
This version of the constructor allows you to specify your own Identity Provider class and the Amazon Cognito client.
provider
- a reference to the provider in question, including what's
needed to interact with it to later connect with Amazon
CognitocibClient
- Preconfigured CognitoIdentity client to make requests
withpublic java.lang.String getIdentityId()
public java.lang.String getToken()
public AWSIdentityProvider getIdentityProvider()
public void setSessionCredentialsExpiration(java.util.Date expiration)
public java.util.Date getSessionCredentialsExpiration()
@Deprecated public java.util.Date getSessionCredentitalsExpiration()
getSessionCredentialsExpiration()
instead.public java.lang.String getIdentityPoolId()
public AWSSessionCredentials getCredentials()
getCredentials
in interface AWSCredentialsProvider
public void setSessionDuration(int sessionDuration)
sessionDuration
- The new duration for session credentials created
by this providerAssumeRoleWithWebIdentityRequest
public CognitoCredentialsProvider withSessionDuration(int sessionDuration)
sessionDuration
- The new duration for session credentials created
by this providerAssumeRoleWithWebIdentityRequest
public int getSessionDuration()
AssumeRoleWithWebIdentityRequest
public void setRefreshThreshold(int refreshThreshold)
refreshThreshold
- The new refresh threshold for session credentials
created by this providerAssumeRoleWithWebIdentityRequest
public CognitoCredentialsProvider withRefreshThreshold(int refreshThreshold)
refreshThreshold
- The new refresh threshold for session credentials
created by this providerAssumeRoleWithWebIdentityRequest
public int getRefreshThreshold()
AssumeRoleWithWebIdentityRequest
public void setLogins(java.util.Map<java.lang.String,java.lang.String> logins)
logins
- The new logins map (providerName, providerToken) to use to
communicate with Amazon Cognitopublic java.lang.String getCustomRoleArn()
public void setCustomRoleArn(java.lang.String customRoleArn)
customRoleArn
- The role arn to be used to get the credentials.public AWSCredentialsProvider withLogins(java.util.Map<java.lang.String,java.lang.String> logins)
logins
- The new logins map (providerName, providerToken) to use to
communicate with Amazon CognitoAssumeRoleWithWebIdentityRequest
public java.util.Map<java.lang.String,java.lang.String> getLogins()
public void refresh()
AWSCredentialsProvider
refresh
in interface AWSCredentialsProvider
public void clear()
public void clearCredentials()
public void registerIdentityChangedListener(IdentityChangedListener listener)
listener
- the listener to be triggered on id changepublic void unregisterIdentityChangedListener(IdentityChangedListener listener)
listener
- the listener to be removedCopyright © 2018 Amazon Web Services, Inc. All Rights Reserved.