mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-15 18:28:47 +00:00
Delete Lambda prototype
Prototype the User DELETE lambda. Amplify does not include this functionality, so putting it in a Lambda with the fine-grained API. This currently does not invalidate outstanding tokens nor does it clean up the database. @claytonwwilson You will want to add the clean up code instead of the deleted stuff in UserDeleter
This commit is contained in:
parent
1907dc6ce5
commit
fe846fb81f
3
Lambdas/Lists/User/resources/cognitoProperties.json
Normal file
3
Lambdas/Lists/User/resources/cognitoProperties.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"userPoolId": "us-east-2_MFgSVKQMd",
|
||||
}
|
||||
11
Lambdas/Lists/User/src/UserDELETE.java
Normal file
11
Lambdas/Lists/User/src/UserDELETE.java
Normal file
@ -0,0 +1,11 @@
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class UserDELETE implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, UserDeleter.class);
|
||||
}
|
||||
}
|
||||
59
Lambdas/Lists/User/src/UserDeleter.java
Normal file
59
Lambdas/Lists/User/src/UserDeleter.java
Normal file
@ -0,0 +1,59 @@
|
||||
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProvider;
|
||||
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClientBuilder;
|
||||
import com.amazonaws.services.cognitoidp.model.AdminDeleteUserRequest;
|
||||
import com.amazonaws.services.cognitoidp.model.AdminUserGlobalSignOutRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class UserDeleter implements CallHandler {
|
||||
|
||||
private DBConnector connector;
|
||||
private String cognitoID;
|
||||
|
||||
//private final String REMOVE_FROM_LIST = "DELETE FROM ListProduct WHERE (ProductID = ? AND ListID = ?);";
|
||||
|
||||
public UserDeleter(DBConnector connector, String cognitoID) {
|
||||
this.connector = connector;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||
AWSCognitoIdentityProvider awsCognitoIdentityProvider = AWSCognitoIdentityProviderClientBuilder.defaultClient();
|
||||
Properties cognitoProperties;
|
||||
try {
|
||||
cognitoProperties = DBConnector.loadProperties("cognitoProperties.json");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
String userPoolId = cognitoProperties.get("userPoolId").toString();
|
||||
System.out.println(userPoolId);
|
||||
AdminDeleteUserRequest adminDeleteUserRequest = new AdminDeleteUserRequest().withUserPoolId(userPoolId);
|
||||
adminDeleteUserRequest.setUsername(cognitoID);
|
||||
System.out.println(adminDeleteUserRequest);
|
||||
awsCognitoIdentityProvider.adminDeleteUser(adminDeleteUserRequest);
|
||||
AdminUserGlobalSignOutRequest adminUserGlobalSignOutRequest = new AdminUserGlobalSignOutRequest().withUserPoolId(userPoolId);
|
||||
adminUserGlobalSignOutRequest.setUsername(cognitoID);
|
||||
System.out.println(adminUserGlobalSignOutRequest);
|
||||
awsCognitoIdentityProvider.adminUserGlobalSignOut(adminUserGlobalSignOutRequest);
|
||||
|
||||
return null;
|
||||
|
||||
// Connection connection = connector.getConnection();
|
||||
// try {
|
||||
// PreparedStatement statement = connection.prepareStatement(REMOVE_FROM_LIST);
|
||||
// statement.setInt(1, (Integer) bodyMap.get("ProductID"));
|
||||
// statement.setInt(2, (Integer) bodyMap.get("ListID"));
|
||||
// System.out.println(statement);
|
||||
// statement.executeUpdate();
|
||||
// connection.commit();
|
||||
// } finally {
|
||||
// connection.close();
|
||||
// }
|
||||
// return null;
|
||||
}
|
||||
}
|
||||
@ -42,13 +42,53 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5</version>
|
||||
<version>4.5.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-cognitoidentity</artifactId>
|
||||
<version>1.11.875</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-cognitoidp</artifactId>
|
||||
<version>1.11.875</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>software.amazon.ion</groupId>
|
||||
<artifactId>ion-java</artifactId>
|
||||
<version>1.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>2.10.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-cbor</artifactId>
|
||||
<version>2.11.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.11.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.source>1.11</maven.compiler.source>
|
||||
|
||||
BIN
Lambdas/Lists/target/Lists-1.0-SNAPSHOT.jar
Normal file
BIN
Lambdas/Lists/target/Lists-1.0-SNAPSHOT.jar
Normal file
Binary file not shown.
5
Lambdas/Lists/target/maven-archiver/pom.properties
Normal file
5
Lambdas/Lists/target/maven-archiver/pom.properties
Normal file
@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Mon Oct 05 10:19:24 EDT 2020
|
||||
groupId=groupId
|
||||
artifactId=Lists
|
||||
version=1.0-SNAPSHOT
|
||||
@ -0,0 +1,4 @@
|
||||
/Users/MNM/Documents/GitHub/Listify/Lambdas/Lists/src/main/java/CallHandler.java
|
||||
/Users/MNM/Documents/GitHub/Listify/Lambdas/Lists/src/main/java/DBConnector.java
|
||||
/Users/MNM/Documents/GitHub/Listify/Lambdas/Lists/src/main/java/BasicHandler.java
|
||||
/Users/MNM/Documents/GitHub/Listify/Lambdas/Lists/src/main/java/InputUtils.java
|
||||
@ -8,6 +8,7 @@ import com.amplifyframework.auth.options.AuthSignUpOptions;
|
||||
import com.amplifyframework.auth.result.AuthSignInResult;
|
||||
import com.amplifyframework.auth.result.AuthSignUpResult;
|
||||
import com.amplifyframework.core.Amplify;
|
||||
import com.example.listify.data.User;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -85,6 +86,10 @@ public class AuthManager {
|
||||
waiting = false;
|
||||
}
|
||||
|
||||
public void signOutSuccess() {
|
||||
waiting = false;
|
||||
}
|
||||
|
||||
public void startSignUp(String email, String password) throws AuthException {
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
@ -124,6 +129,11 @@ public class AuthManager {
|
||||
throwIfAuthError();
|
||||
}
|
||||
|
||||
public void deleteUser(Requestor requestor) {
|
||||
requestor.deleteObject("N/A", User.class);
|
||||
Amplify.Auth.signOut(this::signOutSuccess, error -> setAuthError(error));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Properties loadProperties(Context context, String path) throws IOException, JSONException {
|
||||
|
||||
@ -14,8 +14,8 @@ import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
import com.amplifyframework.auth.AuthException;
|
||||
import com.example.listify.data.Item;
|
||||
import com.example.listify.data.ListEntry;
|
||||
import com.example.listify.data.List;
|
||||
import com.example.listify.data.ListEntry;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import org.json.JSONException;
|
||||
|
||||
@ -60,7 +60,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
//------------------------------------------------------------------------------------------//
|
||||
|
||||
|
||||
boolean testAPI = false;
|
||||
boolean testAPI = true;
|
||||
//----------------------------------API Testing---------------------------------------------//
|
||||
|
||||
if (testAPI) {
|
||||
@ -78,6 +78,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey"));
|
||||
|
||||
authManager.deleteUser(requestor);
|
||||
|
||||
//The name is the only part of this that is used, the rest is generated by the Lambda.
|
||||
List testList = new List(-1, "New List", "user filled by lambda", Instant.now().toEpochMilli());
|
||||
//Everything except addedDate is used for ItemEntry
|
||||
|
||||
@ -24,20 +24,30 @@ public class Requestor {
|
||||
client = new OkHttpClient();
|
||||
}
|
||||
|
||||
public <T> void getObject(String id, Class<T> classType, Receiver<T> receiver) {
|
||||
getObject(id, classType, receiver, null);
|
||||
}
|
||||
|
||||
public <T> void getListOfIds(Class<T> ofType, Receiver<Integer[]> successHandler, RequestErrorHandler failureHandler) {
|
||||
String getURL = DEV_BASEURL + "/" + ofType.getSimpleName() + "?id=-1";
|
||||
Request postRequest = buildBaseRequest(getURL, "GET", null);
|
||||
launchCall(postRequest, successHandler, Integer[].class, failureHandler);
|
||||
}
|
||||
|
||||
public <T> void getObject(String id, Class<T> classType, Receiver<T> receiver) {
|
||||
getObject(id, classType, receiver, null);
|
||||
}
|
||||
|
||||
public <T> void getObject(String id, Class<T> classType, Receiver<T> successHandler, RequestErrorHandler failureHandler) {
|
||||
String getURL = DEV_BASEURL + "/" + classType.getSimpleName() + "?id=" + id;
|
||||
Request postRequest = buildBaseRequest(getURL, "GET", null);
|
||||
launchCall(postRequest, successHandler, classType, failureHandler);
|
||||
Request getRequest = buildBaseRequest(getURL, "GET", null);
|
||||
launchCall(getRequest, successHandler, classType, failureHandler);
|
||||
}
|
||||
|
||||
public void deleteObject(String id, Class classType) {
|
||||
deleteObject(id, classType, null);
|
||||
}
|
||||
|
||||
public void deleteObject(String id, Class classType, RequestErrorHandler failureHandler) {
|
||||
String deleteURL = DEV_BASEURL + "/" + classType.getSimpleName() + "?id=" + id;
|
||||
Request deleteRequest = buildBaseRequest(deleteURL, "DELETE", "{}");
|
||||
launchCall(deleteRequest, null, classType, failureHandler);
|
||||
}
|
||||
|
||||
public void postObject(Object toPost) throws JSONException {
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.listify.data;
|
||||
|
||||
public class User {
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user