Просмотр исходного кода

Merge pull request #20996 from overleaf/ls-proper-error-for-wrong-git-url-format

proper error message for wrong git url format

GitOrigin-RevId: a6278850c2eca7e85c2526135d1c769fcbe94729
Liangjun Song 1 год назад
Родитель
Сommit
51b46f3909

+ 18 - 8
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/Oauth2Filter.java

@@ -122,7 +122,7 @@ public class Oauth2Filter implements Filter {
       cred.setAccessToken(password);
       cred.setAccessToken(password);
     } else if (this.isUserPasswordEnabled) {
     } else if (this.isUserPasswordEnabled) {
       // password auth has been deprecated for git-bridge
       // password auth has been deprecated for git-bridge
-      handlePasswordAuthenticationDeprecation(projectId, request, response);
+      handlePasswordAuthenticationDeprecation(projectId, username, request, response);
       return;
       return;
     } else {
     } else {
       handleNeedAuthorization(projectId, username, request, response);
       handleNeedAuthorization(projectId, username, request, response);
@@ -265,14 +265,24 @@ public class Oauth2Filter implements Filter {
   }
   }
 
 
   private void handlePasswordAuthenticationDeprecation(
   private void handlePasswordAuthenticationDeprecation(
-      String projectId, HttpServletRequest request, HttpServletResponse response)
+      String projectId, String username, HttpServletRequest request, HttpServletResponse response)
       throws IOException {
       throws IOException {
-    Log.info("[{}] Password authentication deprecated, ip={}", projectId, getClientIp(request));
-    sendResponse(
-        response,
-        403,
-        Arrays.asList(
-            "Overleaf now only supports Git authentication tokens to access git. See: https://www.overleaf.com/learn/how-to/Git_integration_authentication_tokens"));
+    if (username.contains("@")) {
+      Log.info("[{}] Password authentication deprecated, ip={}", projectId, getClientIp(request));
+      sendResponse(
+          response,
+          403,
+          Arrays.asList(
+              "Overleaf now only supports Git authentication tokens to access git. See: https://www.overleaf.com/learn/how-to/Git_integration_authentication_tokens"));
+    } else {
+      Log.info("[{}] Wrong git URL format, ip={}", projectId, getClientIp(request));
+      sendResponse(
+          response,
+          403,
+          Arrays.asList(
+              "Overleaf now only supports Git authentication tokens to access git. See: https://www.overleaf.com/learn/how-to/Git_integration_authentication_tokens",
+              "Please make sure your Git URL is correctly formatted. For example: https://git@git.overleaf.com/<YOUR_PROJECT_ID> or https://git:<AUTHENTICATION_TOKEN>@git.overleaf.com/<YOUR_PROJECT_ID>"));
+    }
   }
   }
 
 
   /*
   /*