mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
Merge pull request #140 from ClaytonWWilson/lambda-robustness
Lambda robustness
This commit is contained in:
@@ -43,7 +43,7 @@ public class ListGetter implements CallHandler{
|
|||||||
int sharees = 0;
|
int sharees = 0;
|
||||||
boolean verifiedAccess = false;
|
boolean verifiedAccess = false;
|
||||||
int uiPosition = 1;
|
int uiPosition = 1;
|
||||||
while ((sharees < 2 && accessResults.next()) || !verifiedAccess) {
|
while (accessResults.next() && (sharees < 2 || !verifiedAccess )) {
|
||||||
int permissionLevel = accessResults.getInt("permissionLevel");
|
int permissionLevel = accessResults.getInt("permissionLevel");
|
||||||
if (accessResults.getString("userID").equals(cognitoID)) {
|
if (accessResults.getString("userID").equals(cognitoID)) {
|
||||||
verifiedAccess = true;
|
verifiedAccess = true;
|
||||||
@@ -56,6 +56,9 @@ public class ListGetter implements CallHandler{
|
|||||||
sharees++;
|
sharees++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!verifiedAccess) {
|
||||||
|
throw new AccessControlException("User " + cognitoID + " does not have ant permission for list " + id);
|
||||||
|
}
|
||||||
boolean shared = false;
|
boolean shared = false;
|
||||||
if (sharees > 1) {
|
if (sharees > 1) {
|
||||||
shared = true;
|
shared = true;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
|
import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
|
||||||
import com.amazonaws.services.lambda.model.InvokeRequest;
|
import com.amazonaws.services.lambda.model.InvokeRequest;
|
||||||
import com.amazonaws.services.lambda.model.InvokeResult;
|
import com.amazonaws.services.lambda.model.InvokeResult;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import java.security.AccessControlException;
|
import java.security.AccessControlException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -56,7 +57,7 @@ public class ListSharer implements CallHandler {
|
|||||||
if (invokeResult.getStatusCode() != 200) {
|
if (invokeResult.getStatusCode() != 200) {
|
||||||
throw new InputMismatchException("Could not find specified user to share with");
|
throw new InputMismatchException("Could not find specified user to share with");
|
||||||
}
|
}
|
||||||
String shareWithSub = new String(invokeResult.getPayload().array()).replace("\"", "");
|
String shareWithSub = new Gson().fromJson(new String(invokeResult.getPayload().array()), User.class).cognitoID;
|
||||||
// checkAccess.setString(2, shareWithSub);
|
// checkAccess.setString(2, shareWithSub);
|
||||||
// checkAccessRS = checkAccess.executeQuery();
|
// checkAccessRS = checkAccess.executeQuery();
|
||||||
// if (checkAccessRS.next()) {
|
// if (checkAccessRS.next()) {
|
||||||
|
|||||||
26
Lambdas/Lists/User/src/User.java
Normal file
26
Lambdas/Lists/User/src/User.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
public class User {
|
||||||
|
String cognitoID;
|
||||||
|
String email;
|
||||||
|
|
||||||
|
public User(String cognitoID, String email) {
|
||||||
|
this.cognitoID = cognitoID;
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCognitoID() {
|
||||||
|
return cognitoID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCognitoID(String cognitoID) {
|
||||||
|
this.cognitoID = cognitoID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,16 +33,18 @@ public class UserGetter implements CallHandler {
|
|||||||
checkRequest.setFilter("email=\"" + emailObject.toString() +"\"");
|
checkRequest.setFilter("email=\"" + emailObject.toString() +"\"");
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
String id = queryMap.get("id");
|
// String id = queryMap.get("id");
|
||||||
if ((id != null) && (!id.equals(""))) {
|
attributeToGet = "email";
|
||||||
attributeToGet = "email";
|
checkRequest.setFilter("sub=\"" + cognitoID + "\"");
|
||||||
checkRequest.setFilter("sub=\"" + cognitoID + "\"");
|
// if ((id != null) && (!id.equals(""))) {
|
||||||
} else {
|
// attributeToGet = "email";
|
||||||
return cognitoID;
|
// checkRequest.setFilter("sub=\"" + cognitoID + "\"");
|
||||||
}
|
// } else {
|
||||||
|
// return cognitoID;
|
||||||
|
// }
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
return cognitoID;
|
return new User(cognitoID, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(checkRequest);
|
System.out.println(checkRequest);
|
||||||
@@ -52,9 +54,9 @@ public class UserGetter implements CallHandler {
|
|||||||
if (foundUsers.size() != 1) {
|
if (foundUsers.size() != 1) {
|
||||||
System.out.println(foundUsers);
|
System.out.println(foundUsers);
|
||||||
if (foundUsers.size() == 0) {
|
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);
|
UserType foundUser = foundUsers.get(0);
|
||||||
System.out.println(foundUser.getAttributes());
|
System.out.println(foundUser.getAttributes());
|
||||||
@@ -66,6 +68,11 @@ public class UserGetter implements CallHandler {
|
|||||||
}
|
}
|
||||||
System.out.println(attribute.getName() + ": " + attribute.getValue());
|
System.out.println(attribute.getName() + ": " + attribute.getValue());
|
||||||
}
|
}
|
||||||
return attributeToReturn;
|
if (attributeToGet.equals("email")) {
|
||||||
|
return new User(cognitoID, attributeToReturn);
|
||||||
|
} else if (attributeToGet.equals("sub")) {
|
||||||
|
return new User(attributeToReturn, emailObject.toString());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.amplifyframework.auth.result.AuthResetPasswordResult;
|
|||||||
import com.amplifyframework.auth.result.AuthSignInResult;
|
import com.amplifyframework.auth.result.AuthSignInResult;
|
||||||
import com.amplifyframework.auth.result.AuthSignUpResult;
|
import com.amplifyframework.auth.result.AuthSignUpResult;
|
||||||
import com.amplifyframework.core.Amplify;
|
import com.amplifyframework.core.Amplify;
|
||||||
|
import com.example.listify.data.ListShare;
|
||||||
import com.example.listify.data.User;
|
import com.example.listify.data.User;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -60,7 +61,21 @@ public class AuthManager {
|
|||||||
return authSession.getUserPoolTokens().getValue().getIdToken();
|
return authSession.getUserPoolTokens().getValue().getIdToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEmail() {
|
public String getEmail(Requestor requestor) {
|
||||||
|
if (email == null) {
|
||||||
|
try {
|
||||||
|
requestor.putObject(new ListShare(285, "nmerz@icloud.com", 210, -1, null));
|
||||||
|
} catch (JSONException jsonException) {
|
||||||
|
jsonException.printStackTrace();
|
||||||
|
}
|
||||||
|
SynchronousReceiver<User> userSynchronousReceiver = new SynchronousReceiver<>();
|
||||||
|
requestor.getObject("self", User.class, userSynchronousReceiver);
|
||||||
|
try {
|
||||||
|
email = userSynchronousReceiver.await().getEmail();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
}
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -171,8 +171,6 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
|
|||||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||||
|
|
||||||
TextView emailView = navigationView.getHeaderView(0).findViewById(R.id.textViewEmailSidebar);
|
|
||||||
emailView.setText(am.getEmail());
|
|
||||||
Properties configs = new Properties();
|
Properties configs = new Properties();
|
||||||
try {
|
try {
|
||||||
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||||
@@ -180,6 +178,8 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||||
|
TextView emailView = navigationView.getHeaderView(0).findViewById(R.id.textViewEmailSidebar);
|
||||||
|
emailView.setText(am.getEmail(requestor));
|
||||||
SynchronousReceiver<Picture> profilePictureReceiver = new SynchronousReceiver<>();
|
SynchronousReceiver<Picture> profilePictureReceiver = new SynchronousReceiver<>();
|
||||||
ImageView profilePictureView = navigationView.getHeaderView(0).findViewById(R.id.imageViewProfilePicture);
|
ImageView profilePictureView = navigationView.getHeaderView(0).findViewById(R.id.imageViewProfilePicture);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,4 +1,27 @@
|
|||||||
package com.example.listify.data;
|
package com.example.listify.data;
|
||||||
|
|
||||||
public class User {
|
public class User {
|
||||||
|
String cognitoID;
|
||||||
|
String email;
|
||||||
|
|
||||||
|
public User(String cognitoID, String email) {
|
||||||
|
this.cognitoID = cognitoID;
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCognitoID() {
|
||||||
|
return cognitoID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCognitoID(String cognitoID) {
|
||||||
|
this.cognitoID = cognitoID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,14 @@ public class ProfileFragment extends Fragment {
|
|||||||
View root = inflater.inflate(R.layout.fragment_profile, container, false);
|
View root = inflater.inflate(R.layout.fragment_profile, container, false);
|
||||||
|
|
||||||
TextView emailText = (TextView) root.findViewById(R.id.textViewEmail);
|
TextView emailText = (TextView) root.findViewById(R.id.textViewEmail);
|
||||||
emailText.setText(am.getEmail());
|
Properties configs = new Properties();
|
||||||
|
try {
|
||||||
|
configs = AuthManager.loadProperties(getContext(), "android.resource://" + getActivity().getPackageName() + "/raw/auths.json");
|
||||||
|
} catch (IOException | JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||||
|
emailText.setText(am.getEmail(requestor));
|
||||||
|
|
||||||
toDeleteAccountPage = (Button) root.findViewById(R.id.button);
|
toDeleteAccountPage = (Button) root.findViewById(R.id.button);
|
||||||
toDeleteAccountPage.setOnClickListener(new View.OnClickListener() {
|
toDeleteAccountPage.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|||||||
Reference in New Issue
Block a user