LCOV - code coverage report
Current view: top level - httpd - WebModule.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 30 36 83.3 %
Date: 2022-11-19 15:00:39 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2009 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.httpd;
      16             : 
      17             : import static com.google.gerrit.extensions.registration.PrivateInternals_DynamicTypes.registerInParentInjectors;
      18             : 
      19             : import com.google.gerrit.httpd.GitOverHttpServlet.GitOverHttpServletModule;
      20             : import com.google.gerrit.httpd.auth.become.BecomeAnyAccountModule;
      21             : import com.google.gerrit.httpd.auth.container.HttpAuthModule;
      22             : import com.google.gerrit.httpd.auth.container.HttpsClientSslCertModule;
      23             : import com.google.gerrit.httpd.auth.ldap.LdapAuthModule;
      24             : import com.google.gerrit.httpd.gitweb.GitwebModule;
      25             : import com.google.gerrit.lifecycle.LifecycleModule;
      26             : import com.google.gerrit.server.RemotePeer;
      27             : import com.google.gerrit.server.config.AuthConfig;
      28             : import com.google.gerrit.server.config.GerritOptions;
      29             : import com.google.gerrit.server.config.GerritRequestModule;
      30             : import com.google.gerrit.server.config.GitwebCgiConfig;
      31             : import com.google.gerrit.server.git.receive.AsyncReceiveCommits.AsyncReceiveCommitsModule;
      32             : import com.google.gerrit.server.util.RequestScopePropagator;
      33             : import com.google.inject.Inject;
      34             : import com.google.inject.ProvisionException;
      35             : import com.google.inject.servlet.RequestScoped;
      36             : import java.net.SocketAddress;
      37             : 
      38             : public class WebModule extends LifecycleModule {
      39             :   private final AuthConfig authConfig;
      40             :   private final GitwebCgiConfig gitwebCgiConfig;
      41             :   private final GerritOptions options;
      42             : 
      43             :   @Inject
      44          99 :   WebModule(AuthConfig authConfig, GerritOptions options, GitwebCgiConfig gitwebCgiConfig) {
      45          99 :     this.authConfig = authConfig;
      46          99 :     this.options = options;
      47          99 :     this.gitwebCgiConfig = gitwebCgiConfig;
      48          99 :   }
      49             : 
      50             :   @Override
      51             :   protected void configure() {
      52          99 :     bind(RequestScopePropagator.class).to(GuiceRequestScopePropagator.class);
      53          99 :     bind(HttpRequestContext.class);
      54             : 
      55          99 :     installAuthModule();
      56          99 :     if (options.enableMasterFeatures()) {
      57          99 :       install(new UrlModule(authConfig));
      58             :     }
      59          99 :     install(new GerritRequestModule());
      60          99 :     install(new GitOverHttpServletModule(options.enableMasterFeatures()));
      61             : 
      62          99 :     if (gitwebCgiConfig.getGitwebCgi() != null) {
      63           0 :       install(new GitwebModule());
      64             :     }
      65             : 
      66          99 :     install(new AsyncReceiveCommitsModule());
      67             : 
      68          99 :     bind(SocketAddress.class)
      69          99 :         .annotatedWith(RemotePeer.class)
      70          99 :         .toProvider(HttpRemotePeerProvider.class)
      71          99 :         .in(RequestScoped.class);
      72             : 
      73          99 :     bind(ProxyProperties.class).toProvider(ProxyPropertiesProvider.class);
      74             : 
      75          99 :     listener().toInstance(registerInParentInjectors());
      76             : 
      77          99 :     install(UniversalWebLoginFilter.module());
      78             : 
      79             :     // Static injection was unfortunately the best solution in this place. However, it is to be
      80             :     // avoided if possible.
      81          99 :     requestStaticInjection(WebSessionManager.Val.class);
      82          99 :   }
      83             : 
      84             :   private void installAuthModule() {
      85          99 :     switch (authConfig.getAuthType()) {
      86             :       case HTTP:
      87             :       case HTTP_LDAP:
      88           0 :         install(new HttpAuthModule(authConfig));
      89           0 :         break;
      90             : 
      91             :       case CLIENT_SSL_CERT_LDAP:
      92           0 :         install(new HttpsClientSslCertModule());
      93           0 :         break;
      94             : 
      95             :       case LDAP:
      96             :       case LDAP_BIND:
      97           1 :         install(new LdapAuthModule());
      98           1 :         break;
      99             : 
     100             :       case DEVELOPMENT_BECOME_ANY_ACCOUNT:
     101           2 :         install(new BecomeAnyAccountModule());
     102           2 :         break;
     103             : 
     104             :       case OAUTH:
     105             :         // OAuth support is bound in WebAppInitializer and Daemon.
     106             :       case OPENID:
     107             :       case OPENID_SSO:
     108             :         // OpenID support is bound in WebAppInitializer and Daemon.
     109             :       case CUSTOM_EXTENSION:
     110          99 :         break;
     111             :       default:
     112           0 :         throw new ProvisionException("Unsupported loginType: " + authConfig.getAuthType());
     113             :     }
     114          99 :   }
     115             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750