ユーザーが AD 資格情報を使用してログインする必要がある Web アプリケーションを作成しています。いくつかのページで、ユーザーは AD を使用して別のユーザー ルックアップを実行できます。検索の仕組みは以下の通りです。問題は、有効な資格情報を使用して新しいディレクトリ エントリを作成する必要があることです。開発中に、セッション変数にユーザー ID とパスワードを保持することで、各ユーザーが自分の資格情報を使用できると考えて、資格情報をハードコーディングしました。ただし、この方法が安全かどうかはわかりません。
私が考えていた別の方法は、AD レコードをデータベースにインポートするプログラムをスケジュールすることですが、その方法が見つかりませんでした。見つかったとしても、プログラムは特定の資格情報を使用する必要がありますね。
ここでいくつかの提案が必要です。以下は、ルックアップ関数のスクリプトです。前もって感謝します。
Dim enTry As DirectoryEntry = New DirectoryEntry(strADSvrIP, user_loginID, user_loginpassword)
Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)
mySearcher.Filter = "(&(objectCategory=person)(objectClass=user)(|(givenname=" & strKeyword & ")(name=" & strKeyword & ")(sn=" & strKeyword & ")(samAccountName=" & strKeyword & ")))"
Dim resColl As SearchResultCollection
Dim resEnt As SearchResult
Dim list As New List(Of String)
Try
resColl = mySearcher.FindAll()
lblResult.Text = ""
For Each resEnt In resColl
If Not resEnt.GetDirectoryEntry.Properties("sn").Value Is Nothing Then
lblResult.Text = lblResult.Text & resEnt.GetDirectoryEntry.Properties("samAccountName").Value.ToString() & "-"
lblResult.Text = lblResult.Text & resEnt.GetDirectoryEntry.Properties("name").Value.ToString() & "<br>"
End If
Next
編集(解決策):
IIS 設定で ASP.NET Impersonate を使用してアクティブ化し、次の構文を使用することで、アクティブ ユーザーの資格情報を使用できます。
Dim enTry As DirectoryEntry = New DirectoryEntry(strADSvrIP, Nothing, Nothing, AuthenticationTypes.None)