[英]Update Active Directory without hardcoding username/password
當前,用戶使用針對AD進行驗證的AD(活動目錄)憑據登錄Web應用程序。 進入應用程序后,某些用戶將需要更新AD。 當我對用戶名/密碼進行硬編碼時,我可以更新AD,但是,當我嘗試強制對象使用登錄憑據時,或者如果我未指定用戶名/密碼,則會引發錯誤。 顯然是出於安全考慮,我不想對憑據進行硬編碼。 有解決方案嗎?
錯誤 -System.DirectoryServices.DirectoryServicesCOMException:發生操作錯誤。
Public Shared Sub SetProperty(ByVal de As DirectoryEntry, ByVal propName As String, ByVal propValue As String)
If Not propValue Is Nothing Then
If de.Properties.Contains(propName) Then
de.Properties(propName)(0) = propValue
Else
de.Properties(propName).Add(propValue)
End If
End If
End Sub
Public Shared Function GetDirectoryEntry(ByVal path As String) As DirectoryEntry
Dim de As New DirectoryEntry()
de.Path = path
de.Username = "<username>"
de.Password = "<password>"
'Not setting the username or password or setting both to Nothing throws the error
de.AuthenticationType = AuthenticationTypes.Secure
Return de
End Function
Dim de As DirectoryEntry = GetDirectoryEntry("<path>")
Dim searcher As DirectorySearcher = New DirectorySearcher(de)
searcher.Filter = "(&(objectCategory=person)(objectClass=user)(cn=" & fullName & "))"
searcher.SearchScope = SearchScope.SubTree
Dim result As SearchResult = searcher.FindOne()
If Not result Is Nothing Then
Dim deResult As New DirectoryEntry(result.Path)
SetProperty(deResult, "accountExpires", toAccountExpirationDate)
deResult.CommitChanges()
deResult.Close()
End If
de.Close()
為了不必在執行此操作之前指定任何憑據,運行IIS的用戶需要具有AD編輯特權(默認情況下,它肯定是沒有特權),或者您需要設置“模擬”並使用Windows身份驗證,以便它在用戶查看頁面時運行。
第二種情況有一個額外的困難,因為模擬無法進行“雙跳”,也就是說,Web服務器也必須是域控制器,或者您必須在域管理員所管理的服務器上設置一些額外的AD委托特權。可能不想給你。
在這種情況下,針對您的問題的解決方案是將您的應用程序所運行的用戶帳戶更改為已經具有所需權限的用戶帳戶。 這樣做的危險是,任何安全漏洞都會使攻擊者擁有相同的特權。
或者,您可以加密一些憑據並解密以使用它們,這比硬編碼要好一些。 我想讓用戶手動提供憑據,然后以與當前使用硬編碼憑據相同的方式使用它們也可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.