LCOV - code coverage report
Current view: top level - auth - AuthModule.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 13 16 81.2 %
Date: 2022-11-19 15:00:39 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2013 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.auth;
      16             : 
      17             : import com.google.gerrit.auth.ldap.LdapModule;
      18             : import com.google.gerrit.auth.oauth.OAuthRealm;
      19             : import com.google.gerrit.auth.oauth.OAuthTokenCache;
      20             : import com.google.gerrit.auth.openid.OpenIdRealm;
      21             : import com.google.gerrit.extensions.client.AuthType;
      22             : import com.google.gerrit.extensions.registration.DynamicSet;
      23             : import com.google.gerrit.server.account.DefaultRealm;
      24             : import com.google.gerrit.server.account.Realm;
      25             : import com.google.gerrit.server.auth.AuthBackend;
      26             : import com.google.gerrit.server.auth.InternalAuthBackend;
      27             : import com.google.gerrit.server.config.AuthConfig;
      28             : import com.google.inject.AbstractModule;
      29             : 
      30             : public class AuthModule extends AbstractModule {
      31             :   private final AuthType loginType;
      32             : 
      33         152 :   public AuthModule(AuthConfig authConfig) {
      34         152 :     loginType = authConfig.getAuthType();
      35         152 :   }
      36             : 
      37             :   @Override
      38             :   protected void configure() {
      39         152 :     install(OAuthTokenCache.module());
      40             : 
      41         152 :     switch (loginType) {
      42             :       case HTTP_LDAP:
      43             :       case LDAP:
      44             :       case LDAP_BIND:
      45             :       case CLIENT_SSL_CERT_LDAP:
      46           1 :         install(new LdapModule());
      47           1 :         break;
      48             : 
      49             :       case OAUTH:
      50           0 :         bind(Realm.class).to(OAuthRealm.class);
      51           0 :         break;
      52             : 
      53             :       case CUSTOM_EXTENSION:
      54           0 :         break;
      55             : 
      56             :       case OPENID:
      57             :       case OPENID_SSO:
      58         138 :         bind(Realm.class).to(OpenIdRealm.class);
      59         138 :         DynamicSet.bind(binder(), AuthBackend.class).to(InternalAuthBackend.class);
      60         138 :         break;
      61             : 
      62             :       case DEVELOPMENT_BECOME_ANY_ACCOUNT:
      63             :       case HTTP:
      64             :       default:
      65          18 :         bind(Realm.class).to(DefaultRealm.class);
      66          18 :         DynamicSet.bind(binder(), AuthBackend.class).to(InternalAuthBackend.class);
      67             :         break;
      68             :     }
      69         152 :   }
      70             : }

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