首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更新Active Directory,无需硬编码用户名/密码

问更新Active Directory,无需硬编码用户名/密码
EN

Stack Overflow用户
提问于 2011-01-20 18:08:29
回答 1查看 1.8K关注 0票数 1

当前,用户使用他们的AD (活动目录)凭据登录到web应用程序,这些凭据是根据AD进行验证的。一旦进入应用程序,某些用户将需要更新AD。当我硬编码用户名/密码时,我可以更新AD,但是当我试图强制对象使用登录凭据时,或者如果我不指定用户名/密码,它会抛出一个错误。显然,出于安全考虑,我不想硬编码凭据。有什么解决办法吗?

System.DirectoryServices.DirectoryServicesCOMException:操作错误.

代码语言:javascript
复制
    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()
EN

回答 1

Stack Overflow用户

发布于 2011-01-20 19:12:46

为了不需要在操作之前指定任何凭据,用户IIS运行时需要具有AD编辑权限(默认情况下不需要AD编辑权限),或者您需要设置模拟和使用Windows身份验证,以便在用户查看页面时运行。

第二种情况有一个额外的困难,因为模拟不能“双跳”,也就是说,set服务器也必须是域控制器,或者您必须在服务器上设置一些域管理员可能不想给您的额外广告代表团特权。

在这种情况下,您的问题的解决方案是将应用程序正在运行的用户帐户更改为已经具有所需权限的帐户。其中的危险在于,任何安全漏洞都会授予攻击者相同的权限。

或者,您可以对一些凭据进行加密和解密以使用它们,这比硬编码略好一些。我想让用户手动提供凭据,然后按照当前使用硬编码凭据的方式使用它们也是可行的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4750801

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档