【发布时间】:2012-08-29 00:18:52
【问题描述】:
我在 WCF 服务和模拟方面遇到了一些问题,我已将其提炼为下面的一个简单方法。 WCF 服务目前在 exe 中自托管。异常消息是“未提供所需的模拟级别,或者提供的模拟级别无效”。检查何时抛出错误,Identity ImpersonationLevel 设置为委托,正如我的客户端上指定的并通过 Kerberos 进行身份验证。
我有点疑惑,因为在我看来,ImpersonationLevel 和 Authenticaiton 的要求已经满足了。我的想法是,问题可能与域设置有关,我已经设置并认为设置正确。所以我有两个问题:
- 下面的操作应该成功吗? (还是有缺陷?)
- 需要在 Win2k8 域上配置哪些设置才能使其正常工作?我正在使用两个属于同一个 Win2k8 域的成员(它是一个新域,非常普通,目的是测试模拟)。
代码如下:
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public string Test()
{
WindowsIdentity identity = ServiceSecurityContext.Current.WindowsIdentity;
using (identity.Impersonate())
{
ProcessStartInfo pi = new ProcessStartInfo(@"c:\temp\test.bat");
pi.UseShellExecute = false;
pi.RedirectStandardOutput = true;
Process p = Process.Start(pi); // exception thrown here!
p.WaitForExit();
string o = p.StandardOutput.ReadToEnd();
return o;
}
}
异常详情:
Win32Exception occurred: Either a required impersonation level was not provided, or the provided impersonation level is invalid
at System.Diagnostics.Process.CreatePipeWithSecurityAttributes(SafeFileHandle& hReadPipe, SafeFileHandle& hWritePipe, SECURITY_ATTRIBUTES lpPipeAttributes, Int32 nSize)
at System.Diagnostics.Process.CreatePipe(SafeFileHandle& parentHandle, SafeFileHandle& childHandle, Boolean parentInputs)
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at MonetEnterprise.Service.SecurityService.Test()
Test.bat 文件内容
回显%用户名%
【问题讨论】:
-
在进入
using块之前使用调试器identity等于什么? -
嗨@Rahmhound,这是客户的登录 - 这就是您所期望的吧?
-
在 NT 域中默认禁用委派。如果需要(看起来是这样),那么您必须启用它。见Enabling Constrained Delegation 或How to enable multi-hop impersonation using constrained delegation in .NET and Active Directory
标签: c# wcf impersonation windows-security