在 .NET 中审核用户身份 - 什么是好的策略?

发布于 2024-08-16 20:36:35 字数 380 浏览 5 评论 0原文

我确信这是许多开发人员以前遇到过的要求:业务需要审计跟踪来了解谁在其系统中执行操作。

无论您选择如何存储审核信息,这个问题的核心是如何识别当前用户。

我想编写组件,范围从小型域模型类到服务组件,所有这些都可以从以下任何主机应用程序安全地调用:

  • Windows 桌面应用程序。
  • 托管在 IIS 中的 ASP.NET 网站。
  • 托管在 IIS 中的 WCF 服务。
  • 托管在 Windows 服务中的 WCF 服务。

考虑到技术的范围、各种身份验证模型以及必须考虑“匿名”用户的概念,我不清楚用于获取以集中方式调用我的组件的人的身份的策略。

你们中的任何聪明人都可以提出解决这个问题的方法吗?

I'm sure it's a requirement many developers have faced before: business needs an audit trail to know who is performing actions in their system.

Regardless of how you choose store the audited information, the core of this problem is how to identify the current user.

I want to write components, ranging from small domain model classes to service components, all which can safely be called from any of the following host applications:

  • A Windows desktop application.
  • An ASP.NET website hosted in IIS.
  • A WCF service hosted in IIS.
  • A WCF service hosted in a Windows service.

Given the range of technologies, the various authentication models and having to account for the concept of an "anonymous" user, I'm not clear on a strategy to use to get the identity of whoever invoked my component in a centralised fashion.

Can any of you smart folk suggest an approach to tackle this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小镇女孩 2024-08-23 20:36:35

使用最新技术的最佳方法可能是使用 Windows Identity Foundation< /a>.

WIF 旨在使用 .NET 跨多种技术处理用户身份问题。

The best approach, using the most current techniques, is probably to use Windows Identity Foundation.

WIF is designed to handle user identity issues across multiple technologies using .NET.

一抹微笑 2024-08-23 20:36:35

我通常要求应用程序将 Thread.CurrentPrincipal 设置为其身份代表当前用户的主体。这可以在客户端(WinForms 或控制台)应用程序中的应用程序启动时(使用 WindowsIdentity.GetCurrent())、从 IIS 中托管的 ASP.NET 或 WCF 应用程序中的 HttpContext.Current.User 或 Roles.GetCurrentUser() 来完成然后

在较低级别的组件中,您只需使用 Thread.CurrentPrincipal.Identity 进行审核。

编辑
(回应评论) - 请注意 Thread.CurrentPrincipal.Identity 与线程的安全上下文无关:它由 WindowsIdentity 表示,可以使用 WindowsIdentity.GetCurrent 进行检索 并使用 WindowsIdentity.Impersonate 进行更改。

I would generally require that applications set Thread.CurrentPrincipal to a principal whose identity represents the current user. This can be done at application startup (using WindowsIdentity.GetCurrent()) in a client (WinForms or Console) app, from HttpContext.Current.User or Roles.GetCurrentUser() in an ASP.NET or WCF application hosted in IIS, etc.

Then in the lower level components you simply use Thread.CurrentPrincipal.Identity for auditing.

EDIT
(In response to comment) - note that Thread.CurrentPrincipal.Identity has nothing to do with the security context of the thread: this is represented by the WindowsIdentity and can be retrieved using WindowsIdentity.GetCurrent and changed using WindowsIdentity.Impersonate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文