]> WPIA git - gigi.git/commitdiff
upd: tighten synchronizeation on User Objects while assuring
authorFelix Dörre <felix@dogcraft.de>
Mon, 2 May 2016 12:05:50 +0000 (14:05 +0200)
committerFelix Dörre <felix@dogcraft.de>
Mon, 2 May 2016 12:05:50 +0000 (14:05 +0200)
src/org/cacert/gigi/dbObjects/User.java
src/org/cacert/gigi/pages/account/MyDetailsForm.java
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.java
src/org/cacert/gigi/util/Notary.java

index bf12dd772f993cb30b3b4c00134accfeadbf1810..70fd821442ccbce19454cd91f888b1a07dc15d80 100644 (file)
@@ -19,6 +19,10 @@ import org.cacert.gigi.util.Notary;
 import org.cacert.gigi.util.PasswordHash;
 import org.cacert.gigi.util.PasswordStrengthChecker;
 
 import org.cacert.gigi.util.PasswordHash;
 import org.cacert.gigi.util.PasswordStrengthChecker;
 
+/**
+ * Represents an acting, assurable, user. Synchronizing on user means: no
+ * name-change and no assurance.
+ */
 public class User extends CertificateOwner {
 
     private Name name = new Name(null, null, null, null);
 public class User extends CertificateOwner {
 
     private Name name = new Name(null, null, null, null);
index 0339326a024451de7475fa284e17e0acb51b2b0b..9ea66b359965f8ba0142b1ca4cbcced21f252335 100644 (file)
@@ -37,20 +37,23 @@ public class MyDetailsForm extends Form {
     @Override
     public boolean submit(PrintWriter out, HttpServletRequest req) {
         try {
     @Override
     public boolean submit(PrintWriter out, HttpServletRequest req) {
         try {
-            if (target.getAssurancePoints() == 0) {
-                String newFname = req.getParameter("fname").trim();
-                String newLname = req.getParameter("lname").trim();
-                String newMname = req.getParameter("mname").trim();
-                String newSuffix = req.getParameter("suffix").trim();
-                if (newLname.isEmpty()) {
-                    throw new GigiApiException("Last name cannot be empty.");
+            synchronized (target) {
+                if (target.getAssurancePoints() == 0) {
+                    String newFname = req.getParameter("fname").trim();
+                    String newLname = req.getParameter("lname").trim();
+                    String newMname = req.getParameter("mname").trim();
+                    String newSuffix = req.getParameter("suffix").trim();
+                    if (newLname.isEmpty()) {
+                        throw new GigiApiException("Last name cannot be empty.");
+                    }
+
+                    target.setName(new Name(newFname, newLname, newMname, newSuffix));
+                    ds.update(req);
+                    target.setDoB(ds.getDate());
+                    target.updateUserData();
+                } else {
+                    throw new GigiApiException("No change after assurance allowed.");
                 }
                 }
-                target.setName(new Name(newFname, newLname, newMname, newSuffix));
-                ds.update(req);
-                target.setDoB(ds.getDate());
-                target.updateUserData();
-            } else {
-                throw new GigiApiException("No change after assurance allowed.");
             }
         } catch (GigiApiException e) {
             e.format(out, Page.getLanguage(req));
             }
         } catch (GigiApiException e) {
             e.format(out, Page.getLanguage(req));
index e1c94c6b84577b92eaa9bad5edde0fb274a64a8c..74fb02bb706f76a5fded7b5bd89a0f3b11e638a6 100644 (file)
@@ -105,8 +105,10 @@ public class SupportUserDetailsForm extends Form {
             throw new GigiApiException("Invalid date of birth!");
         }
         Name newName = new Name(fname, lname, mname, suffix);
             throw new GigiApiException("Invalid date of birth!");
         }
         Name newName = new Name(fname, lname, mname, suffix);
-        if (user.setDob(dobSelector.getDate()) | user.setName(newName)) {
-            user.submitSupportAction();
+        synchronized (user.getTargetUser()) {
+            if (user.setDob(dobSelector.getDate()) | user.setName(newName)) {
+                user.submitSupportAction();
+            }
         }
         return true;
     }
         }
         return true;
     }
index aa806fa929ce2b06ee4d4f31c5ce837213cddeae..c3a889ab4ac12a6ed5a3ce763a002c23df800083 100644 (file)
@@ -99,45 +99,47 @@ public class Notary {
         } else if (location.length() <= 2) {
             gae.mergeInto(new GigiApiException("You must enter a location with at least 3 characters eg town and country."));
         }
         } else if (location.length() <= 2) {
             gae.mergeInto(new GigiApiException("You must enter a location with at least 3 characters eg town and country."));
         }
+        synchronized (assuree) {
 
 
-        try {
-            checkAssuranceIsPossible(assurer, assuree);
-        } catch (GigiApiException e) {
-            gae.mergeInto(e);
-        }
+            try {
+                checkAssuranceIsPossible(assurer, assuree);
+            } catch (GigiApiException e) {
+                gae.mergeInto(e);
+            }
 
 
-        if ( !assuree.getName().equals(assureeName) || !assuree.getDoB().equals(dob)) {
-            gae.mergeInto(new GigiApiException("The person you are assuring changed his personal details."));
-        }
-        if (awarded < 0) {
-            gae.mergeInto(new GigiApiException("The points you are trying to award are out of range."));
-        } else {
-            if (type == AssuranceType.NUCLEUS) {
-                if (awarded > 50) {
-                    gae.mergeInto(new GigiApiException("The points you are trying to award are out of range."));
-                }
+            if ( !assuree.getName().equals(assureeName) || !assuree.getDoB().equals(dob)) {
+                gae.mergeInto(new GigiApiException("The person you are assuring changed his personal details."));
+            }
+            if (awarded < 0) {
+                gae.mergeInto(new GigiApiException("The points you are trying to award are out of range."));
             } else {
             } else {
-                if (awarded > assurer.getMaxAssurePoints()) {
-                    gae.mergeInto(new GigiApiException("The points you are trying to award are out of range."));
+                if (type == AssuranceType.NUCLEUS) {
+                    if (awarded > 50) {
+                        gae.mergeInto(new GigiApiException("The points you are trying to award are out of range."));
+                    }
+                } else {
+                    if (awarded > assurer.getMaxAssurePoints()) {
+                        gae.mergeInto(new GigiApiException("The points you are trying to award are out of range."));
+                    }
                 }
             }
                 }
             }
-        }
 
 
-        if ( !gae.isEmpty()) {
-            throw gae;
-        }
+            if ( !gae.isEmpty()) {
+                throw gae;
+            }
 
 
-        if (type == AssuranceType.FACE_TO_FACE) {
-            assureF2F(assurer, assuree, awarded, location, date);
-        } else if (type == AssuranceType.NUCLEUS) {
-            assureNucleus(assurer, assuree, awarded, location, date);
-        } else if (type == AssuranceType.TTP_ASSISTED) {
-            assureTTP(assurer, assuree, awarded, location, date);
-        } else {
-            throw new GigiApiException("Unknown Assurance type: " + type);
+            if (type == AssuranceType.FACE_TO_FACE) {
+                assureF2F(assurer, assuree, awarded, location, date);
+            } else if (type == AssuranceType.NUCLEUS) {
+                assureNucleus(assurer, assuree, awarded, location, date);
+            } else if (type == AssuranceType.TTP_ASSISTED) {
+                assureTTP(assurer, assuree, awarded, location, date);
+            } else {
+                throw new GigiApiException("Unknown Assurance type: " + type);
+            }
+            assurer.invalidateMadeAssurances();
+            assuree.invalidateReceivedAssurances();
         }
         }
-        assurer.invalidateMadeAssurances();
-        assuree.invalidateReceivedAssurances();
     }
 
     private static void assureF2F(User assurer, User assuree, int awarded, String location, String date) throws GigiApiException {
     }
 
     private static void assureF2F(User assurer, User assuree, int awarded, String location, String date) throws GigiApiException {