Bump to GitBlit 1.7.0-SNAPSHOT Change-Id: I11081a077aaad974ca20f29ab0be5d56d69846bb
diff --git a/README b/README deleted file mode 100644 index 5f79157..0000000 --- a/README +++ /dev/null
@@ -1,24 +0,0 @@ -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 new file mode 100644 index 0000000..6c6bec3 --- /dev/null +++ b/README.md
@@ -0,0 +1,56 @@ +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. +(assuming plugin was copied as gitblit.jar) + + [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 1bdabb7..7726835 100644 --- a/pom.xml +++ b/pom.xml
@@ -28,103 +28,31 @@ <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.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> + <version>1.7.0-SNAPSHOT</version> + <exclusions> + <exclusion> + <groupId>org.apache.wicket</groupId> + <artifactId>wicket</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.wicket</groupId> <artifactId>wicket</artifactId> - <version>1.4.21-selfload</version> + <version>1.4.23-gerrit</version> </dependency> </dependencies> <build> @@ -151,7 +79,6 @@ <promoteTransitiveDependencies>true</promoteTransitiveDependencies> <artifactSet> <excludes> - <exclude>com.google.gerrit:*</exclude> <exclude>org.bouncycastle:*</exclude> <exclude>org.slf4j:*</exclude> <exclude>com.google.guava:*</exclude> @@ -161,6 +88,26 @@ <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 new file mode 100644 index 0000000..6e3d101 --- /dev/null +++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GerritGitBlitContext.java
@@ -0,0 +1,77 @@ +// 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 a9d0601..d6f5aeb 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) 2012 The Android Open Source Project +// 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. @@ -11,68 +11,80 @@ // 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.GitBlit; +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.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 WicketFilter { +public class GerritWicketFilter extends GitblitWicketFilter { 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 Provider<WebSession> webSession; - @SuppressWarnings("unused") - // We need Guice to create the GerritGitBlit instance - private final GerritGitBlit gitBlit; + private final DynamicItem<WebSession> webSession; + private final GerritAuthFilter gerritAuthFilter; - private final GitBlitSettings settings; + + private final GerritGitBlitContext gerritGitblitContext; @Inject public GerritWicketFilter( - final Provider<WebSession> webSession, final GerritGitBlit gitBlit, - final GerritAuthFilter gerritAuthFilter, final GitBlitSettings settings) { + 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); this.webSession = webSession; - this.gitBlit = gitBlit; this.gerritAuthFilter = gerritAuthFilter; - this.settings = settings; + this.gerritGitblitContext = gerritGitblitContext; } @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); @@ -102,8 +114,32 @@ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - if (gerritAuthFilter.doFilter(webSession, request, response, chain)) { - super.doFilter(request, response, chain); + 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); } } @@ -113,7 +149,6 @@ 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 4ecdf54..3ec851d 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) 2012 The Android Open Source Project +// 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. @@ -11,23 +11,55 @@ // 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.IUserService; +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.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.GerritGitBlit; +import com.googlesource.gerrit.plugins.gitblit.app.GitBlitSettings; 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, @@ -37,15 +69,38 @@ @Override protected void configureServlets() { - log.info("Configuring servlet and filters"); - bind(IUserService.class).to(GerritToGitBlitUserService.class); - bind(GerritGitBlit.class); + log.info("Configuring Gitblit core services"); + bind(IStoredSettings.class).to(GitBlitSettings.class); + bind(XssFilter.class).to(JSoupXssFilter.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); + // 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); 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 83204ae..b4e5778 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitTopMenu.java +++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/GitBlitTopMenu.java
@@ -1,3 +1,17 @@ +// 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 75c681d..9c95f9d 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) 2012 The Android Open Source Project +// 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. @@ -11,6 +11,7 @@ // 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; @@ -24,7 +25,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; public class GitBlitUrlsConfig { private static final int SSH_DEF_PORT = 22; @@ -99,7 +100,7 @@ return ""; } - String httpUrl = Objects.firstNonNull(canonicalWebUrlString, httpListenUrl); + String httpUrl = MoreObjects.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 new file mode 100644 index 0000000..fa89c87 --- /dev/null +++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/NullPluginManager.java
@@ -0,0 +1,144 @@ +// 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 new file mode 100644 index 0000000..2cdfc7e --- /dev/null +++ b/src/main/java/com/googlesource/gerrit/plugins/gitblit/StaticHttpServletRequest.java
@@ -0,0 +1,35 @@ +// 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 deleted file mode 100644 index 4b5fd24..0000000 --- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedDownloadZipServlet.java +++ /dev/null
@@ -1,28 +0,0 @@ -// 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 deleted file mode 100644 index 1edea30..0000000 --- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedLogoServlet.java +++ /dev/null
@@ -1,27 +0,0 @@ -// 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 ad01de7..80a8968 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) 2012 The Android Open Source Project +// 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. @@ -11,6 +11,7 @@ // 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,22 +22,29 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; -import com.gitblit.PagesFilter; +import com.gitblit.manager.IAuthenticationManager; +import com.gitblit.manager.IRepositoryManager; +import com.gitblit.manager.IRuntimeManager; 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 Provider<WebSession> webSession; + private final DynamicItem<WebSession> webSession; @Inject - public WrappedPagesFilter(final Provider<WebSession> webSession, final GerritAuthFilter gerritAuthFilter) { - super(); + public WrappedPagesFilter(DynamicItem<WebSession> webSession, + GerritAuthFilter gerritAuthFilter, + IRuntimeManager runtimeManager, + IAuthenticationManager authenticationManager, + IRepositoryManager repositoryManager) { + super(runtimeManager, authenticationManager, repositoryManager); 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 deleted file mode 100644 index 13bfcfc..0000000 --- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedPagesServlet.java +++ /dev/null
@@ -1,27 +0,0 @@ -// 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 d86a268..88c93a7 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) 2012 The Android Open Source Project +// 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. @@ -11,6 +11,7 @@ // 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; @@ -20,34 +21,54 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; -import com.gitblit.SyndicationFilter; +import com.gitblit.manager.IAuthenticationManager; +import com.gitblit.manager.IProjectManager; +import com.gitblit.manager.IRepositoryManager; +import com.gitblit.manager.IRuntimeManager; 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 { - @Inject - private GerritAuthFilter gerritAuthFilter; + 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 final Provider<WebSession> webSession; - - @Inject - public WrappedSyndicationFilter(final Provider<WebSession> webSession) { - super(); + public WrappedSyndicationFilter(DynamicItem<WebSession> webSession, + GerritAuthFilter gerritAuthFilter, + IRuntimeManager runtimeManager, + IAuthenticationManager authenticationManager, + IRepositoryManager repositoryManager, + IProjectManager projectManager) { + super(runtimeManager, authenticationManager, repositoryManager, projectManager); 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(request, response, chain); + super.doFilter(new SyndicationHttpServletRequest( + (HttpServletRequest) 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 deleted file mode 100644 index 8560b74..0000000 --- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/WrappedSyndicationServlet.java +++ /dev/null
@@ -1,27 +0,0 @@ -// 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 deleted file mode 100644 index 8da4164..0000000 --- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GerritGitBlit.java +++ /dev/null
@@ -1,65 +0,0 @@ -// 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 deleted file mode 100644 index 419487c..0000000 --- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/GerritToGitBlitWebApp.java +++ /dev/null
@@ -1,31 +0,0 @@ -// 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 2f93f52..67a3090 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) 2012 The Android Open Source Project +// 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. @@ -11,6 +11,7 @@ // 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; @@ -32,10 +33,13 @@ 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; @@ -128,4 +132,10 @@ 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 deleted file mode 100644 index f196e27..0000000 --- a/src/main/java/com/googlesource/gerrit/plugins/gitblit/app/StaticCodingStrategy.java +++ /dev/null
@@ -1,89 +0,0 @@ -//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 5b5058a..ba34643 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) 2012 The Android Open Source Project +// 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. @@ -11,6 +11,7 @@ // 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; @@ -27,17 +28,25 @@ import org.apache.commons.codec.binary.Base64; -import com.gitblit.GitBlit; +import com.gitblit.manager.IGitblit; import com.gitblit.models.UserModel; -import com.google.common.base.Objects; +import com.google.common.base.MoreObjects; +import com.google.gerrit.extensions.registration.DynamicItem; import com.google.gerrit.httpd.WebSession; -import com.google.inject.Provider; +import com.google.inject.Inject; 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 @@ -53,7 +62,7 @@ } user = - GitBlit.self().authenticate(username, + gitBlit.authenticate(username, (GerritToGitBlitUserService.SESSIONAUTH + token).toCharArray()); if (user != null) { return user; @@ -62,7 +71,7 @@ return null; } - public boolean doFilter(final Provider<WebSession> webSession, + public boolean doFilter(final DynamicItem<WebSession> webSession, ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; @@ -78,7 +87,7 @@ } } - public boolean filterSessionAuth(final Provider<WebSession> webSession, + public boolean filterSessionAuth(final DynamicItem<WebSession> webSession, HttpServletRequest request) { request.setAttribute("gerrit-username", webSession.get().getCurrentUser() .getUserName()); @@ -98,7 +107,7 @@ final byte[] decoded = new Base64().decode(hdr.substring(LIT_BASIC.length()).getBytes()); String usernamePassword = - new String(decoded, Objects.firstNonNull( + new String(decoded, MoreObjects.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 30e3baa..49951cf 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) 2012 The Android Open Source Project +// 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. @@ -11,6 +11,7 @@ // 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; @@ -26,7 +27,6 @@ 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,30 +136,9 @@ 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.hasRepository(repositoryName)) { + if (team.hasRepositoryPermission(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 7ba6182..1d0ce9d 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) 2012 The Android Open Source Project +// 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. @@ -11,20 +11,31 @@ // 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.IStoredSettings; -import com.gitblit.IUserService; +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.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; @@ -32,25 +43,24 @@ 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 IUserService { +public class GerritToGitBlitUserService implements IAuthenticationManager, + IUserManager { private static final Logger log = LoggerFactory .getLogger(GerritToGitBlitUserService.class); private final ProjectControl.Factory projectControl; - private AccountManager accountManager; - - private Provider<WebSession> webSession; + private final AccountManager accountManager; + private final DynamicItem<WebSession> webSession; public static final String SESSIONAUTH = "sessionid:"; @Inject public GerritToGitBlitUserService( final ProjectControl.Factory projectControl, - AccountManager accountManager, final Provider<WebSession> webSession) { + AccountManager accountManager, final DynamicItem<WebSession> webSession) { this.projectControl = projectControl; this.accountManager = accountManager; this.webSession = webSession; @@ -75,7 +85,8 @@ 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; } @@ -115,53 +126,108 @@ return new GerritToGitBlitUserModel(username, projectControl); } - @Override - public UserModel getUserModel(String username) { - - return new GerritToGitBlitUserModel(username, projectControl); - } @Override - public boolean supportsCookies() { - return false; - } - - @Override - 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) { + public IManager start() { return null; } @Override - public void logout(UserModel user) { + 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 @@ -170,6 +236,11 @@ } @Override + public boolean updateUserModels(Collection<UserModel> models) { + return false; + } + + @Override public boolean updateUserModel(String username, UserModel model) { return false; } @@ -201,18 +272,12 @@ @Override public List<TeamModel> getAllTeams() { - return Collections.emptyList(); + return null; } @Override - public List<String> getTeamnamesForRepositoryRole(String role) { - return Collections.emptyList(); - } - - @Override - public boolean setTeamnamesForRepositoryRole(String role, - List<String> teamnames) { - return false; + public List<String> getTeamNamesForRepositoryRole(String role) { + return null; } @Override @@ -226,6 +291,11 @@ } @Override + public boolean updateTeamModels(Collection<TeamModel> models) { + return false; + } + + @Override public boolean updateTeamModel(String teamname, TeamModel model) { return false; } @@ -242,13 +312,7 @@ @Override public List<String> getUsernamesForRepositoryRole(String role) { - return Collections.emptyList(); - } - - @Override - public boolean setUsernamesForRepositoryRole(String role, - List<String> usernames) { - return false; + return null; } @Override @@ -262,12 +326,17 @@ } @Override - public boolean updateTeamModels(Collection<TeamModel> arg0) { + public boolean isInternalAccount(String username) { return false; } @Override - public boolean updateUserModels(Collection<UserModel> arg0) { + public boolean supportsRoleChanges(UserModel user, Role role) { + return false; + } + + @Override + public boolean supportsRoleChanges(TeamModel team, Role role) { return false; } }