AWS SDK
This commit is contained in:
commit
d18a598540
33
.gitignore
vendored
Normal file
33
.gitignore
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
HELP.md
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
100
pom.xml
Normal file
100
pom.xml
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.example</groupId>
|
||||||
|
<artifactId>aws-sdk</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<name>aws-sdk</name>
|
||||||
|
<!-- FIXME change it to the project's website -->
|
||||||
|
<url>http://www.example.com</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.11</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.amazonaws</groupId>
|
||||||
|
<artifactId>aws-java-sdk</artifactId>
|
||||||
|
<version>1.12.81</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.amazonaws</groupId>
|
||||||
|
<artifactId>aws-java-sdk-core</artifactId>
|
||||||
|
<version>1.12.81</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-cognitoidp -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.amazonaws</groupId>
|
||||||
|
<artifactId>aws-java-sdk-cognitoidp</artifactId>
|
||||||
|
<version>1.12.81</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||||
|
<plugins>
|
||||||
|
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
|
<version>2.5.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>2.8.2</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>3.7.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
</project>
|
106
src/main/java/org/example/App.java
Normal file
106
src/main/java/org/example/App.java
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package org.example;
|
||||||
|
|
||||||
|
import com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider;
|
||||||
|
import com.amazonaws.client.builder.AwsClientBuilder;
|
||||||
|
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProvider;
|
||||||
|
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClientBuilder;
|
||||||
|
import com.amazonaws.services.cognitoidp.model.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hello world!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class App
|
||||||
|
{
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//AWSCognitoIdentityProvider cognitoClient = getAmazonCognitoIdentityClient();
|
||||||
|
|
||||||
|
try{
|
||||||
|
//awsCognitoIDPClient = new AWSCognitoIdentityProviderClient(new BasicAWSCredentials("AKIAWZE5RV2A25L5XZHW", "4VDMBOAjfcM4IDMuVh8p9YOMqI3zu/JrvF7Nsm4b")).withRegion(Regions.US_EAST_2);
|
||||||
|
|
||||||
|
_addUser();
|
||||||
|
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static AWSCognitoIdentityProvider getAmazonCognitoIdentityClient() {
|
||||||
|
ClasspathPropertiesFileCredentialsProvider propertiesFileCredentialsProvider =
|
||||||
|
new ClasspathPropertiesFileCredentialsProvider();
|
||||||
|
|
||||||
|
//AwsClientBuilder.EndpointConfiguration ep = new AwsClientBuilder.EndpointConfiguration(CognitoConfig.endpoint,CognitoConfig.region);
|
||||||
|
|
||||||
|
return AWSCognitoIdentityProviderClientBuilder.standard()
|
||||||
|
.withCredentials(propertiesFileCredentialsProvider)
|
||||||
|
//.withEndpointConfiguration(ep)
|
||||||
|
|
||||||
|
.withRegion(CognitoConfig.region)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void _listUsers(){
|
||||||
|
AWSCognitoIdentityProvider cognitoClient = getAmazonCognitoIdentityClient();
|
||||||
|
ListUsersRequest request = new ListUsersRequest();
|
||||||
|
request.setUserPoolId("us-east-1_lPr8YBxKX");
|
||||||
|
ListUsersResult listUsersResult = cognitoClient.listUsers(request);
|
||||||
|
System.out.println(listUsersResult.getUsers().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void _listUsersSniffPayload(){
|
||||||
|
AWSCognitoIdentityProvider cognitoClient = getAmazonCognitoIdentityClient();
|
||||||
|
ListUsersRequest request = new ListUsersRequest();
|
||||||
|
request.setUserPoolId("us-east-1_lPr8YBxKX");
|
||||||
|
//cognitoClient.setEndpoint("http://localhost:9999");
|
||||||
|
ListUsersResult listUsersResult = cognitoClient.listUsers(request);
|
||||||
|
System.out.println(listUsersResult.getUsers().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void _addUser(){
|
||||||
|
AWSCognitoIdentityProvider cognitoClient = getAmazonCognitoIdentityClient();
|
||||||
|
AdminCreateUserRequest request = new AdminCreateUserRequest();
|
||||||
|
|
||||||
|
request.setUsername("testsdk1");
|
||||||
|
request.setTemporaryPassword("Welcome@1");
|
||||||
|
request.setUserPoolId(CognitoConfig.userPoolId);
|
||||||
|
|
||||||
|
List<AttributeType> attributeTypeList = new ArrayList<>();
|
||||||
|
|
||||||
|
AttributeType ss = new AttributeType();
|
||||||
|
ss.setName("email");
|
||||||
|
ss.setValue("testsdk@nomail.com");
|
||||||
|
|
||||||
|
AttributeType emailVerified = new AttributeType();
|
||||||
|
emailVerified.setName("email_verified");
|
||||||
|
emailVerified.setValue("true");
|
||||||
|
|
||||||
|
attributeTypeList.add(ss);
|
||||||
|
attributeTypeList.add(emailVerified);
|
||||||
|
|
||||||
|
request.setUserAttributes(attributeTypeList);
|
||||||
|
|
||||||
|
cognitoClient.adminCreateUser(request);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//cognitoClient.setEndpoint("http://localhost:9999");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void _getUser(){
|
||||||
|
AWSCognitoIdentityProvider cognitoClient = getAmazonCognitoIdentityClient();
|
||||||
|
GetUserRequest request = new GetUserRequest();
|
||||||
|
request.setAccessToken("eyJraWQiOiI2YmE3MVF3XC9oTEd3TkR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||||
|
}
|
10
src/main/java/org/example/CognitoConfig.java
Normal file
10
src/main/java/org/example/CognitoConfig.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package org.example;
|
||||||
|
|
||||||
|
public class CognitoConfig {
|
||||||
|
public static final String clientId = "399tlpm1gllr3pve5fju1nadnr";
|
||||||
|
public static final String userPoolId = "us-east-1_lPr8YBxKX";
|
||||||
|
//public static final String endpoint = "cognito-idp.us-east-1.amazonaws.com";
|
||||||
|
public static final String endpoint = "http://localhost:9999";
|
||||||
|
public static final String region = "us-east-1";
|
||||||
|
|
||||||
|
}
|
9
src/main/resources/AwsCredentials.properties
Normal file
9
src/main/resources/AwsCredentials.properties
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
accessKey=AKIAWZE5RV2AU475N74C
|
||||||
|
secretKey=T2r1lWawUgD7hcKr/uAxYOeQSKF55FJetqrzkJPu
|
||||||
|
clientId=399tlpm1gllr3pve5fju1nadnr
|
||||||
|
#userPoolId=us-east-1_lPr8YBxKX
|
||||||
|
userPoolId=us-east-1_lPr8YBxKX
|
||||||
|
endpoint=cognito-idp.us-east-1.amazonaws.com
|
||||||
|
#endpoint=localhost:9999
|
||||||
|
region=us-east-1
|
||||||
|
#identityPoolId = us-east-1:f2810be3-a906-4a1e-83bc-aa1230b6789
|
20
src/test/java/org/example/AppTest.java
Normal file
20
src/test/java/org/example/AppTest.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package org.example;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for simple App.
|
||||||
|
*/
|
||||||
|
public class AppTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Rigorous Test :-)
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldAnswerWithTrue()
|
||||||
|
{
|
||||||
|
assertTrue( true );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user