User retrieval updates

Make sure AuthManager always has the user email.

Make UserGET always return a User object.
This commit is contained in:
NMerz
2020-11-30 10:35:46 -05:00
parent e528830474
commit 53570b3356
4 changed files with 44 additions and 15 deletions

View File

@@ -33,16 +33,18 @@ public class UserGetter implements CallHandler {
checkRequest.setFilter("email=\"" + emailObject.toString() +"\"");
} else {
try {
String id = queryMap.get("id");
if ((id != null) && (!id.equals(""))) {
attributeToGet = "email";
checkRequest.setFilter("sub=\"" + cognitoID + "\"");
} else {
return cognitoID;
}
// String id = queryMap.get("id");
attributeToGet = "email";
checkRequest.setFilter("sub=\"" + cognitoID + "\"");
// if ((id != null) && (!id.equals(""))) {
// attributeToGet = "email";
// checkRequest.setFilter("sub=\"" + cognitoID + "\"");
// } else {
// return cognitoID;
// }
} catch (Exception e) {
System.out.println(e);
return cognitoID;
return new User(cognitoID, null);
}
}
System.out.println(checkRequest);
@@ -52,9 +54,9 @@ public class UserGetter implements CallHandler {
if (foundUsers.size() != 1) {
System.out.println(foundUsers);
if (foundUsers.size() == 0) {
throw new InputMismatchException("Not user with given email");
throw new InputMismatchException("Not user with given attribute (" + attributeToGet + ")");
}
throw new InputMismatchException("Found more than one user with supposedly unique email");
throw new InputMismatchException("Found more than one user with supposedly unique attribute (" + attributeToGet + ")");
}
UserType foundUser = foundUsers.get(0);
System.out.println(foundUser.getAttributes());
@@ -66,6 +68,11 @@ public class UserGetter implements CallHandler {
}
System.out.println(attribute.getName() + ": " + attribute.getValue());
}
return new User(cognitoID, attributeToReturn);
if (attributeToGet.equals("email")) {
return new User(cognitoID, attributeToReturn);
} else if (attributeToGet.equals("sub")) {
return new User(attributeToReturn, emailObject.toString());
}
return null;
}
}