Merge "Reduce number of LDAP queries when having multiple accountBases"

This commit is contained in:
Edwin Kempin
2015-01-26 11:58:27 +00:00
committed by Gerrit Code Review

View File

@@ -191,22 +191,16 @@ import javax.security.auth.login.LoginException;
final HashMap<String, String> params = new HashMap<>(); final HashMap<String, String> params = new HashMap<>();
params.put(LdapRealm.USERNAME, username); params.put(LdapRealm.USERNAME, username);
final List<LdapQuery.Result> res = new ArrayList<>();
for (LdapQuery accountQuery : schema.accountQueryList) { for (LdapQuery accountQuery : schema.accountQueryList) {
res.addAll(accountQuery.query(ctx, params)); List<LdapQuery.Result> res = accountQuery.query(ctx, params);
} if (res.size() == 1) {
switch (res.size()) {
case 0:
throw new NoSuchUserException(username);
case 1:
return res.get(0); return res.get(0);
} else if (res.size() > 1) {
default:
throw new AccountException("Duplicate users: " + username); throw new AccountException("Duplicate users: " + username);
} }
} }
throw new NoSuchUserException(username);
}
Set<AccountGroup.UUID> queryForGroups(final DirContext ctx, Set<AccountGroup.UUID> queryForGroups(final DirContext ctx,
final String username, LdapQuery.Result account) final String username, LdapQuery.Result account)