Refactor how we tie the SSH objects into the HTTP injector
Split the SSH stuff into its own Guice module, allowing more direct replacement of the SSH objects when the SSH daemon is disabled, or is not being loaded into a particular server runtime. Change-Id: Ibe79f394110e4d3d0d21c5f1473f306ed8f49e7c Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -24,7 +24,6 @@ import com.google.gerrit.httpd.auth.ldap.LdapAuthModule;
|
|||||||
import com.google.gerrit.httpd.auth.openid.OpenIdModule;
|
import com.google.gerrit.httpd.auth.openid.OpenIdModule;
|
||||||
import com.google.gerrit.httpd.gitweb.GitWebModule;
|
import com.google.gerrit.httpd.gitweb.GitWebModule;
|
||||||
import com.google.gerrit.httpd.rpc.UiRpcModule;
|
import com.google.gerrit.httpd.rpc.UiRpcModule;
|
||||||
import com.google.gerrit.reviewdb.AuthType;
|
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.RemotePeer;
|
import com.google.gerrit.server.RemotePeer;
|
||||||
@@ -38,12 +37,9 @@ import com.google.gerrit.server.config.FactoryModule;
|
|||||||
import com.google.gerrit.server.config.GerritRequestModule;
|
import com.google.gerrit.server.config.GerritRequestModule;
|
||||||
import com.google.gerrit.server.contact.ContactStore;
|
import com.google.gerrit.server.contact.ContactStore;
|
||||||
import com.google.gerrit.server.contact.ContactStoreProvider;
|
import com.google.gerrit.server.contact.ContactStoreProvider;
|
||||||
import com.google.gerrit.server.ssh.SshInfo;
|
|
||||||
import com.google.gerrit.server.ssh.SshKeyCache;
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Provider;
|
|
||||||
import com.google.inject.ProvisionException;
|
import com.google.inject.ProvisionException;
|
||||||
import com.google.inject.servlet.RequestScoped;
|
import com.google.inject.servlet.RequestScoped;
|
||||||
import com.google.inject.servlet.ServletModule;
|
import com.google.inject.servlet.ServletModule;
|
||||||
@@ -53,20 +49,14 @@ import java.net.SocketAddress;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class WebModule extends FactoryModule {
|
public class WebModule extends FactoryModule {
|
||||||
private final Provider<SshInfo> sshInfoProvider;
|
|
||||||
private final Provider<SshKeyCache> sshKeyCacheProvider;
|
|
||||||
private final AuthConfig authConfig;
|
private final AuthConfig authConfig;
|
||||||
private final boolean wantSSL;
|
private final boolean wantSSL;
|
||||||
private final GitWebConfig gitWebConfig;
|
private final GitWebConfig gitWebConfig;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
WebModule(final Provider<SshInfo> sshInfoProvider,
|
WebModule(final AuthConfig authConfig,
|
||||||
final Provider<SshKeyCache> sshKeyCacheProvider,
|
|
||||||
final AuthConfig authConfig,
|
|
||||||
@CanonicalWebUrl @Nullable final String canonicalUrl,
|
@CanonicalWebUrl @Nullable final String canonicalUrl,
|
||||||
final Injector creatingInjector) {
|
final Injector creatingInjector) {
|
||||||
this.sshInfoProvider = sshInfoProvider;
|
|
||||||
this.sshKeyCacheProvider = sshKeyCacheProvider;
|
|
||||||
this.authConfig = authConfig;
|
this.authConfig = authConfig;
|
||||||
this.wantSSL = canonicalUrl != null && canonicalUrl.startsWith("https:");
|
this.wantSSL = canonicalUrl != null && canonicalUrl.startsWith("https:");
|
||||||
|
|
||||||
@@ -129,9 +119,6 @@ public class WebModule extends FactoryModule {
|
|||||||
install(new GerritRequestModule());
|
install(new GerritRequestModule());
|
||||||
install(new ProjectServlet.Module());
|
install(new ProjectServlet.Module());
|
||||||
|
|
||||||
bind(SshInfo.class).toProvider(sshInfoProvider);
|
|
||||||
bind(SshKeyCache.class).toProvider(sshKeyCacheProvider);
|
|
||||||
|
|
||||||
bind(GitWebConfig.class).toInstance(gitWebConfig);
|
bind(GitWebConfig.class).toInstance(gitWebConfig);
|
||||||
if (gitWebConfig.getGitwebCGI() != null) {
|
if (gitWebConfig.getGitwebCGI() != null) {
|
||||||
install(new GitWebModule());
|
install(new GitWebModule());
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// Copyright (C) 2010 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.google.gerrit.httpd;
|
||||||
|
|
||||||
|
import com.google.gerrit.server.ssh.SshInfo;
|
||||||
|
import com.google.gerrit.server.ssh.SshKeyCache;
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pulls objects from the SSH injector over the HTTP injector.
|
||||||
|
* <p>
|
||||||
|
* This mess is only necessary because we build up two different injectors, in
|
||||||
|
* order to have different request scopes. But some HTTP RPCs can cause changes
|
||||||
|
* to the SSH side of the house, and thus needs access to it.
|
||||||
|
*/
|
||||||
|
public class WebSshGlueModule extends AbstractModule {
|
||||||
|
private final Provider<SshInfo> sshInfoProvider;
|
||||||
|
private final Provider<SshKeyCache> sshKeyCacheProvider;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
WebSshGlueModule(Provider<SshInfo> sshInfoProvider,
|
||||||
|
Provider<SshKeyCache> sshKeyCacheProvider) {
|
||||||
|
this.sshInfoProvider = sshInfoProvider;
|
||||||
|
this.sshKeyCacheProvider = sshKeyCacheProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(SshInfo.class).toProvider(sshInfoProvider);
|
||||||
|
bind(SshKeyCache.class).toProvider(sshKeyCacheProvider);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import static com.google.gerrit.server.schema.DataSourceProvider.Context.MULTI_U
|
|||||||
|
|
||||||
import com.google.gerrit.httpd.HttpCanonicalWebUrlProvider;
|
import com.google.gerrit.httpd.HttpCanonicalWebUrlProvider;
|
||||||
import com.google.gerrit.httpd.WebModule;
|
import com.google.gerrit.httpd.WebModule;
|
||||||
|
import com.google.gerrit.httpd.WebSshGlueModule;
|
||||||
import com.google.gerrit.lifecycle.LifecycleManager;
|
import com.google.gerrit.lifecycle.LifecycleManager;
|
||||||
import com.google.gerrit.pgm.http.jetty.JettyEnv;
|
import com.google.gerrit.pgm.http.jetty.JettyEnv;
|
||||||
import com.google.gerrit.pgm.http.jetty.JettyModule;
|
import com.google.gerrit.pgm.http.jetty.JettyModule;
|
||||||
@@ -241,6 +242,7 @@ public class Daemon extends SiteProgram {
|
|||||||
private Injector createWebInjector() {
|
private Injector createWebInjector() {
|
||||||
final List<Module> modules = new ArrayList<Module>();
|
final List<Module> modules = new ArrayList<Module>();
|
||||||
modules.add(sshInjector.getInstance(WebModule.class));
|
modules.add(sshInjector.getInstance(WebModule.class));
|
||||||
|
modules.add(sshInjector.getInstance(WebSshGlueModule.class));
|
||||||
if (sshd) {
|
if (sshd) {
|
||||||
modules.add(sshInjector.getInstance(ProjectQoSFilter.Module.class));
|
modules.add(sshInjector.getInstance(ProjectQoSFilter.Module.class));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,6 +197,7 @@ public class WebAppInitializer extends GuiceServletContextListener {
|
|||||||
private Injector createWebInjector() {
|
private Injector createWebInjector() {
|
||||||
final List<Module> modules = new ArrayList<Module>();
|
final List<Module> modules = new ArrayList<Module>();
|
||||||
modules.add(sshInjector.getInstance(WebModule.class));
|
modules.add(sshInjector.getInstance(WebModule.class));
|
||||||
|
modules.add(sshInjector.getInstance(WebSshGlueModule.class));
|
||||||
return sysInjector.createChildInjector(modules);
|
return sysInjector.createChildInjector(modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user