简体   繁体   English

通过.NET DirectoryEntry绑定的LDAP总是成功

[英]LDAP Bind through .NET DirectoryEntry always succeeds

I am looking up an arbitrary Windows account in a forms-based C# login scenario using the user's e-mail address as the key. 我正在使用用户的电子邮件地址作为键,在基于表单的C#登录方案中查找任意Windows帐户。 Locating the user works fine and I get back my derived UserPrincipalEx fine. 定位用户工作正常,我又得到了派生的UserPrincipalEx

However, when I try to validate a login using a Bind, it always succeeds: 但是,当我尝试使用“绑定”来验证登录时,它总是成功的:

// we can't use ValidateCredentials because it's too broken - multiple attempts each time,
// can't always negotiate properly, etc.
//if (!_principalContext.ValidateCredentials(userPrincipal.UserPrincipalName, password)) {
//    return LoginValidationResults.ValidationFailed;
//}
try {
    using (var directoryEntry = new DirectoryEntry("LDAP://" + _domain + "/" + _principalContext.Container,
        userPrincipal.UserPrincipalName, password, AuthenticationTypes.FastBind)) {
        var forceBind = directoryEntry.NativeObject;
        Log.DebugFormat("Validation successful ({0}).", forceBind);
        return LoginValidationResults.Valid;
    }                    
}
catch (COMException ex) {
    if (ex.ErrorCode != -2147023570) {
        Log.DebugFormat("Validation exception: {0}", ex.ToString());
        throw;
    }
    Log.Debug("Validation failed.");
    return LoginValidationResults.ValidationFailed;
}

In some cases - and I can't figure out what they are yet - the account always binds successfully, no matter what password I give. 在某些情况下-我无法弄清楚它们的含义-不管我输入什么密码,该帐户始终可以成功绑定。

Why could this be? 为什么会这样呢?

So I looked into this using some packet captures and saw that all of the succeeding binds were using a blank username. 因此,我使用一些数据包捕获功能对此进行了调查,结果发现所有后续绑定均使用空白用户名。

Sure enough, the users in question had a blank (actually null - not set) UPN. 果然,有问题的用户的UPN为空白(实际上为null -未设置)。 This should never happen in our scenario but it did. 在我们的情况下,这永远不会发生,但确实如此。 Because it's a broken user case, I just detect that and throw an exception. 因为这是一个坏的用户案例,所以我只是检测到并抛出异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在DirectoryEntry中转义ldap dn - Escape ldap dn in DirectoryEntry DirectoryEntry.Bind在vb.net中有效,但在c#中失败 - DirectoryEntry.Bind Works in vb.net but fails in c# DirectoryEntry绑定上的访问被拒绝 - access denied on DirectoryEntry bind 检查 .NET LDAP 绑定是否成功 - Check if .NET LDAP Bind was successfull 如何区分DirectoryEntry无效路径或无法连接到.NET中的LDAP? - How do I distinguish between a DirectoryEntry Invalid path, or not being able to connect to LDAP in .NET? 使用 .NET LDAPConnection 执行绑定到 LDAP 实例 - Executing Bind to LDAP instance using .NET LDAPConnection 带有DirectoryEntry的Azure LDAP“服务器无法运行”错误C# - Azure LDAP with DirectoryEntry “the server is not operational” error C# DirectoryEntry 不返回 .NET 中的组成员,但在 ASP.NET 中有效 - DirectoryEntry not returning group members in .NET but works in ASP.NET 为什么使用DirectoryEntry对LDAP进行身份验证会间歇性地抛出COMException(0x8007203A):“服务器无法运行”? - Why does authenticating against LDAP with DirectoryEntry intermittently throw COMException (0x8007203A): “The server is not operational”? DirectoryEntry 不包含“属性”的定义(.NET CORE 3.1) - DirectoryEntry does not contain a definition for 'Properties' (.NET CORE 3.1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM