mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
SignOut and forced signout on delete
Added signout functionality and forced signout on delete.
This commit is contained in:
@@ -32,15 +32,14 @@ public class UserDeleter implements CallHandler {
|
|||||||
}
|
}
|
||||||
String userPoolId = cognitoProperties.get("userPoolId").toString();
|
String userPoolId = cognitoProperties.get("userPoolId").toString();
|
||||||
System.out.println(userPoolId);
|
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 adminUserGlobalSignOutRequest = new AdminUserGlobalSignOutRequest().withUserPoolId(userPoolId);
|
||||||
adminUserGlobalSignOutRequest.setUsername(cognitoID);
|
adminUserGlobalSignOutRequest.setUsername(cognitoID);
|
||||||
System.out.println(adminUserGlobalSignOutRequest);
|
System.out.println(adminUserGlobalSignOutRequest);
|
||||||
awsCognitoIdentityProvider.adminUserGlobalSignOut(adminUserGlobalSignOutRequest);
|
awsCognitoIdentityProvider.adminUserGlobalSignOut(adminUserGlobalSignOutRequest);
|
||||||
|
AdminDeleteUserRequest adminDeleteUserRequest = new AdminDeleteUserRequest().withUserPoolId(userPoolId);
|
||||||
|
adminDeleteUserRequest.setUsername(cognitoID);
|
||||||
|
System.out.println(adminDeleteUserRequest);
|
||||||
|
awsCognitoIdentityProvider.adminDeleteUser(adminDeleteUserRequest);
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Connection connection = connector.getConnection();
|
// Connection connection = connector.getConnection();
|
||||||
|
|||||||
@@ -50,8 +50,12 @@ public class AuthManager {
|
|||||||
fetchAuthSession();
|
fetchAuthSession();
|
||||||
} catch (AuthException e) {
|
} catch (AuthException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (authSession.isSignedIn() == false) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
return authSession.getUserPoolTokens().getValue().getIdToken();
|
return authSession.getUserPoolTokens().getValue().getIdToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,12 +133,17 @@ public class AuthManager {
|
|||||||
throwIfAuthError();
|
throwIfAuthError();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteUser(Requestor requestor) {
|
public void deleteUser(Requestor requestor) throws AuthException {
|
||||||
requestor.deleteObject("N/A", User.class);
|
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 {
|
public static Properties loadProperties(Context context, String path) throws IOException, JSONException {
|
||||||
Properties toReturn = new Properties();
|
Properties toReturn = new Properties();
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey"));
|
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.
|
//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());
|
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);
|
requestor.postObject(testList, idReceiver, idReceiver);
|
||||||
System.out.println(idReceiver.await());
|
System.out.println(idReceiver.await());
|
||||||
requestor.postObject(entry);
|
requestor.postObject(entry);
|
||||||
} catch (JSONException | IOException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
System.out.println(itemReceiver.await());
|
System.out.println(itemReceiver.await());
|
||||||
System.out.println(listReceiver.await());
|
System.out.println(listReceiver.await());
|
||||||
System.out.println(Arrays.toString(listIdsReceiver.await()));
|
System.out.println(Arrays.toString(listIdsReceiver.await()));
|
||||||
} catch (IOException receiverError) {
|
} catch (Exception receiverError) {
|
||||||
receiverError.printStackTrace();
|
receiverError.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,10 @@ public class Requestor {
|
|||||||
} catch (JsonSyntaxException e) {
|
} catch (JsonSyntaxException e) {
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
Log.e("API response was not proper JSON", responseString);
|
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);
|
Log.d("API Response", responseString);
|
||||||
@@ -122,6 +125,6 @@ public class Requestor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface RequestErrorHandler {
|
public interface RequestErrorHandler {
|
||||||
void acceptError(IOException error);
|
void acceptError(Exception error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package com.example.listify;
|
package com.example.listify;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class SynchronousReceiver<T> implements Requestor.Receiver<T>, Requestor.RequestErrorHandler {
|
public class SynchronousReceiver<T> implements Requestor.Receiver<T>, Requestor.RequestErrorHandler {
|
||||||
private volatile boolean waiting;
|
private volatile boolean waiting;
|
||||||
private volatile IOException error;
|
private volatile Exception error;
|
||||||
private T toReturn;
|
private T toReturn;
|
||||||
|
|
||||||
public SynchronousReceiver() {
|
public SynchronousReceiver() {
|
||||||
@@ -12,13 +10,13 @@ public class SynchronousReceiver<T> implements Requestor.Receiver<T>, Requestor.
|
|||||||
error = null;
|
error = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T await() throws IOException {
|
public T await() throws Exception {
|
||||||
while (waiting) {
|
while (waiting) {
|
||||||
Thread.yield();
|
Thread.yield();
|
||||||
}
|
}
|
||||||
waiting = true;
|
waiting = true;
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
IOException toThrow = error;
|
Exception toThrow = error;
|
||||||
error = null;
|
error = null;
|
||||||
throw toThrow;
|
throw toThrow;
|
||||||
}
|
}
|
||||||
@@ -32,7 +30,7 @@ public class SynchronousReceiver<T> implements Requestor.Receiver<T>, Requestor.
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void acceptError(IOException error) {
|
public void acceptError(Exception error) {
|
||||||
waiting = false;
|
waiting = false;
|
||||||
this.error = error;
|
this.error = error;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user