登录用户和委托
我正在使用 LogonUser win32 api:
token = LogonUser(...)
WindowsIdentity newId = new WindowsIdentity(token);
WindowsImpersonationContext impersonatedUser = newId.Impersonate();
但是,在此之后调用 WCF 服务时,我无法使用模拟身份。 我认为这是因为 impersonatedUser.ImpersonationLevel 等于 Impersonation。
是这个原因吗? 我需要 ImpersonationLevel.Identification 级别吗? 怎样才能达到这样的水平呢?
I'm using the LogonUser win32 api:
token = LogonUser(...)
WindowsIdentity newId = new WindowsIdentity(token);
WindowsImpersonationContext impersonatedUser = newId.Impersonate();
However when calling a WCF service after this I'm not able to use the impersonated identity. I think this is because impersonatedUser.ImpersonationLevel equals Impersonation.
Is this the reason?
Is a level of ImpersonationLevel.Identification what I need?
How to get such a level?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道这是否适用于 WCF。 但我们在生产 Web 应用程序中使用它来模拟向文件系统读取和写入文件。 您需要为 AdvApi32.LogonUser、AdvApi32.DuplicateToken 和 Kernel32.CloseHandle 定义 API,并确保完成后关闭 WindowsImpersonationContext。
I don't know if this will work for WCF. But we use it in our production web app for impersonation to read and write files to the file system. You will need to define the API's for AdvApi32.LogonUser, AdvApi32.DuplicateToken, and Kernel32.CloseHandle and make sure to Close the WindowsImpersonationContext when you are done.
模拟应该对同一机器上的访问有效,但对网络上的访问无效。
正如 Consultutah 的代码所示,您可能只需要调用 DuplicateToken() 即可将登录令牌转换为模拟令牌,然后才能使用它。
如果您需要充当其他系统的模拟用户,则需要称为“委托”的更高级别的模拟。 这基本上相当于拥有用户的密码,这样您就可以向其他人展示自己。
The impersonation should be effective for access on the same box, but not on the network.
It may be, as consultutah's code shows, that you just need to call DuplicateToken() in order to convert the logon token to an impersonation token before it can be used.
If you need to act as the impersonated user to other systems, you need a higher level of impersonation called 'delegation'. This is basically equivalent to having the user's password so you can represent yourself as them to others.