SignOut and forced signout on delete

Added signout functionality and forced signout on delete.
This commit is contained in:
NMerz 2020-10-05 22:27:24 -04:00
parent e0fa35bb45
commit 8c526d3b8d
5 changed files with 28 additions and 19 deletions

View File

@ -32,15 +32,14 @@ public class UserDeleter implements CallHandler {
}
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);
AdminDeleteUserRequest adminDeleteUserRequest = new AdminDeleteUserRequest().withUserPoolId(userPoolId);
adminDeleteUserRequest.setUsername(cognitoID);
System.out.println(adminDeleteUserRequest);
awsCognitoIdentityProvider.adminDeleteUser(adminDeleteUserRequest);
return null;
// Connection connection = connector.getConnection();

View File

@ -50,8 +50,12 @@ public class AuthManager {
fetchAuthSession();
} catch (AuthException e) {
e.printStackTrace();
return "";
}
}
if (authSession.isSignedIn() == false) {
return "";
}
return authSession.getUserPoolTokens().getValue().getIdToken();
}
@ -129,12 +133,17 @@ public class AuthManager {
throwIfAuthError();
}
public void deleteUser(Requestor requestor) {
public void deleteUser(Requestor requestor) throws AuthException {
requestor.deleteObject("N/A", User.class);
Amplify.Auth.signOut(this::signOutSuccess, error -> setAuthError(error));
signOutUser();
}
public void signOutUser() throws AuthException {
authSession = null;
waiting = true;
Amplify.Auth.signOut(this::signOutSuccess, error -> setAuthError(error));
throwIfAuthError();
}
public static Properties loadProperties(Context context, String path) throws IOException, JSONException {
Properties toReturn = new Properties();

View File

@ -79,7 +79,7 @@ public class MainActivity extends AppCompatActivity {
Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey"));
authManager.deleteUser(requestor);
//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());
@ -90,7 +90,7 @@ public class MainActivity extends AppCompatActivity {
requestor.postObject(testList, idReceiver, idReceiver);
System.out.println(idReceiver.await());
requestor.postObject(entry);
} catch (JSONException | IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
@ -104,7 +104,7 @@ public class MainActivity extends AppCompatActivity {
System.out.println(itemReceiver.await());
System.out.println(listReceiver.await());
System.out.println(Arrays.toString(listIdsReceiver.await()));
} catch (IOException receiverError) {
} catch (Exception receiverError) {
receiverError.printStackTrace();
}
}

View File

@ -82,7 +82,10 @@ public class Requestor {
} catch (JsonSyntaxException e) {
System.out.println(e);
Log.e("API response was not proper JSON", responseString);
throw new JsonSyntaxException(e);
if (failureHandler != null) {
failureHandler.acceptError(e);
}
//throw new JsonSyntaxException(e);
}
}
Log.d("API Response", responseString);
@ -122,6 +125,6 @@ public class Requestor {
}
public interface RequestErrorHandler {
void acceptError(IOException error);
void acceptError(Exception error);
}
}

View File

@ -1,10 +1,8 @@
package com.example.listify;
import java.io.IOException;
public class SynchronousReceiver<T> implements Requestor.Receiver<T>, Requestor.RequestErrorHandler {
private volatile boolean waiting;
private volatile IOException error;
private volatile Exception error;
private T toReturn;
public SynchronousReceiver() {
@ -12,13 +10,13 @@ public class SynchronousReceiver<T> implements Requestor.Receiver<T>, Requestor.
error = null;
}
public T await() throws IOException {
public T await() throws Exception {
while (waiting) {
Thread.yield();
}
waiting = true;
if (error != null) {
IOException toThrow = error;
Exception toThrow = error;
error = null;
throw toThrow;
}
@ -32,7 +30,7 @@ public class SynchronousReceiver<T> implements Requestor.Receiver<T>, Requestor.
}
@Override
public void acceptError(IOException error) {
public void acceptError(Exception error) {
waiting = false;
this.error = error;
}