LCOV - code coverage report
Current view: top level - auth/ldap - LdapModule.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 15 15 100.0 %
Date: 2022-11-19 15:00:39 Functions: 6 6 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.auth.ldap;
      16             : 
      17             : import com.google.common.collect.ImmutableSet;
      18             : import com.google.gerrit.entities.Account;
      19             : import com.google.gerrit.entities.AccountGroup;
      20             : import com.google.gerrit.extensions.registration.DynamicSet;
      21             : import com.google.gerrit.server.account.GroupBackend;
      22             : import com.google.gerrit.server.account.Realm;
      23             : import com.google.gerrit.server.cache.CacheModule;
      24             : import com.google.inject.Scopes;
      25             : import com.google.inject.TypeLiteral;
      26             : import java.time.Duration;
      27             : import java.util.Optional;
      28             : import java.util.Set;
      29             : 
      30           1 : public class LdapModule extends CacheModule {
      31             :   static final String USERNAME_CACHE = "ldap_usernames";
      32             :   static final String GROUP_CACHE = "ldap_groups";
      33             :   static final String GROUP_EXIST_CACHE = "ldap_group_existence";
      34             :   static final String PARENT_GROUPS_CACHE = "ldap_groups_byinclude";
      35             : 
      36             :   @Override
      37             :   protected void configure() {
      38           1 :     cache(GROUP_CACHE, String.class, new TypeLiteral<Set<AccountGroup.UUID>>() {})
      39           1 :         .expireAfterWrite(Duration.ofHours(1))
      40           1 :         .loader(LdapRealm.MemberLoader.class);
      41             : 
      42           1 :     cache(USERNAME_CACHE, String.class, new TypeLiteral<Optional<Account.Id>>() {})
      43           1 :         .loader(LdapRealm.UserLoader.class);
      44             : 
      45           1 :     cache(GROUP_EXIST_CACHE, String.class, new TypeLiteral<Boolean>() {})
      46           1 :         .expireAfterWrite(Duration.ofHours(1))
      47           1 :         .loader(LdapRealm.ExistenceLoader.class);
      48             : 
      49           1 :     cache(PARENT_GROUPS_CACHE, String.class, new TypeLiteral<ImmutableSet<String>>() {})
      50           1 :         .expireAfterWrite(Duration.ofHours(1));
      51             : 
      52           1 :     bind(Helper.class);
      53           1 :     bind(Realm.class).to(LdapRealm.class).in(Scopes.SINGLETON);
      54             : 
      55           1 :     DynamicSet.bind(binder(), GroupBackend.class).to(LdapGroupBackend.class);
      56           1 :   }
      57             : }

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