Close DirContext context in LdapRealm::isActive

Avoid context leak, drop credentials.

Fixes-Change-Id: I4ecdc08df477960f0e884d7e31e174ad6d47e6e0
Change-Id: Icb076aa2ed5b089b61494bafefa2cc1479f762c2
This commit is contained in:
Alon Bar-Lev
2017-10-22 09:25:20 +03:00
committed by David Pursehouse
parent e75790e74c
commit 109e4ae479

View File

@@ -326,14 +326,20 @@ class LdapRealm extends AbstractRealm {
@Override
public boolean isActive(String username)
throws LoginException, NamingException, AccountException {
final DirContext ctx = helper.open();
try {
DirContext ctx = helper.open();
Helper.LdapSchema schema = helper.getSchema(ctx);
helper.findAccount(schema, ctx, username, false);
return true;
} catch (NoSuchUserException e) {
return false;
} finally {
try {
ctx.close();
} catch (NamingException e) {
log.warn("Cannot close LDAP query handle", e);
}
}
return true;
}
static class UserLoader extends CacheLoader<String, Optional<Account.Id>> {