Remove old LDAP group code.
Change-Id: I38fdd7b0dba73df61f9b7085c202c6f36ecfc04e
This commit is contained in:
		| @@ -79,9 +79,4 @@ public class DefaultRealm implements Realm { | ||||
|     } | ||||
|     return null; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public Set<AccountGroup.ExternalNameKey> lookupGroups(String name) { | ||||
|     return Collections.emptySet(); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -16,8 +16,6 @@ package com.google.gerrit.server.account; | ||||
|  | ||||
| import com.google.gerrit.reviewdb.client.AccountGroup; | ||||
|  | ||||
| import java.util.Collection; | ||||
|  | ||||
| import javax.annotation.Nullable; | ||||
|  | ||||
| /** Tracks group objects in memory for efficient access. */ | ||||
| @@ -34,8 +32,6 @@ public interface GroupCache { | ||||
|   @Nullable | ||||
|   public AccountGroup get(AccountGroup.UUID uuid); | ||||
|  | ||||
|   public Collection<AccountGroup> get(AccountGroup.ExternalNameKey externalName); | ||||
|  | ||||
|   /** @return sorted iteration of groups. */ | ||||
|   public abstract Iterable<AccountGroup> all(); | ||||
|  | ||||
|   | ||||
| @@ -17,7 +17,6 @@ package com.google.gerrit.server.account; | ||||
| import com.google.common.base.Optional; | ||||
| import com.google.common.cache.CacheLoader; | ||||
| import com.google.common.cache.LoadingCache; | ||||
| import com.google.common.collect.ImmutableList; | ||||
| import com.google.gerrit.reviewdb.client.AccountGroup; | ||||
| import com.google.gerrit.reviewdb.client.AccountGroupName; | ||||
| import com.google.gerrit.reviewdb.server.ReviewDb; | ||||
| @@ -34,7 +33,6 @@ import com.google.inject.name.Named; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
| import java.util.concurrent.ExecutionException; | ||||
| @@ -48,7 +46,6 @@ public class GroupCacheImpl implements GroupCache { | ||||
|   private static final String BYID_NAME = "groups"; | ||||
|   private static final String BYNAME_NAME = "groups_byname"; | ||||
|   private static final String BYUUID_NAME = "groups_byuuid"; | ||||
|   private static final String BYEXT_NAME = "groups_byext"; | ||||
|  | ||||
|   public static Module module() { | ||||
|     return new CacheModule() { | ||||
| @@ -69,11 +66,6 @@ public class GroupCacheImpl implements GroupCache { | ||||
|             new TypeLiteral<Optional<AccountGroup>>() {}) | ||||
|           .loader(ByUUIDLoader.class); | ||||
|  | ||||
|         cache(BYEXT_NAME, | ||||
|             String.class, | ||||
|             new TypeLiteral<Collection<AccountGroup>>() {}) | ||||
|           .loader(ByExternalNameLoader.class); | ||||
|  | ||||
|         bind(GroupCacheImpl.class); | ||||
|         bind(GroupCache.class).to(GroupCacheImpl.class); | ||||
|       } | ||||
| @@ -83,7 +75,6 @@ public class GroupCacheImpl implements GroupCache { | ||||
|   private final LoadingCache<AccountGroup.Id, Optional<AccountGroup>> byId; | ||||
|   private final LoadingCache<String, Optional<AccountGroup>> byName; | ||||
|   private final LoadingCache<String, Optional<AccountGroup>> byUUID; | ||||
|   private final LoadingCache<String, Collection<AccountGroup>> byExternalName; | ||||
|   private final SchemaFactory<ReviewDb> schema; | ||||
|  | ||||
|   @Inject | ||||
| @@ -91,15 +82,14 @@ public class GroupCacheImpl implements GroupCache { | ||||
|       @Named(BYID_NAME) LoadingCache<AccountGroup.Id, Optional<AccountGroup>> byId, | ||||
|       @Named(BYNAME_NAME) LoadingCache<String, Optional<AccountGroup>> byName, | ||||
|       @Named(BYUUID_NAME) LoadingCache<String, Optional<AccountGroup>> byUUID, | ||||
|       @Named(BYEXT_NAME) LoadingCache<String, Collection<AccountGroup>> byExternalName, | ||||
|       SchemaFactory<ReviewDb> schema) { | ||||
|     this.byId = byId; | ||||
|     this.byName = byName; | ||||
|     this.byUUID = byUUID; | ||||
|     this.byExternalName = byExternalName; | ||||
|     this.schema = schema; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public AccountGroup get(final AccountGroup.Id groupId) { | ||||
|     try { | ||||
|       Optional<AccountGroup> g = byId.get(groupId); | ||||
| @@ -110,6 +100,7 @@ public class GroupCacheImpl implements GroupCache { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public void evict(final AccountGroup group) { | ||||
|     if (group.getId() != null) { | ||||
|       byId.invalidate(group.getId()); | ||||
| @@ -120,11 +111,9 @@ public class GroupCacheImpl implements GroupCache { | ||||
|     if (group.getGroupUUID() != null) { | ||||
|       byUUID.invalidate(group.getGroupUUID().get()); | ||||
|     } | ||||
|     if (group.getExternalNameKey() != null) { | ||||
|       byExternalName.invalidate(group.getExternalNameKey().get()); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public void evictAfterRename(final AccountGroup.NameKey oldName, | ||||
|       final AccountGroup.NameKey newName) { | ||||
|     if (oldName != null) { | ||||
| @@ -135,6 +124,7 @@ public class GroupCacheImpl implements GroupCache { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public AccountGroup get(AccountGroup.NameKey name) { | ||||
|     if (name == null) { | ||||
|       return null; | ||||
| @@ -147,6 +137,7 @@ public class GroupCacheImpl implements GroupCache { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public AccountGroup get(AccountGroup.UUID uuid) { | ||||
|     if (uuid == null) { | ||||
|       return null; | ||||
| @@ -159,18 +150,6 @@ public class GroupCacheImpl implements GroupCache { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   public Collection<AccountGroup> get(AccountGroup.ExternalNameKey name) { | ||||
|     if (name == null) { | ||||
|       return Collections.emptyList(); | ||||
|     } | ||||
|     try { | ||||
|       return byExternalName.get(name.get()); | ||||
|     } catch (ExecutionException e) { | ||||
|       log.warn("Cannot lookup external group " + name, e); | ||||
|       return Collections.emptyList(); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public Iterable<AccountGroup> all() { | ||||
|     try { | ||||
| @@ -272,27 +251,4 @@ public class GroupCacheImpl implements GroupCache { | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   static class ByExternalNameLoader extends | ||||
|       CacheLoader<String, Collection<AccountGroup>> { | ||||
|     private final SchemaFactory<ReviewDb> schema; | ||||
|  | ||||
|     @Inject | ||||
|     ByExternalNameLoader(final SchemaFactory<ReviewDb> sf) { | ||||
|       schema = sf; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Collection<AccountGroup> load(String name) | ||||
|         throws Exception { | ||||
|       final ReviewDb db = schema.open(); | ||||
|       try { | ||||
|         return ImmutableList.copyOf(db.accountGroups() | ||||
|           .byExternalName(new AccountGroup.ExternalNameKey(name)) | ||||
|           .toList()); | ||||
|       } finally { | ||||
|         db.close(); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -45,9 +45,4 @@ public interface Realm { | ||||
|    * user by that email address. | ||||
|    */ | ||||
|   public Account.Id lookup(String accountName); | ||||
|  | ||||
|   /** | ||||
|    * Search for matching external groups. | ||||
|    */ | ||||
|   public Set<AccountGroup.ExternalNameKey> lookupGroups(String name); | ||||
| } | ||||
|   | ||||
| @@ -17,7 +17,6 @@ package com.google.gerrit.server.auth.ldap; | ||||
| import com.google.gerrit.common.data.ParameterizedString; | ||||
| import com.google.gerrit.reviewdb.client.AccountGroup; | ||||
| import com.google.gerrit.server.account.AccountException; | ||||
| import com.google.gerrit.server.account.GroupCache; | ||||
| import com.google.gerrit.server.config.ConfigUtil; | ||||
| import com.google.gerrit.server.config.GerritServerConfig; | ||||
| import com.google.gerrit.util.ssl.BlindSSLSocketFactory; | ||||
| @@ -47,7 +46,8 @@ import javax.naming.directory.InitialDirContext; | ||||
| import javax.net.ssl.SSLSocketFactory; | ||||
|  | ||||
| @Singleton class Helper { | ||||
|   private final GroupCache groupCache; | ||||
|   static final String LDAP_UUID = "ldap:"; | ||||
|  | ||||
|   private final Config config; | ||||
|   private final String server; | ||||
|   private final String username; | ||||
| @@ -58,8 +58,7 @@ import javax.net.ssl.SSLSocketFactory; | ||||
|   private final String readTimeOutMillis; | ||||
|  | ||||
|   @Inject | ||||
|   Helper(@GerritServerConfig final Config config, final GroupCache groupCache) { | ||||
|     this.groupCache = groupCache; | ||||
|   Helper(@GerritServerConfig final Config config) { | ||||
|     this.config = config; | ||||
|     this.server = LdapRealm.required(config, "server"); | ||||
|     this.username = LdapRealm.optional(config, "username"); | ||||
| @@ -195,12 +194,7 @@ import javax.net.ssl.SSLSocketFactory; | ||||
|  | ||||
|     final Set<AccountGroup.UUID> actual = new HashSet<AccountGroup.UUID>(); | ||||
|     for (String dn : groupDNs) { | ||||
|       for (AccountGroup group : groupCache | ||||
|           .get(new AccountGroup.ExternalNameKey(dn))) { | ||||
|         if (group.getType() == AccountGroup.Type.LDAP) { | ||||
|           actual.add(group.getGroupUUID()); | ||||
|         } | ||||
|       } | ||||
|       actual.add(new AccountGroup.UUID(LDAP_UUID + dn)); | ||||
|     } | ||||
|  | ||||
|     if (actual.isEmpty()) { | ||||
|   | ||||
| @@ -35,7 +35,6 @@ import com.google.gerrit.server.account.GroupMembership; | ||||
| import com.google.gerrit.server.account.MaterializedGroupMembership; | ||||
| import com.google.gerrit.server.account.Realm; | ||||
| import com.google.gerrit.server.auth.AuthenticationUnavailableException; | ||||
| import com.google.gerrit.server.auth.ldap.Helper.LdapSchema; | ||||
| import com.google.gerrit.server.config.AuthConfig; | ||||
| import com.google.gerrit.server.config.ConfigUtil; | ||||
| import com.google.gerrit.server.config.GerritServerConfig; | ||||
| @@ -67,7 +66,6 @@ class LdapRealm implements Realm { | ||||
|   static final Logger log = LoggerFactory.getLogger(LdapRealm.class); | ||||
|   static final String LDAP = "com.sun.jndi.ldap.LdapCtxFactory"; | ||||
|   static final String USERNAME = "username"; | ||||
|   private static final String GROUPNAME = "groupname"; | ||||
|  | ||||
|   private final Helper helper; | ||||
|   private final AuthConfig authConfig; | ||||
| @@ -191,6 +189,7 @@ class LdapRealm implements Realm { | ||||
|     return r.isEmpty() ? null : r; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public AuthRequest authenticate(final AuthRequest who) | ||||
|       throws AccountException { | ||||
|     if (config.getBoolean("ldap", "localUsernameToLowerCase", false)) { | ||||
| @@ -308,40 +307,6 @@ class LdapRealm implements Realm { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public Set<AccountGroup.ExternalNameKey> lookupGroups(String name) { | ||||
|     final Set<AccountGroup.ExternalNameKey> out; | ||||
|     final Map<String, String> params = Collections.<String, String> emptyMap(); | ||||
|  | ||||
|     out = new HashSet<AccountGroup.ExternalNameKey>(); | ||||
|     try { | ||||
|       final DirContext ctx = helper.open(); | ||||
|       try { | ||||
|         final LdapSchema schema = helper.getSchema(ctx); | ||||
|         final ParameterizedString filter = | ||||
|             ParameterizedString.asis(schema.groupPattern | ||||
|                 .replace(GROUPNAME, name).toString()); | ||||
|         for (String groupBase : schema.groupBases) { | ||||
|           final LdapQuery query = | ||||
|               new LdapQuery(groupBase, schema.groupScope, filter, Collections | ||||
|                   .<String> emptySet()); | ||||
|           for (LdapQuery.Result res : query.query(ctx, params)) { | ||||
|             out.add(new AccountGroup.ExternalNameKey(res.getDN())); | ||||
|           } | ||||
|         } | ||||
|       } finally { | ||||
|         try { | ||||
|           ctx.close(); | ||||
|         } catch (NamingException e) { | ||||
|           log.warn("Cannot close LDAP query handle", e); | ||||
|         } | ||||
|       } | ||||
|     } catch (NamingException e) { | ||||
|       log.warn("Cannot query LDAP for groups matching requested name", e); | ||||
|     } | ||||
|     return out; | ||||
|   } | ||||
|  | ||||
|   static class UserLoader extends CacheLoader<String, Optional<Account.Id>> { | ||||
|     private final SchemaFactory<ReviewDb> schema; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Colby Ranger
					Colby Ranger