Winston Li 12 лет назад
Родитель
Сommit
4dc093fcee

+ 6 - 2
services/git-bridge/src/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackHandler.java

@@ -26,9 +26,13 @@ public class SnapshotPushPostbackHandler extends AbstractHandler {
     public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
         if (request.getMethod().equals("POST") && request.getPathInfo().endsWith("postback")) {
             String contents = getContentsOfReader(request.getReader());
-            String projectName = request.getRequestURI().split("/")[1];
+            String[] parts = request.getRequestURI().split("/");
+            if (parts.length < 4) {
+                throw new ServletException();
+            }
+            String projectName = parts[1];
+            String postbackKey = parts[2];
             System.out.println("Postback received for project: " + projectName);
-            String postbackKey = "postback";
             SnapshotPushPostbackContents postbackContents = new SnapshotPushPostbackContents(writeLatexDataSource, projectName, postbackKey, contents);
             try {
                 postbackContents.processPostback();

+ 9 - 1
services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/api/request/push/PostbackManager.java

@@ -2,6 +2,8 @@ package uk.ac.ic.wlgitbridge.writelatex.api.request.push;
 
 import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.SnapshotPostException;
 
+import java.math.BigInteger;
+import java.security.SecureRandom;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -10,9 +12,11 @@ import java.util.Map;
  */
 public class PostbackManager {
 
+    private final SecureRandom random;
     private final Map<String, PostbackContents> postbackContentsTable;
 
     public PostbackManager() {
+        random = new SecureRandom();
         postbackContentsTable = new HashMap<String, PostbackContents>();
     }
 
@@ -39,10 +43,14 @@ public class PostbackManager {
     }
 
     public String makeKeyForProject(String projectName) {
-        String key = "postback";
+        String key = System.currentTimeMillis() + randomString();
         PostbackContents contents = new PostbackContents(key);
         postbackContentsTable.put(projectName, contents);
         return key;
     }
 
+    private String randomString() {
+        return new BigInteger(130, random).toString(32);
+    }
+
 }