当前,用户使用他们的AD (活动目录)凭据登录到web应用程序,这些凭据是根据AD进行验证的。一旦进入应用程序,某些用户将需要更新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()发布于 2011-01-20 19:12:46
为了不需要在操作之前指定任何凭据,用户IIS运行时需要具有AD编辑权限(默认情况下不需要AD编辑权限),或者您需要设置模拟和使用Windows身份验证,以便在用户查看页面时运行。
第二种情况有一个额外的困难,因为模拟不能“双跳”,也就是说,set服务器也必须是域控制器,或者您必须在服务器上设置一些域管理员可能不想给您的额外广告代表团特权。
在这种情况下,您的问题的解决方案是将应用程序正在运行的用户帐户更改为已经具有所需权限的帐户。其中的危险在于,任何安全漏洞都会授予攻击者相同的权限。
或者,您可以对一些凭据进行加密和解密以使用它们,这比硬编码略好一些。我想让用户手动提供凭据,然后按照当前使用硬编码凭据的方式使用它们也是可行的。
https://stackoverflow.com/questions/4750801
复制相似问题