Skip to content

Commit

Permalink
Dispose LdapConnections used by ValidateCredentials
Browse files Browse the repository at this point in the history
Ensure that cached LdapConnection instances created by
PrincipalContext.ValidateCredentials are disposed when
the corresponding PrincipalContext is disposed.

Fix dotnet#62035
  • Loading branch information
juliushardt authored and joperezr committed Jan 22, 2022
1 parent 7414af2 commit 9a15c94
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal static class CapabilityMap
public const string LDAP_CAP_ACTIVE_DIRECTORY_V61_OID = "1.2.840.113556.1.4.1935";
}

internal sealed class CredentialValidator
internal sealed class CredentialValidator : IDisposable
{
private enum AuthMethod
{
Expand Down Expand Up @@ -341,6 +341,14 @@ public bool Validate(string userName, string password, ContextOptions connection
return (BindSam(_serverName, userName, password));
}
}

public void Dispose()
{
foreach (LdapConnection connection in _connCache.Values)
{
connection.Dispose();
}
}
}
// ********************************************
public class PrincipalContext : IDisposable
Expand Down Expand Up @@ -1014,6 +1022,8 @@ public void Dispose()
if (_queryCtx != null)
_queryCtx.Dispose();

_credValidate.Dispose();

_disposed = true;
GC.SuppressFinalize(this);
}
Expand Down

0 comments on commit 9a15c94

Please sign in to comment.