Skip to content

Commit 13e21fd

Browse files
authored
Add ASF package (#2756)
1 parent 82ed2d5 commit 13e21fd

File tree

18 files changed

+809
-5
lines changed

18 files changed

+809
-5
lines changed

CircleciScripts/bump_sdk_version.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ def bump_pomxml(filename, newsdkversion):
1919
parentversion.text = newsdkversion
2020
for dependency in root.findall("./dependencies/dependency[{0}]".format(groupIdFilter), namespaces):
2121
newversion = newsdkversion
22-
if dependency.find("artifactId",namespaces).text == "aws-android-sdk-cognitoidentityprovider-asf":
23-
continue
2422
dependencyVersion = dependency.find("version", namespaces)
2523
if dependencyVersion is not None:
2624
dependencyVersion.text = newversion

CircleciScripts/check_sdk_on_maven.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
'aws-android-sdk-kinesis',
4444
'aws-android-sdk-pinpoint',
4545
'aws-android-sdk-machinelearning',
46-
'aws-android-sdk-sqs'
46+
'aws-android-sdk-sqs',
47+
'aws-android-sdk-cognitoidentityprovider-asf'
4748
}
4849

4950
def IsAllPackageAvailableOnMaven(version):

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Above, SERVICE might be `s3`, `ddb`, `pinpoint`, etc. A full list is provided be
3737
* cloudwatch
3838
* cognitoauth
3939
* cognitoidentityprovider
40+
* cognitoidentityprovider-asf
4041
* comprehend
4142
* connect
4243
* connectparticipant

aws-android-sdk-cognitoauth/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies {
2323
api (project(':aws-android-sdk-core')) {
2424
exclude group: 'com.google.android', module: 'android'
2525
}
26+
api project(':aws-android-sdk-cognitoidentityprovider-asf')
2627
implementation 'androidx.browser:browser:1.3.0'
27-
implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider-asf:1.0.0'
2828
}
2929

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apply from: rootProject.file('publishing.gradle')
2+
apply plugin: 'com.android.library'
3+
4+
android {
5+
compileSdkVersion 30
6+
7+
defaultConfig {
8+
minSdkVersion 9
9+
targetSdkVersion 30
10+
}
11+
12+
compileOptions {
13+
sourceCompatibility 1.8
14+
targetCompatibility 1.8
15+
}
16+
}
17+
18+
dependencies {
19+
api project(':aws-android-sdk-core')
20+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
POM_ARTIFACT_ID=aws-android-sdk-cognitoidentityprovider-asf
2+
POM_DESCRIPTION=The AWS Android SDK for Amazon Cognito Identity Provider ASF module holds the client classes that are used for communicating with Amazon Cognito Identity Provider Advanced Security Features
3+
POM_NAME=AWS SDK for Android - Amazon Cognito Identity Provider ASF
4+
POM_PACKAGING=aar
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.amazonaws.cognito.clientcontext" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2017-2022 Amazon.com,
3+
* Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Amazon Software License (the "License").
6+
* You may not use this file except in compliance with the
7+
* License. A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/asl/
10+
*
11+
* or in the "license" file accompanying this file. This file is
12+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
* CONDITIONS OF ANY KIND, express or implied. See the License
14+
* for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.amazonaws.cognito.clientcontext.data;
19+
20+
import java.nio.charset.Charset;
21+
22+
/**
23+
* It provides constants that defines configuration for the library. These
24+
* constants are used in multiple classes within the library.
25+
*/
26+
public class ConfigurationConstant {
27+
28+
/**
29+
* Default CHARSET used while generating byte array.
30+
*/
31+
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* Copyright 2017-2022 Amazon.com,
3+
* Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Amazon Software License (the "License").
6+
* You may not use this file except in compliance with the
7+
* License. A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/asl/
10+
*
11+
* or in the "license" file accompanying this file. This file is
12+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
* CONDITIONS OF ANY KIND, express or implied. See the License
14+
* for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.amazonaws.cognito.clientcontext.data;
19+
20+
import java.util.Map;
21+
22+
import org.json.JSONException;
23+
import org.json.JSONObject;
24+
25+
import com.amazonaws.cognito.clientcontext.datacollection.ContextDataAggregator;
26+
import com.amazonaws.cognito.clientcontext.util.SignatureGenerator;
27+
28+
import android.content.Context;
29+
import android.util.Base64;
30+
import android.util.Log;
31+
32+
/**
33+
* It provides the user context data that is sent to the server.
34+
*/
35+
public class UserContextDataProvider {
36+
37+
private static final String TAG = UserContextDataProvider.class.getSimpleName();
38+
public static final String VERSION = "ANDROID20171114";
39+
40+
private ContextDataAggregator aggregator;
41+
private SignatureGenerator signatureGenerator;
42+
43+
/**
44+
* Private class to store an instance. This is used to ensure a singleton
45+
* instance of the class.
46+
*/
47+
private static class InstanceHolder {
48+
private static final UserContextDataProvider INSTANCE = new UserContextDataProvider();
49+
}
50+
51+
private UserContextDataProvider() {
52+
this(ContextDataAggregator.getInstance(), new SignatureGenerator());
53+
}
54+
55+
/**
56+
* Protected constructor to instantiate a class object for unit testing.
57+
*/
58+
protected UserContextDataProvider(ContextDataAggregator aggregator, SignatureGenerator signatureGenerator) {
59+
this.aggregator = aggregator;
60+
this.signatureGenerator = signatureGenerator;
61+
}
62+
63+
/**
64+
* @return instance of the class
65+
*/
66+
public static UserContextDataProvider getInstance() {
67+
return InstanceHolder.INSTANCE;
68+
}
69+
70+
/**
71+
* It gets aggregated user context data, adds signature to it and provides
72+
* it in Base64 encoded form. Final data is JSON object with 'signature' and
73+
* 'payload'. Payload is a JSON object that contains 'username',
74+
* 'userPoolId', 'timestamp' and 'contextData'.
75+
*
76+
* @param context
77+
* android application context
78+
* @param username
79+
* username for the user
80+
* @param userPoolId
81+
* cognito userpoolId for the application
82+
* @param signatureSecret
83+
* secret key used while generating signature. For now, this
84+
* would be application clientId.
85+
* @return base64 encoded userContextData.
86+
*/
87+
public String getEncodedContextData(Context context, String username, String userPoolId, String signatureSecret) {
88+
JSONObject jsonResponse = new JSONObject();
89+
90+
try {
91+
final Map<String, String> contextData = aggregator.getAggregatedData(context);
92+
JSONObject payload = getJsonPayload(contextData, username, userPoolId);
93+
String payloadString = payload.toString();
94+
95+
String signature = signatureGenerator.getSignature(payloadString, signatureSecret, VERSION);
96+
jsonResponse = getJsonResponse(payloadString, signature);
97+
return getEncodedResponse(jsonResponse);
98+
} catch (Exception e) {
99+
Log.e(TAG, "Exception in creating JSON from context data");
100+
return null;
101+
}
102+
}
103+
104+
private JSONObject getJsonPayload(Map<String, String> contextData, String username, String userPoolId)
105+
throws JSONException {
106+
JSONObject payload = new JSONObject();
107+
payload.put(ContextDataJsonKeys.CONTEXT_DATA, new JSONObject(contextData));
108+
payload.put(ContextDataJsonKeys.USERNAME, username);
109+
payload.put(ContextDataJsonKeys.USER_POOL_ID, userPoolId);
110+
payload.put(ContextDataJsonKeys.TIMESTAMP_MILLI_SEC, getTimestamp());
111+
return payload;
112+
}
113+
114+
/**
115+
* Protected to allow overriding in unit test.
116+
*/
117+
protected String getTimestamp() {
118+
return String.valueOf(System.currentTimeMillis());
119+
}
120+
121+
private JSONObject getJsonResponse(String payload, String signature) throws JSONException {
122+
JSONObject jsonResponse = new JSONObject();
123+
jsonResponse.put(ContextDataJsonKeys.DATA_PAYLOAD, payload);
124+
jsonResponse.put(ContextDataJsonKeys.SIGNATURE, signature);
125+
jsonResponse.put(ContextDataJsonKeys.VERSION, UserContextDataProvider.VERSION);
126+
return jsonResponse;
127+
}
128+
129+
/**
130+
* Protected to allow overriding in unit test. Base64 is part of AndroidSdk
131+
* which cannot be directly invoked in unit test.
132+
*/
133+
protected String getEncodedResponse(JSONObject jsonResponse) {
134+
byte[] responseBytes = jsonResponse.toString().getBytes(ConfigurationConstant.DEFAULT_CHARSET);
135+
return Base64.encodeToString(responseBytes, Base64.DEFAULT);
136+
}
137+
138+
/**
139+
* Class defines constant keys that are used in JSON response object.
140+
*/
141+
private class ContextDataJsonKeys {
142+
private static final String CONTEXT_DATA = "contextData";
143+
private static final String USERNAME = "username";
144+
private static final String USER_POOL_ID = "userPoolId";
145+
private static final String TIMESTAMP_MILLI_SEC = "timestamp";
146+
private static final String DATA_PAYLOAD = "payload";
147+
private static final String VERSION = "version";
148+
private static final String SIGNATURE = "signature";
149+
}
150+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2017-2022 Amazon.com,
3+
* Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Amazon Software License (the "License").
6+
* You may not use this file except in compliance with the
7+
* License. A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/asl/
10+
*
11+
* or in the "license" file accompanying this file. This file is
12+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
* CONDITIONS OF ANY KIND, express or implied. See the License
14+
* for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.amazonaws.cognito.clientcontext.datacollection;
19+
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
23+
import android.content.Context;
24+
import android.content.pm.ApplicationInfo;
25+
import android.content.pm.PackageInfo;
26+
import android.content.pm.PackageManager;
27+
import android.content.pm.PackageManager.NameNotFoundException;
28+
import android.util.Log;
29+
30+
/**
31+
* It collects application related data for the device.
32+
*/
33+
public class ApplicationDataCollector extends DataCollector {
34+
35+
private static final String TAG = ApplicationDataCollector.class.getSimpleName();
36+
private static final int ALL_FLAGS_OFF = 0;
37+
38+
/**
39+
* {@inheritDoc}
40+
*/
41+
@Override
42+
public Map<String, String> collect(Context context) {
43+
Map<String, String> contextData = new HashMap<String, String>();
44+
contextData.put(DataRecordKey.APP_NAME, getAppName(context));
45+
contextData.put(DataRecordKey.APP_TARGET_SDK, getAppTargetSdk(context));
46+
contextData.put(DataRecordKey.APP_VERSION, getAppVersion(context));
47+
return contextData;
48+
}
49+
50+
private String getAppName(Context context) {
51+
ApplicationInfo applicationInfo = context.getApplicationInfo();
52+
53+
PackageManager packageManager = context.getPackageManager();
54+
String appName = (String) packageManager.getApplicationLabel(applicationInfo);
55+
return appName;
56+
}
57+
58+
private String getAppVersion(Context context) {
59+
PackageManager packageManager = context.getPackageManager();
60+
61+
String appVersion = "";
62+
try {
63+
PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), ALL_FLAGS_OFF);
64+
appVersion = packageInfo.versionName;
65+
} catch (NameNotFoundException e) {
66+
Log.i(TAG, "Unable to get app version. Provided package name could not be found.");
67+
}
68+
return appVersion;
69+
}
70+
71+
private String getAppTargetSdk(Context context) {
72+
ApplicationInfo applicationInfo = context.getApplicationInfo();
73+
return String.valueOf(applicationInfo.targetSdkVersion);
74+
}
75+
}

0 commit comments

Comments
 (0)