8wDlpd.png
8wDFp9.png
8wDEOx.png
8wDMfH.png
8wDKte.png

.NET 8 Ldap 在 Linux 上验证空的 LdapException.ServerErrorMessage

Sefa Dedeoglu 3月前

19 0

当我在 Windows 上使用 LDAP 时,我可以正确获取 Server ErrorMessage 来抑制错误消息。但在 Linux 上 ServerErrorMessage 结果全为空,而且我在此上发现了同样的问题...

我在windows上使用LDAP时,可以正确获取Server ErrorMessage来抑制错误信息,但是在Linux上ServerErrorMessage结果全部为空

我在这个问题上发现了同样的问题 https://github.com/dotnet/runtime/issues/70210

这是我调用 Ldap Authenticate 的函数

public void Authenticate(string username, string password)
{
    var ldapUsername = $"{_ldapDomain}\\{username}";
    var ldapPassword = password;

    using var connection = new LdapConnection(new LdapDirectoryIdentifier(_ldapServer, _ldapPort));

    connection.AuthType = AuthType.Basic;
    connection.Credential = new System.Net.NetworkCredential(ldapUsername, ldapPassword);
    connection.SessionOptions.ProtocolVersion = 3;


    try
    {
        connection.Bind();
    }
    catch (LdapException ex)
    {
        var message = ex.ErrorCode switch
        {
            49 => ex.ServerErrorMessage switch
            {
                string s when s.Contains("data 525") => "User not found. Please check your username.",
                string s when s.Contains("data 52e") => "AD authentication failed. Please check your username and password.",
                string s when s.Contains("data 530") => "Login not permitted at this time. Please contact your administrator.",
                string s when s.Contains("data 531") => "Login not permitted from this workstation. Please contact your administrator.",
                string s when s.Contains("data 532") => "Password expired. Please update your password.",
                string s when s.Contains("data 533") => "Account disabled. Please contact your administrator.",
                string s when s.Contains("data 534") => "Login requires a secure connection. Please ensure you are using a secure connection and try again.",
                string s when s.Contains("data 701") => "Account expired. Please contact your administrator.",
                string s when s.Contains("data 773") => "Password must be reset. Please update your password.",
                string s when s.Contains("data 775") => "Your AD account is locked. Please try again later.",
                _ => $"Authentication failed, please check your username and password, or contact support."
            },
            _ => "LDAP server internal error: please contact support.",
        };
        throw new AuthenticationException(message, ex);
    }
    catch
    {
        throw;
    }
}
帖子版权声明 1、本帖标题:.NET 8 Ldap 在 Linux 上验证空的 LdapException.ServerErrorMessage
    本站网址:http://xjnalaquan.com/
2、本网站的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
3、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
4、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
5、站长邮箱:yeweds@126.com 除非注明,本帖由Sefa Dedeoglu在本站《linux》版块原创发布, 转载请注明出处!
最新回复 (0)
返回
作者最近主题: