Skip to content

Commit e38196a

Browse files
author
AWS
committed
AWS SDK for Android 2.3.2
1 parent 23c5874 commit e38196a

File tree

60 files changed

+3504
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3504
-347
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# Change Log - AWS SDK for Android
2+
## [Release 2.3.2] (https://github.com/aws/aws-sdk-android/releases/tag/release_v2.3.2) (10/06/2016)
3+
4+
### Improvements
5+
- **Amazon Cognito Identity Provider**:
6+
- Support for Admin Create User feature.
7+
- Allow SDK to refresh tokens which are about to expire within a pre-set threshold.
28

39
## [Release 2.3.1](https://github.com/aws/aws-sdk-android/releases/tag/release_v2.3.1) (09/08/2016)
410

aws-android-sdk-apigateway-core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
<parent>
1313
<groupId>com.amazonaws</groupId>
1414
<artifactId>aws-android-sdk-pom</artifactId>
15-
<version>2.3.1</version>
15+
<version>2.3.2</version>
1616
</parent>
1717

1818
<dependencies>
1919
<dependency>
2020
<groupId>com.amazonaws</groupId>
2121
<artifactId>aws-android-sdk-core</artifactId>
2222
<optional>false</optional>
23-
<version>2.3.1</version>
23+
<version>2.3.2</version>
2424
</dependency>
2525
</dependencies>
2626

aws-android-sdk-apigateway-core/src/main/java/com/amazonaws/mobileconnectors/apigateway/ApiRequest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@ public class ApiRequest {
3535

3636
/**
3737
* Constructor.
38+
*
39+
* @param serviceName The name of the service to which this request is being
40+
* sent.
3841
*/
3942
public ApiRequest(String serviceName) {
4043
request = new DefaultRequest<ApiResponse>(serviceName);
4144
}
4245

46+
/**
47+
* Constructor.
48+
*/
49+
public ApiRequest() {
50+
request = new DefaultRequest<ApiResponse>("");
51+
}
52+
4353
/**
4454
* Sets all headers, clearing any existing ones.
4555
*

aws-android-sdk-autoscaling/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
<parent>
1313
<groupId>com.amazonaws</groupId>
1414
<artifactId>aws-android-sdk-pom</artifactId>
15-
<version>2.3.1</version>
15+
<version>2.3.2</version>
1616
</parent>
1717

1818
<dependencies>
1919
<dependency>
2020
<groupId>com.amazonaws</groupId>
2121
<artifactId>aws-android-sdk-core</artifactId>
2222
<optional>false</optional>
23-
<version>2.3.1</version>
23+
<version>2.3.2</version>
2424
</dependency>
2525
</dependencies>
2626

aws-android-sdk-cloudwatch/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
<parent>
1313
<groupId>com.amazonaws</groupId>
1414
<artifactId>aws-android-sdk-pom</artifactId>
15-
<version>2.3.1</version>
15+
<version>2.3.2</version>
1616
</parent>
1717

1818
<dependencies>
1919
<dependency>
2020
<groupId>com.amazonaws</groupId>
2121
<artifactId>aws-android-sdk-core</artifactId>
2222
<optional>false</optional>
23-
<version>2.3.1</version>
23+
<version>2.3.2</version>
2424
</dependency>
2525
</dependencies>
2626

aws-android-sdk-cognito/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<artifactId>aws-android-sdk-cognito</artifactId>
77
<packaging>jar</packaging>
88
<name>AWS SDK for Android - Amazon Cognito Sync</name>
9-
<version>2.3.1</version>
9+
<version>2.3.2</version>
1010
<description>The AWS Android SDK for Amazon Cognito Sync module holds the client classes that are used for communicating with Amazon Cognito Sync Service</description>
1111
<url>http://aws.amazon.com/sdkforandroid</url>
1212

1313
<parent>
1414
<groupId>com.amazonaws</groupId>
1515
<artifactId>aws-android-sdk-pom</artifactId>
16-
<version>2.3.1</version>
16+
<version>2.3.2</version>
1717
</parent>
1818

1919
<licenses>
@@ -29,7 +29,7 @@
2929
<groupId>com.amazonaws</groupId>
3030
<artifactId>aws-android-sdk-core</artifactId>
3131
<optional>false</optional>
32-
<version>2.3.1</version>
32+
<version>2.3.2</version>
3333
</dependency>
3434
<dependency>
3535
<groupId>com.google.android</groupId>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
fabric-identifier=com.amazonaws.aws-android-sdk-cognito
2-
fabric-version=2.3.1
2+
fabric-version=2.3.2
33
fabric-build-type=binary

aws-android-sdk-cognitoidentityprovider/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<artifactId>aws-android-sdk-cognitoidentityprovider</artifactId>
77
<packaging>jar</packaging>
88
<name>AWS SDK for Android - Amazon Cognito Identity Provider</name>
9-
<version>2.3.1</version>
9+
<version>2.3.2</version>
1010
<description>The AWS Android SDK for Amazon Cognito Identity Provider module holds the client classes that are used for communicating with Amazon Cognito Identity Provider Service</description>
1111
<url>http://aws.amazon.com/sdkforandroid</url>
1212

1313
<parent>
1414
<groupId>com.amazonaws</groupId>
1515
<artifactId>aws-android-sdk-pom</artifactId>
16-
<version>2.3.1</version>
16+
<version>2.3.2</version>
1717
</parent>
1818

1919
<licenses>
@@ -29,7 +29,7 @@
2929
<groupId>com.amazonaws</groupId>
3030
<artifactId>aws-android-sdk-core</artifactId>
3131
<optional>false</optional>
32-
<version>2.3.1</version>
32+
<version>2.3.2</version>
3333
</dependency>
3434
<dependency>
3535
<groupId>com.google.android</groupId>

aws-android-sdk-cognitoidentityprovider/src/main/java/com/amazonaws/mobileconnectors/cognitoidentityprovider/CognitoUser.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ChallengeContinuation;
2929
import com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ForgotPasswordContinuation;
3030
import com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation;
31+
import com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.NewPasswordContinuation;
3132
import com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException;
3233
import com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException;
3334
import com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException;
@@ -83,10 +84,10 @@
8384
import com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesResult;
8485
import com.amazonaws.services.cognitoidentityprovider.model.VerifyUserAttributeRequest;
8586
import com.amazonaws.services.cognitoidentityprovider.model.VerifyUserAttributeResult;
86-
8787
import com.amazonaws.util.Base64;
8888
import com.amazonaws.util.StringUtils;
8989

90+
import java.io.IOException;
9091
import java.math.BigInteger;
9192
import java.security.MessageDigest;
9293
import java.security.NoSuchAlgorithmException;
@@ -707,14 +708,14 @@ protected CognitoUserSession getCachedSession() {
707708
}
708709

709710
if (cipSession != null) {
710-
if (cipSession.isValid()) {
711+
if (cipSession.isValidForThreshold()) {
711712
return cipSession;
712713
}
713714
}
714715

715716
CognitoUserSession cachedTokens = readCachedTokens();
716717

717-
if (cachedTokens.isValid()) {
718+
if (cachedTokens.isValidForThreshold()) {
718719
cipSession = cachedTokens;
719720
return cipSession;
720721
}
@@ -724,12 +725,14 @@ protected CognitoUserSession getCachedSession() {
724725
cipSession = refreshSession(cachedTokens);
725726
cacheTokens(cipSession);
726727
return cipSession;
727-
} catch (Exception e) {
728+
} catch (NotAuthorizedException nae) {
728729
clearCachedTokens();
729-
throw new CognitoNotAuthorizedException("user is not authenticated");
730+
throw new CognitoNotAuthorizedException("User is not authenticated", nae);
731+
} catch (Exception e) {
732+
throw new CognitoInternalErrorException("Failed to authenticate user", e);
730733
}
731734
}
732-
throw new CognitoNotAuthorizedException("user is not authenticated");
735+
throw new CognitoNotAuthorizedException("User is not authenticated");
733736
}
734737

735738
/**
@@ -1583,9 +1586,18 @@ private void setUserSettingsInternal(CognitoUserSettings cognitoUserSettings,
15831586
*/
15841587
private void clearCachedTokens() {
15851588
try {
1586-
// Clear all cached tokens and last logged in user.
1589+
// Clear all cached tokens.
15871590
SharedPreferences csiCachedTokens = context.getSharedPreferences("CognitoIdentityProviderCache", 0);
1588-
csiCachedTokens.edit().clear().apply();
1591+
1592+
// Format "key" strings
1593+
String csiIdTokenKey = String.format("CognitoIdentityProvider.%s.%s.idToken", clientId, userId);
1594+
String csiAccessTokenKey = String.format("CognitoIdentityProvider.%s.%s.accessToken", clientId, userId);
1595+
String csiRefreshTokenKey = String.format("CognitoIdentityProvider.%s.%s.refreshToken", clientId, userId);
1596+
1597+
SharedPreferences.Editor cacheEdit = csiCachedTokens.edit();
1598+
cacheEdit.remove(csiIdTokenKey);
1599+
cacheEdit.remove(csiAccessTokenKey);
1600+
cacheEdit.remove(csiRefreshTokenKey).apply();
15891601
} catch (Exception e) {
15901602
// Logging exception, this is not a fatal error
15911603
Log.e(TAG, "Error while deleting from SharedPreferences");
@@ -1599,15 +1611,15 @@ private void clearCachedTokens() {
15991611
*/
16001612
private CognitoUserSession readCachedTokens() {
16011613
CognitoUserSession userSession = new CognitoUserSession(null, null, null);
1602-
1614+
16031615
try {
16041616
SharedPreferences csiCachedTokens = context.getSharedPreferences("CognitoIdentityProviderCache", 0);
16051617

16061618
// Format "key" strings
16071619
String csiIdTokenKey = "CognitoIdentityProvider." + clientId + "." + userId + ".idToken";
16081620
String csiAccessTokenKey = "CognitoIdentityProvider." + clientId + "." + userId + ".accessToken";
16091621
String csiRefreshTokenKey = "CognitoIdentityProvider." + clientId + "." + userId + ".refreshToken";
1610-
1622+
16111623
if (csiCachedTokens.contains(csiIdTokenKey)) {
16121624
CognitoIdToken csiCachedIdToken = new CognitoIdToken(csiCachedTokens.getString(csiIdTokenKey, null));
16131625
CognitoAccessToken csiCachedAccessToken = new CognitoAccessToken(csiCachedTokens.getString(csiAccessTokenKey, null));
@@ -1911,9 +1923,18 @@ public void run() {
19111923
};
19121924
} else if (CognitoServiceConstants.CHLG_TYPE_DEVICE_SRP_AUTH.equals(challengeName)) {
19131925
nextTask = deviceSrpAuthentication(challenge, callback, runInBackground);
1926+
} else if (CognitoServiceConstants.CHLG_TYPE_NEW_PASSWORD_REQUIRED.equals(challengeName)) {
1927+
final NewPasswordContinuation newPasswordContinuation =
1928+
new NewPasswordContinuation(cognitoUser, context, usernameInternal, clientId, secretHash, challenge, runInBackground, callback);
1929+
nextTask = new Runnable() {
1930+
@Override
1931+
public void run() {
1932+
callback.authenticationChallenge(newPasswordContinuation);
1933+
}
1934+
};
19141935
} else {
19151936
final ChallengeContinuation challengeContinuation =
1916-
new ChallengeContinuation(cognitoUser, context, clientId, challenge, runInBackground, callback);
1937+
new ChallengeContinuation(cognitoUser, context, usernameInternal, clientId, secretHash, challenge, runInBackground, callback);
19171938
nextTask = new Runnable() {
19181939
@Override
19191940
public void run() {

aws-android-sdk-cognitoidentityprovider/src/main/java/com/amazonaws/mobileconnectors/cognitoidentityprovider/CognitoUserSession.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
package com.amazonaws.mobileconnectors.cognitoidentityprovider;
1919

20+
import com.amazonaws.SDKGlobalConfiguration;
2021
import com.amazonaws.mobileconnectors.cognitoidentityprovider.tokens.CognitoAccessToken;
2122
import com.amazonaws.mobileconnectors.cognitoidentityprovider.tokens.CognitoIdToken;
2223
import com.amazonaws.mobileconnectors.cognitoidentityprovider.tokens.CognitoRefreshToken;
24+
import com.amazonaws.mobileconnectors.cognitoidentityprovider.util.CognitoIdentityProviderClientConfig;
2325

2426
import java.util.Date;
2527

@@ -97,4 +99,19 @@ public boolean isValid() {
9799
return false;
98100
}
99101
}
102+
103+
/**
104+
* Returns true if this session for the threshold set in {@link CognitoIdentityProviderClientConfig#refreshThreshold}.
105+
*
106+
* @return boolean to indicate if the session is valid for atleast {@link CognitoIdentityProviderClientConfig#refreshThreshold} seconds.
107+
*/
108+
public boolean isValidForThreshold() {
109+
try {
110+
long currentTime = System.currentTimeMillis() - SDKGlobalConfiguration.getGlobalTimeOffset() * 1000;
111+
long expiresInMilliSeconds = idToken.getExpiration().getTime() - currentTime;
112+
return (expiresInMilliSeconds > CognitoIdentityProviderClientConfig.getRefreshThreshold());
113+
} catch (Exception e) {
114+
return false;
115+
}
116+
}
100117
}

0 commit comments

Comments
 (0)