Fix the CurrentUser request context propagation

To properly propagate the CurrentUser for the request scoped injection
which happens in a project import thread we must not get the CurrentUser
injected into the constructor of the ProjectRestEndpoint as it is a
singleton, instantiated at the plugin loading time when the CurrentUser
is just the PluginUser.

Instead, get the Provider<CurrentUser> in the constructor and execute it
in the context of the current request later.

Change-Id: I46dce05870cb049b016114057ec20a89382acf99
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectRestEndpoint.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectRestEndpoint.java
index 422349e..324c31e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectRestEndpoint.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectRestEndpoint.java
@@ -58,7 +58,7 @@
   private final WorkQueue queue;
   private final ImportProjectTask.Factory importFactory;
   private final ThreadLocalRequestContext tl;
-  private final CurrentUser user;
+  private final Provider<CurrentUser> currentUser;
   private final SchemaFactory<ReviewDb> schemaFactory;
 
   private WorkQueue.Executor executor;
@@ -68,12 +68,12 @@
   ProjectRestEndpoint(WorkQueue queue,
       ImportProjectTask.Factory importFactory,
       ThreadLocalRequestContext tl,
-      CurrentUser user,
+      Provider<CurrentUser> currentUser,
       SchemaFactory<ReviewDb> schemaFactory) {
     this.queue = queue;
     this.importFactory = importFactory;
     this.tl = tl;
-    this.user = user;
+    this.currentUser = currentUser;
     this.schemaFactory = schemaFactory;
   }
 
@@ -112,8 +112,10 @@
     }
   }
 
-  private Runnable withRequestContext(final Runnable task) throws OrmException {
+  private Runnable withRequestContext(final Runnable task)
+      throws OrmException {
     final ReviewDb db = schemaFactory.open();
+    final CurrentUser user = currentUser.get();
     return new Runnable() {
       @Override
       public void run() {