Commits

Luke Cyca committed 2cd5993

Fall back to password auth after three kerberos failures

Comments (0)

Files changed (1)

hgssoauthentication/__init__.py

         pass
 
     def http_error_401(self, req, fp, code, msg, headers):
+
+        # Count the number of failures on this request
+        if hasattr(req, 'failure_count'):
+            req.failure_count += 1
+        else:
+            req.failure_count = 1
+
+        # If it hasn't been successful after three tries, fall back
+        if req.failure_count >= 3:
+            print "Kerberos failed"
+            mercurial.url.handlerfuncs.remove(self.__class__)
+            return
+
         supported_schemes = [s.strip() for s in headers.get("WWW-Authenticate", "").split(",")]
 
         context = kerberos.authGSSClientInit("HTTP@%s" % req.get_host())[1]