BugFix: Git over HTTP/OAuth new WebSession injection

After the refactoring of Gerrit's WebSession pluggability [1]
the GitHub over HTTP/OAuth authentication stopped working because
of a different injection mechanism.
The regression caused Gerrit startup failure as the
GitHub OAuth filter was throwing a non recoverable exception during
init.

With this change, the injection works again correctly
and Git over HTTP/OAuth is fully functional again.

References:
[1] https://gerrit-review.googlesource.com/#/c/48697

Change-Id: I9ff2b651bd63393a465a54e64cc5dc19c07cc9e4
diff --git a/github-oauth/src/main/java/com/google/gerrit/httpd/XGerritAuth.java b/github-oauth/src/main/java/com/google/gerrit/httpd/XGerritAuth.java
index 25a308e..69a40ca 100644
--- a/github-oauth/src/main/java/com/google/gerrit/httpd/XGerritAuth.java
+++ b/github-oauth/src/main/java/com/google/gerrit/httpd/XGerritAuth.java
@@ -15,9 +15,11 @@
 
 import javax.servlet.http.Cookie;
 
+import com.google.common.cache.Cache;
 import com.google.gerrit.httpd.WebSessionManager.Val;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
+import com.google.inject.name.Named;
 
 @Singleton
 public class XGerritAuth {
@@ -25,12 +27,14 @@
   private WebSessionManager manager;
 
   @Inject
-  public XGerritAuth(WebSessionManager manager) {
-    this.manager = manager;
+  public XGerritAuth(WebSessionManagerFactory managerFactory,
+      @Named(WebSessionManager.CACHE_NAME) Cache<String, Val> cache) {
+    this.manager = managerFactory.create(cache);
   }
-  
+
   public String getAuthValue(Cookie gerritCookie) {
-    Val session = manager.get(new WebSessionManager.Key(gerritCookie.getValue()));
+    Val session =
+        manager.get(new WebSessionManager.Key(gerritCookie.getValue()));
     return session.getAuth();
   }
 }
diff --git a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/OAuthGitFilter.java b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/OAuthGitFilter.java
index 326ad23..cd8b32e 100644
--- a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/OAuthGitFilter.java
+++ b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/OAuthGitFilter.java
@@ -115,17 +115,17 @@
   @Inject
   public OAuthGitFilter(OAuthCache oauthCache, AccountCache accountCache,
       GitHubHttpProvider httpClientProvider, GitHubOAuthConfig config,
-      XGerritAuth xGerritAuth) {
+      XGerritAuth xGerritAuth, GitHubLogin.Provider ghLoginProvider) {
     this.oauthCache = oauthCache;
     this.accountCache = accountCache;
     this.httpClientProvider = httpClientProvider;
     this.config = config;
     this.xGerritAuth = xGerritAuth;
+    this.ghLoginProvider = ghLoginProvider;
   }
 
   @Override
   public void init(FilterConfig filterConfig) throws ServletException {
-    this.ghLoginProvider = new GitHubLogin.Provider();
   }
 
   @Override
@@ -142,22 +142,21 @@
     String username =
         getAuthenticatedUserFromGitRequestUsingOAuthToken(httpRequest,
             httpResponse);
-    if (username == null) {
-      return;
-    }
-    String gerritPassword =
-        accountCache.getByUsername(username).getPassword(username);
+    if (username != null) {
+      String gerritPassword =
+          accountCache.getByUsername(username).getPassword(username);
 
-    if (gerritPassword == null) {
-      gerritPassword =
-          generateRandomGerritPassword(username, httpRequest, httpResponse,
-              chain);
-      httpResponse.sendRedirect(getRequestPathWithQueryString(httpRequest));
-      return;
-    }
+      if (gerritPassword == null) {
+        gerritPassword =
+            generateRandomGerritPassword(username, httpRequest, httpResponse,
+                chain);
+        httpResponse.sendRedirect(getRequestPathWithQueryString(httpRequest));
+        return;
+      }
 
-    httpRequest =
-        new BasicAuthHttpRequest(httpRequest, username, gerritPassword);
+      httpRequest =
+          new BasicAuthHttpRequest(httpRequest, username, gerritPassword);
+    }
 
     chain.doFilter(httpRequest, httpResponse);
   }