簡體   English   中英

一位用戶無法從我們的應用程序連接 LDAP 服務器

[英]One user is not able to connect LDAP server from our application

我有一個內置於 ASP.Net 3.0 並升級到 4.7.Net Framework 並部署在 web 服務器上的應用程序。 在應用程序的登錄頁面中,我通過 WebAPI 通過 LDAP 驗證用戶憑據。

每個人都可以登錄應用程序,但 LDAP 的身份驗證僅對一個用戶失敗。 該用戶可以通過其他應用程序連接到 LDAP。 他能夠訪問那些也通過相同的 LDAP 域對他進行身份驗證的應用程序。

當我們與 AD 團隊檢查時,他們無法找到該用戶的任何日志,因此懷疑 LDAP 服務器本身沒有受到該用戶的攻擊。

我們使用以下代碼連接到 LDAP 服務器。

 public static bool IsActiveDirectoryLoginValid(string username, string password, out string errorMessage)
    {
        bool authenticated = false;
        string _activeDirectoryDomain = "domain controller name";

        try
        {
            directoryEntry = new DirectoryEntry(string.Format("LDAP://{0}", _activeDirectoryDomain), username, password);
            DirectorySearcher ds = new DirectorySearcher(directoryEntry);
            ds.FindOne();

            authenticated = directoryEntry.NativeObject != null;
            errorMessage = !authenticated ? "Unable to authenticate user with provided username and password!" : null;

        }
        catch(Exception ex)
        {
            Logger.Error("ActiveDirectoryAuthenticationHelper : IsActiveDirectoryLoginValid " + username, ex);
            errorMessage = ex.Message;
            authenticated = false; // most commonly user name/ password incorrect
        }

        return authenticated;
    }

如果密碼中有“#”符號,則從 MVC 發送到 WebAPI 的密碼會被截斷。 我們糾正了它,問題得到了解決。

此外,正如 Fredrik 建議的那樣,NativeObject 會檢查用戶是否有權讀取活動目錄信息。 我刪除了 NativeObject 並使用 FindOne() 方法進行搜索。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM