Revert "Bump to GitBlit 1.7.0-SNAPSHOT"

This version of gitblit is not compatible with Gerrit 2.10 due to
different version of Guava.

This reverts commit 57a914de98eed950d0b451df5a111a80f970c1ff.

Change-Id: I13871f39eb69f83721a797c08c73a85e54f6b9c9
diff --git a/README b/README
new file mode 100644
index 0000000..5f79157
--- /dev/null
+++ b/README
@@ -0,0 +1,24 @@
+GitBlit plugin
+==============
+
+In order to use GitBlit as GitWeb replacement, please apply
+the following configuration to your Gerrit config.
+(assuming plugin was copied as gitblit.jar)
+
+[gitweb]
+        type = custom
+        url = /plugins/gitblit/
+        linkname = gitblit
+        project = summary/${project}.git
+        revision = commit/${project}.git/${commit}
+        branch = log/${project}.git/${branch}
+        filehistory = history/${project}.git/${branch}/${file}
+
+How to build:
+
+gitblit.jar (optionally):
+1. clone GitBlit
+2. ant -DresourceFolderPrefix=static installMaven
+
+gerrit-gitblit-plugin:
+mvn package
diff --git a/README.md b/README.md
deleted file mode 100644
index 08d468b..0000000
--- a/README.md
+++ /dev/null
@@ -1,55 +0,0 @@
-GitBlit plugin
-==============
-
-Overview
---------
-Purpose of this plugin is to use Gitblit as web-based viewer
-(i.e. GitWeb replacement) on top of Gerrit Code Review.
-
-How to build
-------------
-As pre-requisites you need to make a custom-build of Gitblit
-and Wicket: the standard JARs downloaded from a public Maven
-repository aren't enough as they are missing some specific
-build parameters and constraints (i.e. shaded-jar) that are
-needed for a Gerrit plugin to work properly.
-
-### Wicket
-You need to clone and build a modified version of Wicket that
-is currently published on GitHub under the GerritCodeReview
-organisation: https://github.com/GerritCodeReview/wicket.git
-
-    $ git clone https://github.com/GerritCodeReview/wicket.git
-    $ git checkout wicket-1.4.23-gerrit
-    $ mvn clean install -DskipTests
-
-### Gitblit
-You need to clone Gitblit from GitHub and build it locally
-using the installMaven ANT target.
-
-    $ git clone https://github.com/gitblit/gitblit.git
-    $ git checkout develop
-    $ ant -DresourceFolderPrefix=static installMaven
-
-### Gitblit plugin
-You are ready now to clone and build the Gitblit plugin: the
-Wicket and Giblit dependencies will be taken from your local
-Maven repository.
-
-    $ mvn package
-
-Configuration
--------------
-In order to use GitBlit as GitWeb replacement, please apply
-the following configuration to your Gerrit config.
-
-    [gitweb]
-        type = custom
-        linkname = Gitblit
-        url = plugins/
-        revision = gitblit/commit/?r=${project}&h=${commit}
-        project = gitblit/summary/?r=${project}
-        branch = gitblit/log/?r=${project}&h=${branch}
-        filehistory = gitblit/history/?f=${file}&r=${project}&h=${branch}
-        file = gitblit/blob/?r=${project}&h=${commit}&f=${file}
-        roottree = gitblit/tree/?r=${project}&h=${commit}
diff --git a/pom.xml b/pom.xml
index abdc915..da93aa1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,31 +28,103 @@
     <Gerrit-InitStep>com.googlesource.gerrit.plugins.gitblit.GitBlitInitStep</Gerrit-InitStep>
     <Gerrit-Module>com.googlesource.gerrit.plugins.gitblit.GitBlitModule</Gerrit-Module>
     <Gerrit-HttpModule>com.googlesource.gerrit.plugins.gitblit.GitBlitServletModule</Gerrit-HttpModule>
-    <dagger.version>1.1.0</dagger.version>
-    <wicket.version>1.4.23-gerrit</wicket.version>
   </properties>
   <dependencies>
     <dependency>
       <groupId>com.google.gerrit</groupId>
       <artifactId>gerrit-plugin-api</artifactId>
       <version>${Gerrit-ApiVersion}</version>
-      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>com.gitblit</groupId>
       <artifactId>gitblit</artifactId>
-      <version>1.7.0-SNAPSHOT</version>
-      <exclusions>
-        <exclusion>
-          <groupId>org.apache.wicket</groupId>
-          <artifactId>wicket</artifactId>
-        </exclusion>
-      </exclusions>
+      <version>1.4.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.wicket</groupId>
+      <artifactId>wicket-auth-roles</artifactId>
+      <version>1.4.21</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.wicket</groupId>
+      <artifactId>wicket-extensions</artifactId>
+      <version>1.4.21</version>
+    </dependency>
+    <dependency>
+      <groupId>org.wicketstuff</groupId>
+      <artifactId>googlecharts</artifactId>
+      <version>1.4.21</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpcore</artifactId>
+      <version>4.2.1</version>
+    </dependency>
+    <dependency>
+      <groupId>javax.mail</groupId>
+      <artifactId>mail</artifactId>
+      <version>1.4</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-net</groupId>
+      <artifactId>commons-net</artifactId>
+      <scope>provided</scope>
+      <version>3.1</version>
+    </dependency>
+      <dependency>
+        <groupId>commons-codec</groupId>
+        <artifactId>commons-codec</artifactId>
+        <version>1.6</version>
+      </dependency>
+    <dependency>
+      <groupId>org.codehaus.groovy</groupId>
+      <artifactId>groovy-all</artifactId>
+      <version>1.8.8</version>
+    </dependency>
+    <dependency>
+      <groupId>com.beust</groupId>
+      <artifactId>jcommander</artifactId>
+      <version>1.17</version>
+    </dependency>
+    <dependency>
+      <groupId>jdom</groupId>
+      <artifactId>jdom</artifactId>
+      <version>1.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.lucene</groupId>
+      <artifactId>lucene-core</artifactId>
+      <version>3.6.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.lucene</groupId>
+      <artifactId>lucene-highlighter</artifactId>
+      <version>3.6.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.lucene</groupId>
+      <artifactId>lucene-memory</artifactId>
+      <version>3.6.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.tautua.markdownpapers</groupId>
+      <artifactId>markdownpapers-core</artifactId>
+      <version>1.3.2</version>
+    </dependency>
+    <dependency>
+      <groupId>rome</groupId>
+      <artifactId>rome</artifactId>
+      <version>1.0-selfload</version>
+    </dependency>
+    <dependency>
+      <groupId>com.unboundid</groupId>
+      <artifactId>unboundid-ldapsdk</artifactId>
+      <version>2.3.0</version>
     </dependency>
     <dependency>
       <groupId>org.apache.wicket</groupId>
       <artifactId>wicket</artifactId>
-      <version>1.4.23-gerrit</version>
+      <version>1.4.21-selfload</version>
     </dependency>
   </dependencies>
   <build>
@@ -79,6 +151,7 @@
           <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
           <artifactSet>
             <excludes>
+              <exclude>com.google.gerrit:*</exclude>
               <exclude>org.bouncycastle:*</exclude>
               <exclude>org.slf4j:*</exclude>
               <exclude>com.google.guava:*</exclude>
@@ -88,26 +161,6 @@
               <exclude>com.googlecode.javaewah:*</exclude>
               <exclude>com.jcraft:*</exclude>
               <exclude>javax.servlet:*</exclude>
-              <exclude>org.apache.lucene:lucene-core</exclude>
-              <exclude>org.apache.lucene:lucene-analyzers-common</exclude>
-              <exclude>org.apache.lucene:lucene-queries</exclude>
-              <exclude>org.apache.lucene:lucene-queryparser</exclude>
-              <exclude>org.apache.sshd:*</exclude>
-              <exclude>org.apache.mina:*</exclude>
-              <exclude>org.bouncycastle:*</exclude>
-              <exclude>com.google.inject:*</exclude>
-              <exclude>com.google.inject.extensions:*</exclude>
-              <exclude>javax.inject:*</exclude>
-              <exclude>aopalliance:*</exclude>
-              <exclude>org.pegdown:*</exclude>
-              <exclude>org.parboiled:*</exclude>
-              <exclude>commons-io:commons-io</exclude>
-              <exclude>commons-codec:commons-codec</exclude>
-              <exclude>args4j:args4j</exclude>
-              <exclude>org.apache.commons:commons-compress</exclude>
-              <exclude>org.tukaani:xz</exclude>
-              <exclude>org.ow2.asm:*</exclude>
-              <exclude>org.eclipse.jetty:*</exclude>
             </excludes>
           </artifactSet>
           <transformers>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GerritGitBlitContext.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GerritGitBlitContext.java
deleted file mode 100644
index 6e3d101..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GerritGitBlitContext.java
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright (C) 2014 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.googlesource.gerrit.plugins.gitblit;
-
-import javax.servlet.ServletContext;
-
-import com.gitblit.manager.IAuthenticationManager;
-import com.gitblit.manager.IGitblit;
-import com.gitblit.manager.INotificationManager;
-import com.gitblit.manager.IProjectManager;
-import com.gitblit.manager.IRepositoryManager;
-import com.gitblit.manager.IRuntimeManager;
-import com.gitblit.manager.IUserManager;
-import com.gitblit.servlet.GitblitContext;
-import com.google.gerrit.server.config.SitePaths;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-
-@Singleton
-class GerritGitBlitContext extends GitblitContext {
-  private final SitePaths sitePaths;
-  private final IRuntimeManager runtime;
-  private final INotificationManager notificationManager;
-  private final IUserManager userManager;
-  private final IAuthenticationManager authenticationManager;
-  private final IRepositoryManager repositoryManager;
-  private final IProjectManager projectManager;
-  private final IGitblit gitblit;
-
-  @Inject
-  GerritGitBlitContext(SitePaths sitePaths, 
-      IRuntimeManager runtime,
-      INotificationManager notificationManager, 
-      IUserManager userManager,
-      IAuthenticationManager authenticationManager,
-      IRepositoryManager repositoryManager, 
-      IProjectManager projectManager,
-      IGitblit gitblit) {
-    this.sitePaths = sitePaths;
-    this.runtime = runtime;
-    this.notificationManager = notificationManager;
-    this.userManager = userManager;
-    this.authenticationManager = authenticationManager;
-    this.repositoryManager = repositoryManager;
-    this.projectManager = projectManager;
-    this.gitblit = gitblit;
-  }
-
-  void init(ServletContext context) {
-    // Manually configure IRuntimeManager
-    runtime.setBaseFolder(sitePaths.site_path);
-    runtime.getStatus().servletContainer = context.getServerInfo();
-    runtime.start();
-
-    // start all other managers
-    startManager(notificationManager);
-    startManager(userManager);
-    startManager(authenticationManager);
-    startManager(repositoryManager);
-    startManager(projectManager);
-    startManager(gitblit);
-
-    logger.info("All Gitblit managers started.");
-  }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GerritWicketFilter.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GerritWicketFilter.java
index d6f5aeb..a9d0601 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GerritWicketFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GerritWicketFilter.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 The Android Open Source Project
+// Copyright (C) 2012 The Android Open Source Project
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,80 +11,68 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-
 package com.googlesource.gerrit.plugins.gitblit;
 
 import java.io.IOException;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Set;
 import java.util.Vector;
 
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
 import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
 
+import org.apache.wicket.protocol.http.WicketFilter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.gitblit.Constants;
-import com.gitblit.IStoredSettings;
-import com.gitblit.manager.IProjectManager;
-import com.gitblit.manager.IRepositoryManager;
-import com.gitblit.manager.IRuntimeManager;
-import com.gitblit.wicket.GitBlitWebApp;
-import com.gitblit.wicket.GitblitWicketFilter;
-import com.google.common.collect.ImmutableSet;
-import com.google.gerrit.extensions.registration.DynamicItem;
+import com.gitblit.GitBlit;
 import com.google.gerrit.httpd.WebSession;
-import com.google.gerrit.server.config.SitePaths;
 import com.google.inject.Inject;
+import com.google.inject.Provider;
 import com.google.inject.Singleton;
+import com.googlesource.gerrit.plugins.gitblit.app.GerritGitBlit;
+import com.googlesource.gerrit.plugins.gitblit.app.GerritToGitBlitWebApp;
+import com.googlesource.gerrit.plugins.gitblit.app.GitBlitSettings;
 import com.googlesource.gerrit.plugins.gitblit.auth.GerritAuthFilter;
 
 @Singleton
-public class GerritWicketFilter extends GitblitWicketFilter {
+public class GerritWicketFilter extends WicketFilter {
   private static final Logger log = LoggerFactory
       .getLogger(GerritWicketFilter.class);
-  private static final Set<String> RESOURCES_SUFFIXES =
-      new ImmutableSet.Builder<String>().add("css", "js", "png", "gif", "ttf",
-          "swf", "afm", "eot", "otf", "scss", "svg", "woff").build();
 
-  private final DynamicItem<WebSession> webSession;
-
+  private final Provider<WebSession> webSession;
+  @SuppressWarnings("unused")
+  // We need Guice to create the GerritGitBlit instance
+  private final GerritGitBlit gitBlit;
   private final GerritAuthFilter gerritAuthFilter;
-
-  private final GerritGitBlitContext gerritGitblitContext;
+  private final GitBlitSettings settings;
 
   @Inject
   public GerritWicketFilter(
-      DynamicItem<WebSession> webSession,
-      GerritAuthFilter gerritAuthFilter,
-      GerritGitBlitContext gerritGitblitContext,
-      SitePaths sitePaths,
-      IStoredSettings settings,
-      IRuntimeManager runtimeManager,
-      IRepositoryManager repositoryManager,
-      IProjectManager projectManager,
-      GitBlitWebApp webapp) {
-    super(settings, runtimeManager, repositoryManager, projectManager, webapp);
+      final Provider<WebSession> webSession, final GerritGitBlit gitBlit,
+      final GerritAuthFilter gerritAuthFilter, final GitBlitSettings settings) {
     this.webSession = webSession;
+    this.gitBlit = gitBlit;
     this.gerritAuthFilter = gerritAuthFilter;
-    this.gerritGitblitContext = gerritGitblitContext;
+    this.settings = settings;
   }
 
   @Override
   public void init(FilterConfig filterConfig) throws ServletException {
-    ServletContext servletContext = filterConfig.getServletContext();
     showGitBlitBanner();
-    gerritGitblitContext.init(servletContext);
 
     try {
+      GitBlit.self().configureContext(settings, settings.getBasePath(),
+          false);
+      GitBlit.self().contextInitialized(
+          new ServletContextEvent(filterConfig.getServletContext()));
       super.init(new CustomFilterConfig(filterConfig));
     } catch (Exception e) {
       throw new ServletException(e);
@@ -114,32 +102,8 @@
   @Override
   public void doFilter(ServletRequest request, ServletResponse response,
       FilterChain chain) throws IOException, ServletException {
-    HttpServletRequest httpServletRequest = (HttpServletRequest) request;
-    String requestPathInfo = httpServletRequest.getPathInfo();
-
-    if (isStaticResourceRequest(requestPathInfo)) {
-      if (!requestPathInfo.startsWith("/static")
-          && !requestPathInfo.startsWith("/resources")) {
-        httpServletRequest = new StaticHttpServletRequest(httpServletRequest);
-      }
-      super.doFilter(httpServletRequest, response, chain);
-    } else if (gerritAuthFilter.doFilter(webSession, httpServletRequest,
-        response, chain)) {
-      super.doFilter(httpServletRequest, response, chain);
-    }
-  }
-
-  private boolean isStaticResourceRequest(String requestPathInfo) {
-    return RESOURCES_SUFFIXES.contains(getResourceSuffix(requestPathInfo)
-        .toLowerCase());
-  }
-
-  private String getResourceSuffix(String requestPathInfo) {
-    int requestPathLastDot = requestPathInfo.lastIndexOf('.');
-    if (requestPathLastDot < 0) {
-      return "";
-    } else {
-      return requestPathInfo.substring(requestPathLastDot + 1);
+    if (gerritAuthFilter.doFilter(webSession, request, response, chain)) {
+      super.doFilter(request, response, chain);
     }
   }
 
@@ -149,6 +113,7 @@
 
     private HashMap<String, String> getGitblitInitParams() {
       HashMap<String, String> props = new HashMap<String, String>();
+      props.put("applicationClassName", GerritToGitBlitWebApp.class.getName());
       props.put("filterMappingUrlPattern", "/*");
       props.put("ignorePaths", "pages/,feed/");
       return props;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitServletModule.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitServletModule.java
index 3ec851d..4ecdf54 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitServletModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitServletModule.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 The Android Open Source Project
+// Copyright (C) 2012 The Android Open Source Project
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,55 +11,23 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-
 package com.googlesource.gerrit.plugins.gitblit;
 
 import org.eclipse.jgit.lib.Config;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.gitblit.IStoredSettings;
-import com.gitblit.guice.IPublicKeyManagerProvider;
-import com.gitblit.guice.ITicketServiceProvider;
-import com.gitblit.guice.WorkQueueProvider;
-import com.gitblit.manager.FederationManager;
-import com.gitblit.manager.GitblitManager;
-import com.gitblit.manager.IAuthenticationManager;
-import com.gitblit.manager.IFederationManager;
-import com.gitblit.manager.IGitblit;
-import com.gitblit.manager.INotificationManager;
-import com.gitblit.manager.IPluginManager;
-import com.gitblit.manager.IProjectManager;
-import com.gitblit.manager.IRepositoryManager;
-import com.gitblit.manager.IRuntimeManager;
-import com.gitblit.manager.IServicesManager;
-import com.gitblit.manager.IUserManager;
-import com.gitblit.manager.NotificationManager;
-import com.gitblit.manager.ProjectManager;
-import com.gitblit.manager.RepositoryManager;
-import com.gitblit.manager.RuntimeManager;
-import com.gitblit.manager.ServicesManager;
-import com.gitblit.servlet.BranchGraphServlet;
-import com.gitblit.servlet.DownloadZipServlet;
-import com.gitblit.servlet.LogoServlet;
-import com.gitblit.servlet.PagesServlet;
-import com.gitblit.servlet.SyndicationServlet;
-import com.gitblit.tickets.ITicketService;
-import com.gitblit.transport.ssh.IPublicKeyManager;
-import com.gitblit.utils.JSoupXssFilter;
-import com.gitblit.utils.WorkQueue;
-import com.gitblit.utils.XssFilter;
+import com.gitblit.IUserService;
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.server.config.GerritServerConfig;
 import com.google.gerrit.server.config.SitePaths;
 import com.google.inject.Inject;
 import com.google.inject.servlet.ServletModule;
-import com.googlesource.gerrit.plugins.gitblit.app.GitBlitSettings;
+import com.googlesource.gerrit.plugins.gitblit.app.GerritGitBlit;
 import com.googlesource.gerrit.plugins.gitblit.auth.GerritToGitBlitUserService;
 
 public class GitBlitServletModule extends ServletModule {
-  private static final Logger log = LoggerFactory
-      .getLogger(GitBlitServletModule.class);
+  private static final Logger log = LoggerFactory.getLogger(GitBlitServletModule.class);
 
   @Inject
   public GitBlitServletModule(@PluginName final String name,
@@ -69,38 +37,15 @@
 
   @Override
   protected void configureServlets() {
-    log.info("Configuring Gitblit core services");
-    bind(IStoredSettings.class).to(GitBlitSettings.class);
-    bind(XssFilter.class).to(JSoupXssFilter.class);
+    log.info("Configuring servlet and filters");
+    bind(IUserService.class).to(GerritToGitBlitUserService.class);
+    bind(GerritGitBlit.class);
 
-    // bind complex providers
-    bind(IPublicKeyManager.class).toProvider(IPublicKeyManagerProvider.class);
-    bind(ITicketService.class).toProvider(ITicketServiceProvider.class);
-    bind(WorkQueue.class).toProvider(WorkQueueProvider.class);
-
-    // core managers
-    bind(IRuntimeManager.class).to(RuntimeManager.class);
-    bind(IPluginManager.class).to(NullPluginManager.class);
-    bind(INotificationManager.class).to(NotificationManager.class);
-    bind(IUserManager.class).to(GerritToGitBlitUserService.class);
-    bind(IAuthenticationManager.class).to(GerritToGitBlitUserService.class);
-    bind(IRepositoryManager.class).to(RepositoryManager.class);
-    bind(IProjectManager.class).to(ProjectManager.class);
-    bind(IFederationManager.class).to(FederationManager.class);
-
-    // the monolithic manager
-    bind(IGitblit.class).to(GitblitManager.class);
-
-    // manager for long-running daemons and services
-    bind(IServicesManager.class).to(ServicesManager.class);
-
-    log.info("Configuring Gitblit servlets and filters");
-    serve("/graph/*").with(BranchGraphServlet.class);
-    serve("/pages/*").with(PagesServlet.class);
-    serve("/feed/*").with(SyndicationServlet.class);
-    serve("/zip/*").with(DownloadZipServlet.class);
-    serve("/logo.png").with(LogoServlet.class);
-    serve("/static/logo.png").with(LogoServlet.class);
+    serve("/pages/*").with(WrappedPagesServlet.class);
+    serve("/feed/*").with(WrappedSyndicationServlet.class);
+    serve("/zip/*").with(WrappedDownloadZipServlet.class);
+    serve("/logo.png").with(WrappedLogoServlet.class);
+    serve("/static/logo.png").with(WrappedLogoServlet.class);
 
     filter("/*").through(GerritWicketFilter.class);
     filter("/pages/*").through(WrappedPagesFilter.class);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitTopMenu.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitTopMenu.java
index b4e5778..83204ae 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitTopMenu.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitTopMenu.java
@@ -1,17 +1,3 @@
-// Copyright (C) 2014 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
 package com.googlesource.gerrit.plugins.gitblit;
 
 import java.util.Arrays;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitUrlsConfig.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitUrlsConfig.java
index 9c95f9d..75c681d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitUrlsConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitUrlsConfig.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 The Android Open Source Project
+// Copyright (C) 2012 The Android Open Source Project
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,7 +11,6 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-
 package com.googlesource.gerrit.plugins.gitblit;
 
 import java.net.InetAddress;
@@ -25,7 +24,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
 
 public class GitBlitUrlsConfig {
   private static final int SSH_DEF_PORT = 22;
@@ -100,7 +99,7 @@
         return "";
       }
 
-    String httpUrl = MoreObjects.firstNonNull(canonicalWebUrlString, httpListenUrl);
+    String httpUrl = Objects.firstNonNull(canonicalWebUrlString, httpListenUrl);
     httpUrl = httpUrl.replace("://", "://" + GITBLIT_USER + "@");
     httpUrl += (httpUrl.endsWith("/") ? "" : "/") + GITBLIT_REPO;
     return httpUrl;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/NullPluginManager.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/NullPluginManager.java
deleted file mode 100644
index fa89c87..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/NullPluginManager.java
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright (C) 2014 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.googlesource.gerrit.plugins.gitblit;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
-
-import ro.fortsoft.pf4j.PluginState;
-import ro.fortsoft.pf4j.PluginWrapper;
-import ro.fortsoft.pf4j.Version;
-
-import com.gitblit.manager.IManager;
-import com.gitblit.manager.IPluginManager;
-import com.gitblit.models.PluginRegistry.InstallState;
-import com.gitblit.models.PluginRegistry.PluginRegistration;
-import com.gitblit.models.PluginRegistry.PluginRelease;
-import com.google.inject.Singleton;
-
-@Singleton
-public class NullPluginManager implements IPluginManager {
-
-  @Override
-  public IManager start() {
-    return this;
-  }
-
-  @Override
-  public IManager stop() {
-    return this;
-  }
-
-  @Override
-  public Version getSystemVersion() {
-    return Version.ZERO;
-  }
-
-  @Override
-  public void startPlugins() {
-  }
-
-  @Override
-  public void stopPlugins() {
-  }
-
-  @Override
-  public PluginState startPlugin(String pluginId) {
-    return null;
-  }
-
-  @Override
-  public PluginState stopPlugin(String pluginId) {
-    return null;
-  }
-
-  @Override
-  public List<Class<?>> getExtensionClasses(String pluginId) {
-    return Collections.emptyList();
-  }
-
-  @Override
-  public <T> List<T> getExtensions(Class<T> type) {
-    return Collections.emptyList();
-  }
-
-  @Override
-  public List<PluginWrapper> getPlugins() {
-    return Collections.emptyList();
-  }
-
-  @Override
-  public PluginWrapper getPlugin(String pluginId) {
-    return null;
-  }
-
-  @Override
-  public PluginWrapper whichPlugin(Class<?> clazz) {
-    return null;
-  }
-
-  @Override
-  public boolean disablePlugin(String pluginId) {
-    return false;
-  }
-
-  @Override
-  public boolean enablePlugin(String pluginId) {
-    return false;
-  }
-
-  @Override
-  public boolean uninstallPlugin(String pluginId) {
-    return false;
-  }
-
-  @Override
-  public boolean refreshRegistry(boolean verifyChecksum) {
-    return false;
-  }
-
-  @Override
-  public boolean installPlugin(String url, boolean verifyChecksum)
-      throws IOException {
-    return false;
-  }
-
-  @Override
-  public boolean upgradePlugin(String pluginId, String url,
-      boolean verifyChecksum) throws IOException {
-    return false;
-  }
-
-  @Override
-  public List<PluginRegistration> getRegisteredPlugins() {
-    return null;
-  }
-
-  @Override
-  public List<PluginRegistration> getRegisteredPlugins(InstallState state) {
-    return null;
-  }
-
-  @Override
-  public PluginRegistration lookupPlugin(String idOrName) {
-    return null;
-  }
-
-  @Override
-  public PluginRelease lookupRelease(String idOrName, String version) {
-    return null;
-  }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/StaticHttpServletRequest.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/StaticHttpServletRequest.java
deleted file mode 100644
index 2cdfc7e..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/StaticHttpServletRequest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (C) 2014 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.googlesource.gerrit.plugins.gitblit;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-
-public class StaticHttpServletRequest extends HttpServletRequestWrapper {
-
-  public StaticHttpServletRequest(HttpServletRequest request) {
-    super(request);
-  }
-
-  @Override
-  public String getPathInfo() {
-    return "/static" + super.getPathInfo();
-  }
-
-  @Override
-  public String getRequestURI() {
-    return super.getContextPath() + "/static" + super.getPathInfo();
-  }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedDownloadZipServlet.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedDownloadZipServlet.java
new file mode 100644
index 0000000..4b5fd24
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedDownloadZipServlet.java
@@ -0,0 +1,28 @@
+// Copyright (C) 2013 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.googlesource.gerrit.plugins.gitblit;
+
+import com.gitblit.DownloadZipServlet;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+@Singleton
+public class WrappedDownloadZipServlet extends DownloadZipServlet {
+  private static final long serialVersionUID = 1348780775920545752L;
+
+  @Inject
+  public WrappedDownloadZipServlet() {
+    super();
+  }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedLogoServlet.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedLogoServlet.java
new file mode 100644
index 0000000..1edea30
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedLogoServlet.java
@@ -0,0 +1,27 @@
+// Copyright (C) 2013 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.googlesource.gerrit.plugins.gitblit;
+
+import com.gitblit.LogoServlet;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+@Singleton
+@SuppressWarnings("serial")
+public class WrappedLogoServlet extends LogoServlet {
+  @Inject
+  public WrappedLogoServlet() {
+    super();
+  }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedPagesFilter.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedPagesFilter.java
index 80a8968..ad01de7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedPagesFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedPagesFilter.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 The Android Open Source Project
+// Copyright (C) 2012 The Android Open Source Project
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,7 +11,6 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-
 package com.googlesource.gerrit.plugins.gitblit;
 
 import java.io.IOException;
@@ -22,29 +21,22 @@
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 
-import com.gitblit.manager.IAuthenticationManager;
-import com.gitblit.manager.IRepositoryManager;
-import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.PagesFilter;
 import com.gitblit.models.UserModel;
-import com.gitblit.servlet.PagesFilter;
-import com.google.gerrit.extensions.registration.DynamicItem;
 import com.google.gerrit.httpd.WebSession;
 import com.google.inject.Inject;
+import com.google.inject.Provider;
 import com.google.inject.Singleton;
 import com.googlesource.gerrit.plugins.gitblit.auth.GerritAuthFilter;
 
 @Singleton
 public class WrappedPagesFilter extends PagesFilter {
   private final GerritAuthFilter gerritAuthFilter;
-  private final DynamicItem<WebSession> webSession;
+  private final Provider<WebSession> webSession;
 
   @Inject
-  public WrappedPagesFilter(DynamicItem<WebSession> webSession,
-      GerritAuthFilter gerritAuthFilter,
-      IRuntimeManager runtimeManager,
-      IAuthenticationManager authenticationManager,
-      IRepositoryManager repositoryManager) {
-    super(runtimeManager, authenticationManager, repositoryManager);
+  public WrappedPagesFilter(final Provider<WebSession> webSession, final GerritAuthFilter gerritAuthFilter) {
+    super();
 
     this.webSession = webSession;
     this.gerritAuthFilter = gerritAuthFilter;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedPagesServlet.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedPagesServlet.java
new file mode 100644
index 0000000..13bfcfc
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedPagesServlet.java
@@ -0,0 +1,27 @@
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.googlesource.gerrit.plugins.gitblit;
+
+import com.gitblit.PagesServlet;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+@Singleton
+@SuppressWarnings("serial")
+public class WrappedPagesServlet extends PagesServlet {
+  @Inject
+  public WrappedPagesServlet() {
+   super();
+  }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedSyndicationFilter.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedSyndicationFilter.java
index 88c93a7..d86a268 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedSyndicationFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedSyndicationFilter.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 The Android Open Source Project
+// Copyright (C) 2012 The Android Open Source Project
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,7 +11,6 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-
 package com.googlesource.gerrit.plugins.gitblit;
 
 import java.io.IOException;
@@ -21,54 +20,34 @@
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
 
-import com.gitblit.manager.IAuthenticationManager;
-import com.gitblit.manager.IProjectManager;
-import com.gitblit.manager.IRepositoryManager;
-import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.SyndicationFilter;
 import com.gitblit.models.UserModel;
-import com.gitblit.servlet.SyndicationFilter;
-import com.google.gerrit.extensions.registration.DynamicItem;
 import com.google.gerrit.httpd.WebSession;
 import com.google.inject.Inject;
+import com.google.inject.Provider;
 import com.google.inject.Singleton;
 import com.googlesource.gerrit.plugins.gitblit.auth.GerritAuthFilter;
 
 @Singleton
 public class WrappedSyndicationFilter extends SyndicationFilter {
-  private final GerritAuthFilter gerritAuthFilter;
-  private final DynamicItem<WebSession> webSession;
-  
-  static class SyndicationHttpServletRequest extends HttpServletRequestWrapper {
-    public SyndicationHttpServletRequest(HttpServletRequest request) {
-      super(request);
-    }
-
-    @Override
-    public String getServletPath() {
-      return super.getServletPath() + "/feed";
-    }
-  }
+  @Inject
+  private GerritAuthFilter gerritAuthFilter;
 
   @Inject
-  public WrappedSyndicationFilter(DynamicItem<WebSession> webSession,
-      GerritAuthFilter gerritAuthFilter,
-      IRuntimeManager runtimeManager,
-      IAuthenticationManager authenticationManager,
-      IRepositoryManager repositoryManager,
-      IProjectManager projectManager) {
-    super(runtimeManager, authenticationManager, repositoryManager, projectManager);
+  private final Provider<WebSession> webSession;
+
+  @Inject
+  public WrappedSyndicationFilter(final Provider<WebSession> webSession) {
+    super();
     this.webSession = webSession;
-    this.gerritAuthFilter = gerritAuthFilter;
   }
 
   @Override
   public void doFilter(ServletRequest request, ServletResponse response,
       FilterChain chain) throws IOException, ServletException {
     if (gerritAuthFilter.doFilter(webSession, request, response, chain)) {
-      super.doFilter(new SyndicationHttpServletRequest(
-          (HttpServletRequest) request), response, chain);
+      super.doFilter(request, response, chain);
     }
   }
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedSyndicationServlet.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedSyndicationServlet.java
new file mode 100644
index 0000000..8560b74
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedSyndicationServlet.java
@@ -0,0 +1,27 @@
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.googlesource.gerrit.plugins.gitblit;
+
+import com.gitblit.SyndicationServlet;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+@Singleton
+@SuppressWarnings("serial")
+public class WrappedSyndicationServlet extends SyndicationServlet {
+  @Inject
+  public WrappedSyndicationServlet() {
+    super();
+  }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GerritGitBlit.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GerritGitBlit.java
new file mode 100644
index 0000000..8da4164
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GerritGitBlit.java
@@ -0,0 +1,65 @@
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.googlesource.gerrit.plugins.gitblit.app;
+
+import java.io.InputStream;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
+
+import com.gitblit.GitBlit;
+import com.gitblit.models.UserModel;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.googlesource.gerrit.plugins.gitblit.auth.GerritToGitBlitUserModel;
+import com.googlesource.gerrit.plugins.gitblit.auth.GerritToGitBlitUserService;
+
+@Singleton
+public class GerritGitBlit extends GitBlit {
+
+  @Inject
+  public GerritGitBlit(GerritToGitBlitUserService userService) {
+    super(userService);
+  }
+
+  public UserModel authenticate(HttpServletRequest request) {
+    String user = (String) request.getAttribute("gerrit-username");
+    String token = (String) request.getAttribute("gerrit-token");
+    String password = (String) request.getAttribute("gerrit-password");
+    if (token != null) {
+      return GitBlit.self().authenticate(user,
+          (GerritToGitBlitUserService.SESSIONAUTH + token).toCharArray());
+    } else if(user != null && password != null){
+      return GitBlit.self().authenticate(user, password.toCharArray());
+    } else {
+      return GitBlit.self().authenticate(
+          GerritToGitBlitUserModel.ANONYMOUS_USER,
+          GerritToGitBlitUserModel.ANONYMOUS_PASSWORD);
+    }
+  }
+
+  @Override
+  public InputStream getResourceAsStream(String file)
+      throws ResourceStreamNotFoundException {
+    String resourceName = "/static/" + file;
+    InputStream is = getClass().getResourceAsStream(resourceName);
+    if (is == null) {
+      throw new ResourceStreamNotFoundException("Cannot access resource "
+          + resourceName + " using class-loader " + getClass().getClassLoader());
+    }
+
+    return is;
+  }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GerritToGitBlitWebApp.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GerritToGitBlitWebApp.java
new file mode 100644
index 0000000..419487c
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GerritToGitBlitWebApp.java
@@ -0,0 +1,31 @@
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.googlesource.gerrit.plugins.gitblit.app;
+
+import org.apache.wicket.protocol.http.WebRequestCycleProcessor;
+import org.apache.wicket.request.IRequestCodingStrategy;
+import org.apache.wicket.request.IRequestCycleProcessor;
+
+import com.gitblit.wicket.GitBlitWebApp;
+
+public class GerritToGitBlitWebApp extends GitBlitWebApp {
+    @Override
+    protected IRequestCycleProcessor newRequestCycleProcessor() {
+        return new WebRequestCycleProcessor() {
+            protected IRequestCodingStrategy newRequestCodingStrategy() {
+                return new StaticCodingStrategy("summary/", "project/");
+            }
+        };
+    }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GitBlitSettings.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GitBlitSettings.java
index 67a3090..2f93f52 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GitBlitSettings.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GitBlitSettings.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 The Android Open Source Project
+// Copyright (C) 2012 The Android Open Source Project
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,7 +11,6 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-
 package com.googlesource.gerrit.plugins.gitblit.app;
 
 import java.io.File;
@@ -33,13 +32,10 @@
 import com.google.gerrit.server.config.SitePaths;
 import com.google.gerrit.server.git.LocalDiskRepositoryManager;
 import com.google.inject.Inject;
-import com.google.inject.Singleton;
 import com.googlesource.gerrit.plugins.gitblit.GitBlitUrlsConfig;
 import com.googlesource.gerrit.plugins.gitblit.auth.GerritToGitBlitUserService;
 
-@Singleton
 public class GitBlitSettings extends IStoredSettings {
-  private static final Logger log = LoggerFactory.getLogger(GitBlitSettings.class);
   private static final String GITBLIT_GERRIT_PROPERTIES = "/gitblit.properties";
 
   private final LocalDiskRepositoryManager repoManager;
@@ -132,10 +128,4 @@
     stringSettings.append(properties.toString());
     return stringSettings.toString();
   }
-
-  @Override
-  public boolean saveSettings() {
-    log.warn("Store of GitBlit settings is not supported");
-    return false;
-  }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/StaticCodingStrategy.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/StaticCodingStrategy.java
new file mode 100644
index 0000000..f196e27
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/StaticCodingStrategy.java
@@ -0,0 +1,89 @@
+//Copyright (C) 2012 The Android Open Source Project
+//
+//Licensed under the Apache License, Version 2.0 (the "License");
+//you may not use this file except in compliance with the License.
+//You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing, software
+//distributed under the License is distributed on an "AS IS" BASIS,
+//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//See the License for the specific language governing permissions and
+//limitations under the License.
+package com.googlesource.gerrit.plugins.gitblit.app;
+
+import org.apache.wicket.Request;
+import org.apache.wicket.RequestCycle;
+import org.apache.wicket.protocol.http.request.WebRequestCodingStrategy;
+import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class StaticCodingStrategy extends WebRequestCodingStrategy {
+  private static final Logger LOG = LoggerFactory
+      .getLogger(StaticCodingStrategy.class);
+  private String[] ignoreResourceUrlPrefixes;
+
+  public StaticCodingStrategy(String... ignoreResourceUrlPrefixes) {
+    this.ignoreResourceUrlPrefixes = ignoreResourceUrlPrefixes;
+  }
+
+  @Override
+  public String rewriteStaticRelativeUrl(String url) {
+    // Avoid rewriting of non-static resources
+    String[] urlParts = url.split("/");
+    if (urlParts[urlParts.length - 1].indexOf('.') < 0) {
+      return url;
+    }
+
+    if(isMatchingIgnoreUrlPrefixes(url)) {
+      return url;
+    }
+
+    int depth =
+        ((ServletWebRequest) RequestCycle.get().getRequest())
+            .getDepthRelativeToWicketHandler();
+    return getRelativeStaticUrl(url, depth);
+  }
+
+  private boolean isMatchingIgnoreUrlPrefixes(String url) {
+    for (String ignoredUrlPrefix : ignoreResourceUrlPrefixes) {
+      if(url.startsWith(ignoredUrlPrefix)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  public static String getRelativePrefix(Request request) {
+    int depth = ((ServletWebRequest) request).getDepthRelativeToWicketHandler();
+
+    StringBuffer urlBuffer = new StringBuffer();
+    for (; depth > 0; depth--) {
+      urlBuffer.append("../");
+    }
+
+    return urlBuffer.toString();
+  }
+
+  public static String getStaticRelativePrefix(Request request) {
+    int depth = ((ServletWebRequest) request).getDepthRelativeToWicketHandler();
+    return getRelativeStaticUrl("", depth);
+  }
+
+  public static String getRelativeStaticUrl(String url, int depth) {
+    StringBuffer urlBuffer = new StringBuffer();
+    for (; depth > 0; depth--) {
+      urlBuffer.append("../");
+    }
+    urlBuffer.append("static/"); // tells to Gerrit plugin runtime to load
+                                 // static resources from gitblit plugin jar
+                                 // file
+    urlBuffer.append(url);
+
+    LOG.debug("Rewriting URL " + url + " to " + urlBuffer);
+
+    return urlBuffer.toString();
+  }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/auth/GerritAuthFilter.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/auth/GerritAuthFilter.java
index ba34643..5b5058a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/auth/GerritAuthFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/auth/GerritAuthFilter.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 The Android Open Source Project
+// Copyright (C) 2012 The Android Open Source Project
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,7 +11,6 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-
 package com.googlesource.gerrit.plugins.gitblit.auth;
 
 import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
@@ -28,25 +27,17 @@
 
 import org.apache.commons.codec.binary.Base64;
 
-import com.gitblit.manager.IGitblit;
+import com.gitblit.GitBlit;
 import com.gitblit.models.UserModel;
-import com.google.common.base.MoreObjects;
-import com.google.gerrit.extensions.registration.DynamicItem;
+import com.google.common.base.Objects;
 import com.google.gerrit.httpd.WebSession;
-import com.google.inject.Inject;
+import com.google.inject.Provider;
 import com.google.inject.Singleton;
 
 @Singleton
 public class GerritAuthFilter {
   private static final String LIT_BASIC = "Basic ";
 
-  private final IGitblit gitBlit;
-
-  @Inject
-  public GerritAuthFilter(IGitblit gitBlit) {
-    this.gitBlit = gitBlit;
-  }
-
   /**
    * Returns the user making the request, if the user has authenticated.
    * @param httpRequest
@@ -62,7 +53,7 @@
     }
 
     user =
-        gitBlit.authenticate(username,
+        GitBlit.self().authenticate(username,
             (GerritToGitBlitUserService.SESSIONAUTH + token).toCharArray());
     if (user != null) {
       return user;
@@ -71,7 +62,7 @@
     return null;
   }
 
-  public boolean doFilter(final DynamicItem<WebSession> webSession,
+  public boolean doFilter(final Provider<WebSession> webSession,
       ServletRequest request, ServletResponse response, FilterChain chain)
       throws IOException, ServletException {
     HttpServletRequest httpRequest = (HttpServletRequest) request;
@@ -87,7 +78,7 @@
     }
   }
 
-  public boolean filterSessionAuth(final DynamicItem<WebSession> webSession,
+  public boolean filterSessionAuth(final Provider<WebSession> webSession,
       HttpServletRequest request) {
     request.setAttribute("gerrit-username", webSession.get().getCurrentUser()
         .getUserName());
@@ -107,7 +98,7 @@
     final byte[] decoded =
         new Base64().decode(hdr.substring(LIT_BASIC.length()).getBytes());
     String usernamePassword =
-        new String(decoded, MoreObjects.firstNonNull(
+        new String(decoded, Objects.firstNonNull(
             request.getCharacterEncoding(), "UTF-8"));
     int splitPos = usernamePassword.indexOf(':');
     if (splitPos < 1) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/auth/GerritToGitBlitUserModel.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/auth/GerritToGitBlitUserModel.java
index 49951cf..30e3baa 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/auth/GerritToGitBlitUserModel.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/auth/GerritToGitBlitUserModel.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 The Android Open Source Project
+// Copyright (C) 2012 The Android Open Source Project
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,7 +11,6 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-
 package com.googlesource.gerrit.plugins.gitblit.auth;
 
 import java.util.HashSet;
@@ -27,6 +26,7 @@
 import com.google.gerrit.server.project.NoSuchProjectException;
 import com.google.gerrit.server.project.ProjectControl;
 import com.google.gerrit.server.project.ProjectControl.Factory;
+import com.google.gerrit.server.project.RefControl;
 
 public class GerritToGitBlitUserModel extends UserModel {
   public static final String ANONYMOUS_USER = "$anonymous";
@@ -136,9 +136,30 @@
     return result;
   }
 
+  @Override
+  public boolean hasBranchPermission(String repoName, String branchRef) {
+    boolean result = false;
+
+    try {
+      repoName = getRepositoryName(repoName);
+
+      ProjectControl control =
+          projectControlFactory.validateFor(new NameKey(repoName));
+      if (control != null && control.isVisible()) {
+        RefControl branchCtrl = control.controlForRef(branchRef);
+        result = branchCtrl != null && branchCtrl.isVisible();
+      }
+
+    } catch (NoSuchProjectException e) {
+      result = false;
+    }
+
+    return result;
+  }
+
   public boolean hasTeamAccess(String repositoryName) {
     for (TeamModel team : teams) {
-      if (team.hasRepositoryPermission(repositoryName)) {
+      if (team.hasRepository(repositoryName)) {
         return true;
       }
     }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitblit/auth/GerritToGitBlitUserService.java b/src/main/java/com/googlesource/gerrit/plugins/gitblit/auth/GerritToGitBlitUserService.java
index 1d0ce9d..7ba6182 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/auth/GerritToGitBlitUserService.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/auth/GerritToGitBlitUserService.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 The Android Open Source Project
+// Copyright (C) 2012 The Android Open Source Project
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,31 +11,20 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-
 package com.googlesource.gerrit.plugins.gitblit.auth;
 
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.gitblit.Constants;
-import com.gitblit.Constants.AuthenticationType;
-import com.gitblit.Constants.Role;
-import com.gitblit.manager.IAuthenticationManager;
-import com.gitblit.manager.IManager;
-import com.gitblit.manager.IRuntimeManager;
-import com.gitblit.manager.IUserManager;
+import com.gitblit.IStoredSettings;
+import com.gitblit.IUserService;
 import com.gitblit.models.TeamModel;
 import com.gitblit.models.UserModel;
-import com.gitblit.transport.ssh.SshKey;
 import com.google.common.base.Strings;
-import com.google.gerrit.extensions.registration.DynamicItem;
 import com.google.gerrit.httpd.WebSession;
 import com.google.gerrit.server.account.AccountException;
 import com.google.gerrit.server.account.AccountManager;
@@ -43,24 +32,25 @@
 import com.google.gerrit.server.account.AuthResult;
 import com.google.gerrit.server.project.ProjectControl;
 import com.google.inject.Inject;
+import com.google.inject.Provider;
 import com.google.inject.Singleton;
 
 @Singleton
-public class GerritToGitBlitUserService implements IAuthenticationManager,
-    IUserManager {
+public class GerritToGitBlitUserService implements IUserService {
   private static final Logger log = LoggerFactory
       .getLogger(GerritToGitBlitUserService.class);
 
   private final ProjectControl.Factory projectControl;
-  private final AccountManager accountManager;
-  private final DynamicItem<WebSession> webSession;
+  private AccountManager accountManager;
+
+  private Provider<WebSession> webSession;
 
   public static final String SESSIONAUTH = "sessionid:";
 
   @Inject
   public GerritToGitBlitUserService(
       final ProjectControl.Factory projectControl,
-      AccountManager accountManager, final DynamicItem<WebSession> webSession) {
+      AccountManager accountManager, final Provider<WebSession> webSession) {
     this.projectControl = projectControl;
     this.accountManager = accountManager;
     this.webSession = webSession;
@@ -85,8 +75,7 @@
   public UserModel authenticateSSO(String username, String sessionToken) {
     WebSession session = webSession.get();
 
-    if (session.getSessionId() == null
-        || !session.getSessionId().equals(sessionToken)) {
+    if (session.getSessionId() == null || !session.getSessionId().equals(sessionToken)) {
       log.warn("Invalid Gerrit session token for user '" + username + "'");
       return null;
     }
@@ -126,117 +115,57 @@
     return new GerritToGitBlitUserModel(username, projectControl);
   }
 
-
-  @Override
-  public IManager start() {
-    return null;
-  }
-
-  @Override
-  public IManager stop() {
-    return null;
-  }
-
-  @Override
-  public UserModel authenticate(HttpServletRequest httpRequest) {
-    String gerritUsername =
-        (String) httpRequest.getAttribute("gerrit-username");
-    String gerritToken = (String) httpRequest.getAttribute("gerrit-token");
-    if (Strings.isNullOrEmpty(gerritUsername)
-        || Strings.isNullOrEmpty(gerritToken)) {
-      return null;
-    }
-
-    httpRequest.getSession().setAttribute(Constants.AUTHENTICATION_TYPE,
-        AuthenticationType.CONTAINER);
-    return authenticateSSO(gerritUsername, gerritToken);
-  }
-
-  @Override
-  public UserModel authenticate(String username, SshKey key) {
-    return null;
-  }
-
-  @Override
-  public UserModel authenticate(HttpServletRequest httpRequest,
-      boolean requiresCertificate) {
-    return null;
-  }
-
-  @Override
-  public String getCookie(HttpServletRequest request) {
-    return null;
-  }
-
-  @Override
-  public void setCookie(HttpServletResponse response, UserModel user) {
-  }
-
-  @Override
-  public void setCookie(HttpServletRequest request,
-      HttpServletResponse response, UserModel user) {
-  }
-
-  @Override
-  public void logout(HttpServletResponse response, UserModel user) {
-  }
-
-  @Override
-  public void logout(HttpServletRequest request, HttpServletResponse response,
-      UserModel user) {
-  }
-
-  @Override
-  public boolean supportsCredentialChanges(UserModel user) {
-    return false;
-  }
-
-  @Override
-  public boolean supportsDisplayNameChanges(UserModel user) {
-    return false;
-  }
-
-  @Override
-  public boolean supportsEmailAddressChanges(UserModel user) {
-    return false;
-  }
-
-  @Override
-  public boolean supportsTeamMembershipChanges(UserModel user) {
-    return false;
-  }
-
-  @Override
-  public boolean supportsTeamMembershipChanges(TeamModel team) {
-    return false;
-  }
-
-  @Override
-  public void setup(IRuntimeManager runtimeManager) {
-  }
-
-  @Override
-  public String getCookie(UserModel model) {
-    return null;
-  }
-
-  @Override
-  public UserModel getUserModel(char[] cookie) {
-    return null;
-  }
-
   @Override
   public UserModel getUserModel(String username) {
+
     return new GerritToGitBlitUserModel(username, projectControl);
   }
 
   @Override
-  public boolean updateUserModel(UserModel model) {
+  public boolean supportsCookies() {
     return false;
   }
 
   @Override
-  public boolean updateUserModels(Collection<UserModel> models) {
+  public void setup(IStoredSettings settings) {
+  }
+
+  @Override
+  public boolean supportsCredentialChanges() {
+    return false;
+  }
+
+  @Override
+  public boolean supportsDisplayNameChanges() {
+    return false;
+  }
+
+  @Override
+  public boolean supportsEmailAddressChanges() {
+    return false;
+  }
+
+  @Override
+  public boolean supportsTeamMembershipChanges() {
+    return false;
+  }
+
+  @Override
+  public String getCookie(UserModel model) {
+    return model.cookie;
+  }
+
+  @Override
+  public UserModel authenticate(char[] cookie) {
+    return null;
+  }
+
+  @Override
+  public void logout(UserModel user) {
+  }
+
+  @Override
+  public boolean updateUserModel(UserModel model) {
     return false;
   }
 
@@ -272,12 +201,18 @@
 
   @Override
   public List<TeamModel> getAllTeams() {
-    return null;
+    return Collections.emptyList();
   }
 
   @Override
-  public List<String> getTeamNamesForRepositoryRole(String role) {
-    return null;
+  public List<String> getTeamnamesForRepositoryRole(String role) {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public boolean setTeamnamesForRepositoryRole(String role,
+      List<String> teamnames) {
+    return false;
   }
 
   @Override
@@ -291,11 +226,6 @@
   }
 
   @Override
-  public boolean updateTeamModels(Collection<TeamModel> models) {
-    return false;
-  }
-
-  @Override
   public boolean updateTeamModel(String teamname, TeamModel model) {
     return false;
   }
@@ -312,7 +242,13 @@
 
   @Override
   public List<String> getUsernamesForRepositoryRole(String role) {
-    return null;
+    return Collections.emptyList();
+  }
+
+  @Override
+  public boolean setUsernamesForRepositoryRole(String role,
+      List<String> usernames) {
+    return false;
   }
 
   @Override
@@ -326,17 +262,12 @@
   }
 
   @Override
-  public boolean isInternalAccount(String username) {
+  public boolean updateTeamModels(Collection<TeamModel> arg0) {
     return false;
   }
 
   @Override
-  public boolean supportsRoleChanges(UserModel user, Role role) {
-    return false;
-  }
-
-  @Override
-  public boolean supportsRoleChanges(TeamModel team, Role role) {
+  public boolean updateUserModels(Collection<UserModel> arg0) {
     return false;
   }
 }