更新日付

最新投稿:道通神社(笠岡市)
投稿日:2024年6月6日
既存投稿更新:吉備津彦神社
更新日:2024年6月13日

2011年9月24日土曜日

AD(ActiveDirectory)サーバにユーザ確認

AD(ActiveDirectory)サーバ上のユーザを利用したユーザ認証
(単にユーザ・パスワードが有効なのかチェックするだけw)をVB.NETでって案件。

ADサーバをLDAPサーバ扱いすれば可能なようなので。

----------------------------------------------------------------------------
        Dim aName As String
        Dim aSn As String
        Dim aGivenName As String
        Dim aDescription As String

        Try
            Dim searcher As New System.DirectoryServices.DirectorySearcher()
            'サーバーが結果を返すまでのクライアント待機時間
            searcher.ClientTimeout = New TimeSpan(500)
            'サーバーが検索するための制限時間
            searcher.ServerTimeLimit = New TimeSpan(500)
            'サーバーが結果のページを検索するための時間
            searcher.ServerPageTimeLimit = New TimeSpan(500)
            '検索を開始する Active Directory 階層のノード
            searcher.SearchRoot = New System.DirectoryServices.DirectoryEntry(%サーバ名%, _
                                                        %ユーザ名% & "@" & %ドメイン名%, %パスワード%)
            searcher.Filter = "(sAMAccountName=" & %ユーザ名%  & ")"
            searcher.SearchScope = System.DirectoryServices.SearchScope.Subtree
            searcher.PageSize = 512
            '姓(漢字姓),名(漢字名),部署名(説明),ユーザID
            searcher.PropertiesToLoad.AddRange(New String() {"name", _
                                                        "sn", _
                                                        "givenName", _
                                                        "description", _
                                                        "sAMAccountName"})
            Dim results As System.DirectoryServices.SearchResult = searcher.FindOne
            'name
            If results.Properties("name").Count > 0 Then
                aName = results.Properties("name").Item(0).ToString
            End If
            'sn
            If results.Properties("sn").Count > 0 Then
                aSn = results.Properties("sn").Item(0).ToString
            End If
            'GivenName
            If results.Properties("givenName").Count > 0 Then
                aGivenName = results.Properties("givenName").Item(0).ToString
            End If
            'Description
            If results.Properties("description").Count > 0 Then
                aDescription = results.Properties("description").Item(0).ToString
            End If
        Catch ex As System.DirectoryServices.DirectoryServicesCOMException
            MsgBox(ex.Message)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

0 件のコメント:

コメントを投稿