WCF 服务模拟一个用户但仍然使用 Windows 身份验证?

发布于 2024-12-03 20:01:53 字数 483 浏览 0 评论 0原文

我正在使用 LinqToEntitiesDomainService 连接到 SQL Server 数据库。这需要 Windows 身份验证,我正在使用它。

我编写了一个 Web 服务,它使用 Activator.CreateInstance(...) 在服务器上运行可执行文件。我也希望使用 Windows 身份验证。 但是,我需要该服务具有运行可执行文件的适当权限。

当我现在运行该服务时,它工作正常。我的帐户具有适当的角色来进行身份验证。我还在服务器上拥有上帝般的权限,这使我可以让 Activator.CreateInstance(...) 命令工作。

虽然具有适当角色的其他用户可以进行身份​​验证,但他们的帐户在服务器上没有权限,也不应该有权限。

是否有某种(最好是简单的)方法作为一个用户运行该服务,但所有身份验证都通过 Windows 身份验证完成?如果我能在一个应用程序池中完成这一切,那也是最好的...

谢谢!

I am using LinqToEntitiesDomainService to connect to a SQL Server Database. This requires Windows Authentication, which I have working.

I wrote a web service that uses Activator.CreateInstance(...) to run an executable on the server. I would like this to use Windows Authentication, as well. However, I need the service to have the proper permissions to run the executable.

When I run the service right now, it works fine. My account has the proper roles to authenticate. I also have god-like permissions on the server, which allows me to have the Activator.CreateInstance(...) command work.

While other users who have the proper roles can authenticate, their account doesn't have permissions on the server, nor should it.

Is there some (preferably, easy) way to run the service as one user, but have all of the authentication done with windows authentication? It would also be best if I could do it all in just one app pool...

Thank You!

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

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

发布评论

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

评论(1

喜爱皱眉﹌ 2024-12-10 20:01:53

是的,您可以,请查看这篇文章。这展示了一些模仿用户的技术。

using (WindowsImpersonationContext impersonationContext =
                                 ((WindowsIdentity)User.Identity).Impersonate())
{
    // do something as current user
}

或者在 WCF 中您也可以声明性地定义它。

public class HelloService : IHelloService
{
    [OperationBehavior(Impersonation = ImpersonationOption.Required)]
    public string Hello(string message)
    {
        return "hello";
    }
}

请注意,这两种技术会模拟客户端(调用者)。

要明确地模拟另一个用户,您需要一些 P/Invoke。这里有一个项目,它非常整洁地为您包装了所有内容。然后你可以这样做:

using (new Impersonator("myUsername", "myDomainname", "myPassword"))
{
   // do something as myUsername
}

Yes you can, take a look at this article. This shows some techniques for impersonating users.

using (WindowsImpersonationContext impersonationContext =
                                 ((WindowsIdentity)User.Identity).Impersonate())
{
    // do something as current user
}

Or in WCF you can also define this declaritively.

public class HelloService : IHelloService
{
    [OperationBehavior(Impersonation = ImpersonationOption.Required)]
    public string Hello(string message)
    {
        return "hello";
    }
}

Note these two techniques impersonate the client (caller).

To impersonate another user explicitly you need some P/Invoke. There's a project here that wraps it all up for you quite neatly. You can then do this:

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